cyntaria/UniPal-Backend

[POST] A New Class

arafaysaleem opened this issue · 0 comments

Summary

As an admin, I should be able to create classes, so that students can choose them for timetables.

Acceptance Criteria

GIVEN a student is creating a class in the app
WHEN the app hits the /classes endpoint with a valid class request, containing:

  • an array of classes
[
 {
  `class_erp` varchar(5) NOT NULL,
  `semester` varchar(45) NOT NULL,
  `classroom_id` int(10) unsigned NOT NULL,
  `term_id` int(10) unsigned NOT NULL,
  `subject_code` varchar(6) NOT NULL,
  `teacher_id` int(10) unsigned NOT NULL,
  `parent_class_erp` varchar(5) DEFAULT NULL,
  `timeslot_1` int(10) unsigned NOT NULL,
  `timeslot_2` int(10) unsigned NOT NULL,
  `day_1` enum('monday','tuesday','wednesday','thursday','friday','saturday','sunday') NOT NULL,
  `day_2` enum('monday','tuesday','wednesday','thursday','friday','saturday','sunday') NOT NULL
 }
]

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 class entries with a POST request to /classes endpoint with admin token and ensure a 201 status code is returned.
  2. Make a subsequent GET request to /classes/:class_erp endpoint and ensure a 200 status code is returned.
  3. Ensure the response contains a class with the correct information i.e. matching the initially sent body.
  4. Clean up the database by sending a DELETE request to /classes/:class_erp endpoint and ensure a 200 status code is returned.

Scenario 2: POST request is unsuccessful due to unknown term_id

  1. Make a POST request to /classes endpoint using an admin token containing body parameter:
  • term_id, a non-existent id
  1. Ensure a 512 status code is returned.
  2. And the response headers' code parameter should contain "ForeignKeyViolationException"
  3. And the response headers' message parameter should contain "term_id"

Scenario 3: POST request is unsuccessful due to unknown subject_code

  1. Make a POST request to /classes endpoint using an admin token containing body parameter:
  • subject_code, a non-existent id
  1. Ensure a 512 status code is returned.
  2. And the response headers' code parameter should contain "ForeignKeyViolationException"
  3. And the response headers' message parameter should contain "subject_code"

Scenario 4: POST request is unsuccessful due to unknown teacher_id

  1. Make a POST request to /classes endpoint using an admin token containing body parameter:
  • teacher_id, a non-existent id
  1. Ensure a 512 status code is returned.
  2. And the response headers' code parameter should contain "ForeignKeyViolationException"
  3. And the response headers' message parameter should contain "teacher_id"

Scenario 5: POST request is unsuccessful due to unknown classroom_id

  1. Make a POST request to /classes endpoint using an admin token containing body parameter:
  • classroom_id, a non-existent id
  1. Ensure a 512 status code is returned.
  2. And the response headers' code parameter should contain "ForeignKeyViolationException"
  3. And the response headers' message parameter should contain "classroom_id"

Scenario 6: POST request is unsuccessful due to unknown timeslot_id

  1. Make a POST request to /classes endpoint using an admin token containing body parameter:
  • timeslot_1, a non-existent id
  1. Ensure a 512 status code is returned.
  2. And the response headers' code parameter should contain "ForeignKeyViolationException"
  3. And the response headers' message parameter should contain "timeslot_id"

Scenario 7: POST request is unsuccessful due to unknown parent_class_erp

  1. Make a POST request to /classes endpoint using an admin token containing body parameter:
  • parent_class_erp, a non-existent id
  1. Ensure a 512 status code is returned.
  2. And the response headers' code parameter should contain "ForeignKeyViolationException"
  3. And the response headers' message parameter should contain "parent_class_erp"

Scenario 8: POST request is incorrect

  1. Send a POST request to /classes 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 9: POST request is forbidden

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

Scenario 10: POST request is unauthorized

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