cyntaria/UniPal-Backend

[POST] A New Subject

arafaysaleem opened this issue · 0 comments

Summary

As an admin, I should be able to create subjects, so that I can select one while creating classes.

Acceptance Criteria

GIVEN an admin is creating a subject entry in the app
WHEN the app hits the /subjects endpoint with a valid POST request, containing:

  • subject_code
  • subject

THEN the app should receive a status 201
AND in the response, the following information should be returned:

  • headers
  • affected_rows

Sample Request/Sample Response

headers: {
    error: 0,
    message: "..."
}
body: {
    "affected_rows": 1
}

Resources

  • Development URL: {Here goes a URL to the feature on development API}
  • Production URL: {Here goes a URL to the feature on production API}

Dev Notes

{Some complementary notes if necessary}

Testing Notes

Scenario 1: POST request is successful

  1. Create a new subject entry with a POST request to /subjects endpoint and ensure a 201 status code is returned.
  2. Use the id returned by the response in a subsequent GET request to /subjects/:id endpoint and ensure a 200 status code is returned.
  3. Ensure the response contains an subject with the correct information i.e. matching the initially sent body.
  4. Clean up the database by sending a DELETE request to /subjects/:id endpoint and ensure a 200 status code is returned.

Scenario 2: POST request is incorrect

  1. Send a POST request to /subjects endpoint with an incorrect key name in the body
  2. Ensure a 422 status code is returned
  3. And the response headers' code parameter should contain "InvalidPropertiesException".
  4. And the response headers' data parameter should contain the name of the invalid parameter.

Scenario 3: POST request is forbidden

  1. Send a POST request to /subjects endpoint with a student account token.
  2. Ensure a 403 forbidden status code is returned.
  3. And the response headers' code parameter should contain "ForbiddenException"

Scenario 4: POST request is unauthorized

  1. Send a POST request to /subjects endpoint without an authorization token
  2. Ensure a 401 unauthorized status code is returned.
  3. And the response headers' code parameter should contain "TokenMissingException"