Skip to content

Commit

Permalink
test: upgrade test timeout and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CaduGomes committed Nov 13, 2023
1 parent fe82336 commit f79bd50
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
1 change: 0 additions & 1 deletion __test__/metadata/Product/createProduct.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ describe('Create Product', () => {
},
body: JSON.stringify(requiredFields),
}).then(res => res.json())) as KonectyResponse;
console.log(data);

// Assert
expect(data.success).to.be.equal(false);
Expand Down
43 changes: 41 additions & 2 deletions __test__/metadata/Product/deleteProduct.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function createProductHelper(authId: string) {

describe('Delete Product', () => {
describe('Admin', () => {
beforeEach(async () => {
afterEach(async () => {
await db.collection('data.Product').deleteMany({});
});

Expand Down Expand Up @@ -53,10 +53,49 @@ describe('Delete Product', () => {
},
body: JSON.stringify(requestFields),
}).then(res => res.json())) as KonectyResponse;
console.log(data);

// Assert
expect(data.success).to.be.equal(true);
});
});

describe('User', () => {
afterEach(async () => {
await db.collection('data.Product').deleteMany({});
});

it('Should not delete Product', async () => {
// Arrange
const authId = login('user-test');

const product = await createProductHelper(authId);

await new Promise(resolve => setTimeout(resolve, 1000));

const requestFields = {
ids: [
{
_id: product?._id,
_updatedAt: {
$date: product?._updatedAt,
},
},
],
};

// Act
const data = (await fetch(`http://127.0.0.1:3000/rest/data/Product`, {
method: 'DELETE',
headers: {
Cookie: `_authTokenId=${authId}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(requestFields),
}).then(res => res.json())) as KonectyResponse;

// Assert
expect(data.success).to.be.equal(false);
expect(data.errors?.[0].message).to.be.equal("[Product] You don't have permission to delete records");
});
});
});
6 changes: 6 additions & 0 deletions __test__/metadata/Product/updateProduct.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ describe('Update Product', () => {
beforeEach(async () => {
await db.collection('data.Product').deleteMany({});
});
afterEach(async () => {
await db.collection('data.Product').deleteMany({});
});

it('Should not update Product because invalid field', async () => {
// Arrange
Expand Down Expand Up @@ -134,6 +137,9 @@ describe('Update Product', () => {
beforeEach(async () => {
await db.collection('data.Product').deleteMany({});
});
afterEach(async () => {
await db.collection('data.Product').deleteMany({});
});

it('Should not update Product because invalid field', async () => {
// Arrange
Expand Down
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const jestConfig: JestConfigWithTsJest = {
],
coverageDirectory: 'coverage',
coverageProvider: 'v8',
testTimeout: 30000,
globalSetup: '<rootDir>/__test__/globalSetup.ts',
globalTeardown: '<rootDir>/__test__/globalTeardown.ts',

Expand Down

0 comments on commit f79bd50

Please sign in to comment.