From 7d829e1b9e642a1da9f00b79760e351ed4dfff3f Mon Sep 17 00:00:00 2001 From: Abdulrahman Goni Date: Fri, 12 Apr 2024 14:56:56 +0300 Subject: [PATCH] test: Add a test case to `products_createCategory_post.test` tests file Add a test case to the tests file of `products_createCategory_post` route handler for testing the case that admins trying to add an existing category. Fix a failure in the last test case in `products_createCategory_post.test` tests file. --- .../products_createCategory_post.test.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/__tests__/integration_testing/admin_routes_tests/products_createCategory_post.test.js b/__tests__/integration_testing/admin_routes_tests/products_createCategory_post.test.js index 365fb236..03d68ade 100644 --- a/__tests__/integration_testing/admin_routes_tests/products_createCategory_post.test.js +++ b/__tests__/integration_testing/admin_routes_tests/products_createCategory_post.test.js @@ -39,15 +39,27 @@ describe(`POST ${routePath}`, () => { const { productsCategories } = await SettingsModel.findOne({}); expect(productsCategories.length).toBe(oldCategoriesLength + 1); expect(productsCategories.includes(newCategory)).toBe(true); + }) + it("Should returns \"400\" error with \"The category already exist\" message", async () => { + const settings = await SettingsModel.findOne({}, ["productsCategories"]); + const existingCategory = settings.productsCategories[0]; + const oldCategoriesLength = settings.productsCategories.length; + const response = await adminRequest(routePath + `?category=${existingCategory}`, "post"); + expect(response.statusCode).toBe(400); + expect(response.body.message).toMatch("The category already exist"); + expect(response.body.status).toMatch("Fail"); + const { productsCategories } = await SettingsModel.findOne({}); + expect(productsCategories.length).toBe(oldCategoriesLength); + expect(productsCategories.includes(existingCategory)).toBe(true); }) - it("Should returns \"400\" error with \"You didn't provide a valid category name\" message", async () => { + it("Should returns \"400\" error with \"Ivalid Category Name\" message", async () => { const settings = await SettingsModel.findOne({}, ["productsCategories"]); const oldCategoriesLength = settings.productsCategories.length; const response = await adminRequest(routePath, "post"); expect(response.statusCode).toBe(400); - expect(response.body.message).toMatch("You didn't provide a valid category name"); + expect(response.body.message).toMatch("Ivalid Category Name"); expect(response.body.status).toMatch("Fail"); const { productsCategories } = await SettingsModel.findOne({}); expect(productsCategories.length).toBe(oldCategoriesLength);