Skip to content

Commit

Permalink
test: Add a test case to products_createCategory_post.test tests file
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AbdulrhmanGoni committed Apr 12, 2024
1 parent 8d106e4 commit 7d829e1
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7d829e1

Please sign in to comment.