Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue#25] add test API for DELETE by id for article #35

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

adamcegielka
Copy link
Collaborator

@adamcegielka adamcegielka commented Nov 8, 2023

This is a draft to verify the API request for POST and DELETE method

@adamcegielka adamcegielka added the tests New test(s) to be added label Nov 8, 2023
@adamcegielka adamcegielka self-assigned this Nov 8, 2023
@adamcegielka adamcegielka changed the title add test API for DELETE by id for article [Issue#25] add test API for DELETE by id for article Nov 8, 2023
@adamcegielka adamcegielka linked an issue Nov 8, 2023 that may be closed by this pull request
@adamcegielka adamcegielka added the bug Something isn't working label Nov 8, 2023
@bugITwhisperer bugITwhisperer changed the title [Issue#25] add test API for DELETE by id for article [DRAFT] [Issue#25] add test API for DELETE by id for article Nov 8, 2023
Copy link
Owner

@kat-kan kat-kan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will review again after changes are introduced

@adamcegielka adamcegielka removed the bug Something isn't working label Nov 8, 2023
@adamcegielka
Copy link
Collaborator Author

I have added corrections in the test, the test works correctly, please review :)

@adamcegielka adamcegielka changed the title [DRAFT] [Issue#25] add test API for DELETE by id for article [Issue#25] add test API for DELETE by id for article Nov 8, 2023
tests/api/articles-delete-by-id.spec.ts Outdated Show resolved Hide resolved
tests/api/articles-delete-by-id.spec.ts Outdated Show resolved Hide resolved
tests/api/articles-delete-by-id.spec.ts Outdated Show resolved Hide resolved
tests/api/articles-delete-by-id.spec.ts Outdated Show resolved Hide resolved
});

test("delete article by ID 60", async ({ request }) => {
const nonExistentArticleID = 60;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you meant the existing article?

tests/api/articles-id-delete.spec.ts Outdated Show resolved Hide resolved
tests/api/articles-id-delete.spec.ts Outdated Show resolved Hide resolved
Copy link
Owner

@kat-kan kat-kan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General comment:
I think that we agreed to add Given/When/Then in all tests. Especially in this test it would be beneficial - would make more obvious why the article is created at first. I'm not pushing, but you can consider adding GWT comments :)

expect(deleteResponse.status()).toBe(expectedResponseCode);
});

// Error - Received: 401
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that we discussed that but a lot of time passed by and I completely don't remember. Can you please explain again why this test fails?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed 5.02:

  • reason it fails is because regular user can try to delete only his/her article
  • would be nice to add 2 different tests, for regular user and admin

tests/api/articles-id-delete.spec.ts Show resolved Hide resolved
…into chore/ISSUE-25_DELETE_articles_id-test
import { testUsers } from "@_src_fixtures_api/auth";

test.describe("DELETE articles/{id}", () => {
const baseURL: string = process.env.BASE_URL;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed this can be deleted


test.describe("DELETE articles/{id}", () => {
const baseURL: string = process.env.BASE_URL;
const articles: string = `${baseURL}/api/articles/`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

baseURL part can be deleted

});

// 401 status received - Use the `test.fail();` instruction to mark as a failed test
test("returns 404 status code when delete a non-existent article", async ({ request }) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test to fix: returns 401 when delete a non-existing article as a regular user


// Then: The response status code should be 404
expect(response.status()).toBe(expectedResponseCode);
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new test to be added: returns 404 when delete a non-existing article as an admin user

@Slawomir-DKl Slawomir-DKl self-assigned this May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests New test(s) to be added
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DELETE /articles/{id} - tests
4 participants