Skip to content

Commit b445608

Browse files
creando função que le json e csv
1 parent 383ee32 commit b445608

File tree

6 files changed

+124
-67
lines changed

6 files changed

+124
-67
lines changed

custom-sequencer.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Sequencer from '@jest/test-sequencer';
1+
const Sequencer = require('@jest/test-sequencer').default;
22

33
class CustomSequencer extends Sequencer {
44
shard(tests, {shardIndex, shardCount}) {
@@ -11,10 +11,9 @@ class CustomSequencer extends Sequencer {
1111
.slice(shardStart, shardEnd);
1212
}
1313
sort(tests) {
14-
1514
const copyTests = Array.from(tests);
1615
return copyTests.sort((testA, testB) => (testA.path > testB.path ? 1 : -1));
1716
}
1817
}
1918

20-
export default CustomSequencer;
19+
module.exports = CustomSequencer;

test/data/csv/authors.csv

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
QA by csv name 1,QA by csv name
2+
QA by csv name 2,QA by csv name
3+
QA by csv name 3,QA by csv name
4+
QA by csv name 4,QA by csv name
5+
QA by csv name 5,QA by csv name
6+
QA by csv name 6,QA by csv name
7+
QA by csv name 7,QA by csv name
8+
QA by csv name 8,QA by csv name
9+
QA by csv name 9,QA by csv name
10+
QA by csv name 10,QA by csv name
11+
QA by csv name 11,QA by csv name
12+
QA by csv name 12,QA by csv name
13+
QA by csv name 13,QA by csv name

test/data/json/authors.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[
2+
{
3+
"firstName": "QA by json name 1",
4+
"lastName": "QA by json last Name 1"
5+
},
6+
{
7+
"firstName": "QA by json name 2",
8+
"lastName": "QA by json last Name 2"
9+
},
10+
{
11+
"firstName": "QA by json name 3",
12+
"lastName": "QA by json last Name 3"
13+
},
14+
{
15+
"firstName": "QA by json name 4",
16+
"lastName": "QA by json last Name 4"
17+
},
18+
{
19+
"firstName": "QA by json name 5",
20+
"lastName": "QA by json last Name 5"
21+
},
22+
{
23+
"firstName": "QA by json name 6",
24+
"lastName": "QA by json last Name 6"
25+
},
26+
{
27+
"firstName": "QA by json name 7",
28+
"lastName": "QA by json last Name 7"
29+
},
30+
{
31+
"firstName": "QA by json name 8",
32+
"lastName": "QA by json last Name 8"
33+
},
34+
{
35+
"firstName": "QA by json name 9",
36+
"lastName": "QA by json last Name 9"
37+
},
38+
{
39+
"firstName": "QA by json name 10",
40+
"lastName": "QA by json last Name 10"
41+
}
42+
]

test/data/json/characters.json

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { expect } from '@jest/globals';
2+
import * as request from 'supertest';
3+
import { BASE_URL } from '../../constants/constants';
4+
import * as path from 'path';
5+
import generics from '../utils/generics';
6+
7+
const randomId = Math.floor(Math.random() * 1000) + 1;
8+
9+
describe('Post request example test with CSV', () => {
10+
11+
it('Should create authors from CSV file and check response data and status code 200', async () => {
12+
13+
const filePath = path.join(__dirname, '../data/csv/authors.csv');
14+
const authors = await generics.readCsvFile(filePath);
15+
16+
for (const author of authors) {
17+
const novoAutor = {
18+
id: randomId,
19+
idBook: randomId,
20+
firstName: author.firstName,
21+
lastName: author.lastName
22+
};
23+
24+
const response = await request(BASE_URL)
25+
.post('/api/v1/Authors')
26+
.send(novoAutor);
27+
28+
console.log(response.body);
29+
30+
31+
expect(response.status).toBe(200);
32+
// expect(response.body).toEqual(expect.objectContaining({
33+
// id: randomId,
34+
// idBook: randomId,
35+
// firstName: author.firstName,
36+
// lastName: author.lastName
37+
// }));
38+
}
39+
});
40+
});
Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
11
import { expect } from '@jest/globals';
22
import * as request from 'supertest';
33
import { BASE_URL } from '../../constants/constants';
4-
4+
import * as path from 'path';
5+
import generics from '../utils/generics'
56

67
const randomId = Math.floor(Math.random() * 1000) + 1;
78

9+
810
describe('Post request example test', () => {
911

1012
it('Should create an author then check response data and check the return status code 200', async () => {
11-
const novoAutor = {
12-
// id: 550,
13-
idBook: randomId,
14-
firstName: "Luke" + randomId,
15-
lastName: "Skywalker" + randomId
16-
};
17-
18-
const response = await request(BASE_URL)
19-
.post('/api/v1/Authors')
20-
.send(novoAutor);
21-
22-
expect(response.status).toBe(200);
23-
expect(response.body).toEqual(expect.objectContaining(
24-
{
25-
id: 650,
26-
idBook: 1,
27-
firstName: "Luke",
28-
lastName: "Skywalker"
29-
30-
}
31-
));
3213

14+
const filePath = path.join(__dirname, '../data/json/authors.json');
15+
const authors = await generics.readJsonFile(filePath);
16+
17+
for (const author of authors) {
18+
const novoAutor = {
19+
id: randomId,
20+
idBook: randomId,
21+
firstName: author.firstName,
22+
lastName: author.lastName
23+
};
24+
25+
const response = await request(BASE_URL)
26+
.post('/api/v1/Authors')
27+
.send(novoAutor);
28+
29+
expect(response.status).toBe(200);
30+
expect(response.body).toEqual(expect.objectContaining({
31+
id: randomId,
32+
idBook: randomId,
33+
firstName: author.firstName,
34+
lastName: author.lastName
35+
}));
36+
}
3337
});
38+
3439
});

0 commit comments

Comments
 (0)