Skip to content

Commit f79bd50

Browse files
committed
test: upgrade test timeout and fix tests
1 parent fe82336 commit f79bd50

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

__test__/metadata/Product/createProduct.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ describe('Create Product', () => {
192192
},
193193
body: JSON.stringify(requiredFields),
194194
}).then(res => res.json())) as KonectyResponse;
195-
console.log(data);
196195

197196
// Assert
198197
expect(data.success).to.be.equal(false);

__test__/metadata/Product/deleteProduct.test.ts

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async function createProductHelper(authId: string) {
2121

2222
describe('Delete Product', () => {
2323
describe('Admin', () => {
24-
beforeEach(async () => {
24+
afterEach(async () => {
2525
await db.collection('data.Product').deleteMany({});
2626
});
2727

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

5857
// Assert
5958
expect(data.success).to.be.equal(true);
6059
});
6160
});
61+
62+
describe('User', () => {
63+
afterEach(async () => {
64+
await db.collection('data.Product').deleteMany({});
65+
});
66+
67+
it('Should not delete Product', async () => {
68+
// Arrange
69+
const authId = login('user-test');
70+
71+
const product = await createProductHelper(authId);
72+
73+
await new Promise(resolve => setTimeout(resolve, 1000));
74+
75+
const requestFields = {
76+
ids: [
77+
{
78+
_id: product?._id,
79+
_updatedAt: {
80+
$date: product?._updatedAt,
81+
},
82+
},
83+
],
84+
};
85+
86+
// Act
87+
const data = (await fetch(`http://127.0.0.1:3000/rest/data/Product`, {
88+
method: 'DELETE',
89+
headers: {
90+
Cookie: `_authTokenId=${authId}`,
91+
'Content-Type': 'application/json',
92+
},
93+
body: JSON.stringify(requestFields),
94+
}).then(res => res.json())) as KonectyResponse;
95+
96+
// Assert
97+
expect(data.success).to.be.equal(false);
98+
expect(data.errors?.[0].message).to.be.equal("[Product] You don't have permission to delete records");
99+
});
100+
});
62101
});

__test__/metadata/Product/updateProduct.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ describe('Update Product', () => {
2525
beforeEach(async () => {
2626
await db.collection('data.Product').deleteMany({});
2727
});
28+
afterEach(async () => {
29+
await db.collection('data.Product').deleteMany({});
30+
});
2831

2932
it('Should not update Product because invalid field', async () => {
3033
// Arrange
@@ -134,6 +137,9 @@ describe('Update Product', () => {
134137
beforeEach(async () => {
135138
await db.collection('data.Product').deleteMany({});
136139
});
140+
afterEach(async () => {
141+
await db.collection('data.Product').deleteMany({});
142+
});
137143

138144
it('Should not update Product because invalid field', async () => {
139145
// Arrange

jest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const jestConfig: JestConfigWithTsJest = {
1414
],
1515
coverageDirectory: 'coverage',
1616
coverageProvider: 'v8',
17+
testTimeout: 30000,
1718
globalSetup: '<rootDir>/__test__/globalSetup.ts',
1819
globalTeardown: '<rootDir>/__test__/globalTeardown.ts',
1920

0 commit comments

Comments
 (0)