Skip to content

CkKean/ufinity_interview_assignment

Repository files navigation

Interview Assignment

This is the codebase for the Ufinity interview test assignment. The system provides the features to Teachers to perform administrative functions for their students

Prerequisites

  • NodeJS v18.x.x
  • Docker

Folder Structure

S/N Name Type Description
1 database dir Contains the DDL query for the database
2 src dir Contains the config, models, routes, controllers, services, utils, rules, test, errors, middleware, and const directories
3 README.md file This file

Exposed Ports

S/N Application Exposed Port
1 database (Development Environment) 33306
1 database (Test Environment) 33307
2 application 3000

Commands

All the commands listed below should be run in the ./ufinity_interview_assignment directory.

Installing Dependencies

npm install

Starting the Project

Start the project in the local environment, which also starts the necessary dependencies such as the database.

npm start

Running in Watch Mode

Start the application in watch mode.

npm run start:dev

Execute Automated Tests

To execute the automated tests.

npm test

Clear Test Database

To remove the existing test database container service.

npm run test:clear

Execute ESLint

To execute ESLint and check your code for any potential issues or errors.

npm run lint

Execute prettier

To execute Prettier and format your code according to the specified rules.

npm run prettier

Steps to Run a Local Instance

  1. Clone the project repository from this URL: https://github.com/CkKean/ufinity_interview_assignment.git
  2. Open the codebase in your preferred IDE (e.g., VS Code)
  3. Start Docker Desktop to run the MySQL database
  4. Run npm install to install the project dependencies
  5. Run npm start to start the project. The application is ready for use if displays the following message. Please check FAQ if there are any issues.
 ✔ Container teacher-administration-system-mysql  Running                                                                                                                                                                                                         0.0s 

> [email protected] start
> ts-node ./src/server.ts

2023-07-05 15:50:40     [database.ts]   INFO    Executing (default): SELECT 1+1 AS result
2023-07-05 15:50:40     [server.ts]     INFO    Application started at http://localhost:3000
  1. You should be able to send a GET request to the following endpoint and receive a 200 response:
http://localhost:3000/api/healthCheck/

Testing

The test suites are located in the ufinity_interview_assignment/src/test directory. There is one test suite with 31 test cases for the Student APIs. A default set of dummy data will be created before executing the test script. The data will remain for every test run for consistency. Please check FAQ if has any issues with executions.

Steps to Run the Tests

  1. Start Docker Desktop to run the MySQL database.
  2. Run npm test to run the tests. The test result will be displayed if there are no problems on init database container. Please check FAQ if there are any issues.
Test Suites: 1 passed, 1 total
Tests:       31 passed, 31 total
Snapshots:   0 total
Time:        8.037 s, estimated 31 s
  1. Run npm run test:clear to remove the existing test database. Note: It is better to run step 3 to clear the existing database to make consistent data.

API Routes

The Postman APIs json file is provided in the ufinity_interview_assignment/api.postman_collection.json.

The following APIs are available for the test assignment:

1. POST http://localhost:3000/api/register

  • Register one or more students to a specified teacher. The API behaves differently based on the conditions below:
    • a. If the student exists but is unassigned, they will be assigned to the specified teacher.
    • b. If the student does not exist, a new student record will be created and assigned to the specified teacher.
    • c. If the student exists and is already assigned, no action will be taken.
  • Request:
  • Response:
    • Status: 204 No Content

2. GET http://localhost:3000/api/[email protected]

3. POST http://localhost:3000/api/suspend

  • Suspend a specified student.
  • Request:
    • Method: POST
    • URL: /api/suspend
    • Headers:
      • Content-Type: application/json
    • Request Body:
      {
        "student": "[email protected]"
      }
  • Response:
    • Status: 204 No Content

4. POST http://localhost:3000/api/retrievefornotifications

5. POST http://localhost:3000/api/teachers

  • Create a new teacher record.
  • Request
    • Method: POST
    • URL: /api/teachers
    • Headers:
      • Content-Type: application/json
    • Request Body:
      {
        "teacher_email": "[email protected]"
      }
  • Response:
    • Status: 200 OK

6. GET http://localhost:3000/api/healthCheck/

  • This endpoint is used to check if the system is running or not.
  • Request
    • Method: GET
    • URL: /api/healthCheck
    • Headers:
      • Content-Type: application/json
  • Response:
    • Status: 200 OK
    • Response Body: OK

Database

The application uses a MySQL database to store data. The database schema is automatically created when the MySQL Docker container is initialized for the first time.

The database has three tables as ERD shows:

  1. student: Stores student information
  2. teacher: Stores teacher information
  3. teacher_student_relationship: Stores the relationship between students and teachers

ERD

Database Image

Environments

There are two environments in which the application operates: test and development.

Test Environment

  • The test environment is used for running automated tests. It has a separate MySQL database for testing purposes. The test database configuration can be customized in the .env file and add it into the /src directory. The default test database configuration is as follows:

    • Host: 127.0.0.1
    • Port: 33307
    • Password: 'password'
    • user: 'root'
    • Schema: 'teacher-administration-system-test'

Development Environment

  • The development environment is used for local development and testing. It has its own MySQL database. The development database configuration can be customized in the .env file and add it into the /src directory. The default test database configuration is as follows:

    • Host: 127.0.0.1
    • Port: 33306
    • Password: 'password'
    • user: 'root'
    • Schema: 'teacher-administration-system'

Test Data

The following is the default sample data used for Student APIs:

Note: The student with email "[email protected]" is suspended and will not receive notifications.


Error when starting up

If you encounter the following error when running npm start, it is due to the slow startup of your database container.
Please run npm start again.


[server.js] ERROR SequelizeConnectionError: Connection lost: The server closed the connection.
[server.js] ERROR Unable to start application

Error when conducted testing

If you encounter the following error when running npm test, it is due to the slow startup of your database container.
Please run npm test again. It might display partial test cases passed result if the following error occurs.

[server.js] ERROR SequelizeConnectionError: Connection lost: The server closed the connection.
[server.js] ERROR Unable to start application

About

A test assignment for Ufinity interview.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published