diff --git a/__test__/metadata/Product/createProduct.test.ts b/__test__/metadata/Product/createProduct.test.ts index bada8093..d0298cf6 100644 --- a/__test__/metadata/Product/createProduct.test.ts +++ b/__test__/metadata/Product/createProduct.test.ts @@ -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); diff --git a/__test__/metadata/Product/deleteProduct.test.ts b/__test__/metadata/Product/deleteProduct.test.ts index 14b206ad..a6b2c84b 100644 --- a/__test__/metadata/Product/deleteProduct.test.ts +++ b/__test__/metadata/Product/deleteProduct.test.ts @@ -21,7 +21,7 @@ async function createProductHelper(authId: string) { describe('Delete Product', () => { describe('Admin', () => { - beforeEach(async () => { + afterEach(async () => { await db.collection('data.Product').deleteMany({}); }); @@ -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"); + }); + }); }); diff --git a/__test__/metadata/Product/updateProduct.test.ts b/__test__/metadata/Product/updateProduct.test.ts index 9291a7b8..bc936eb9 100644 --- a/__test__/metadata/Product/updateProduct.test.ts +++ b/__test__/metadata/Product/updateProduct.test.ts @@ -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 @@ -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 diff --git a/jest.config.ts b/jest.config.ts index 001c4704..c65afeaf 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -14,6 +14,7 @@ const jestConfig: JestConfigWithTsJest = { ], coverageDirectory: 'coverage', coverageProvider: 'v8', + testTimeout: 30000, globalSetup: '/__test__/globalSetup.ts', globalTeardown: '/__test__/globalTeardown.ts',