Unit Testing: Patient V3 - CBTYoung/Documentation GitHub Wiki

Paitent Tests

import { PatientAPI } from "../../src/architecture/service_layer/Patient";
import { isOk } from "../../src/architecture/service_layer/Result";

const username: string = "hello";
const password: string = "goodbye";
const patient: PatientAPI = PatientAPI.Instance;

1. Patient Service Layer Tests:

describe("Patient service layer tests", () => {
    test('checking patient username without login in service', () =>{
        const name = patient.getUsername();
        if(isOk(name)){
            throw new Error("not ok");
        } 
        expect(name.message).toBe("Not a Patient");
    });

    test('checking patient username after login in service', () =>{
        patient.continueAsPatient({username: username, password: password});
        const name = patient.getUsername();
        if(isOk(name)){
            expect(name.value).toBe(username)
        }
        else
            throw new Error("not ok");
    });
});

Test 1.1: Checking Patient Username Without Login In Service

When a user tries to become a Patient, but he didn't log in.

In that case, the system sends a message saying: "Not a Patient". If we are returned a Patient object instead, we throw an error.

Test 1.2: Checking Patient Username After Login In Service

When a user tries to become a Patient, and he did log in.

In that case, the system sends a Patient object back, and we check it's username to see if it's correct. If we are returned an object that is not OK, we throw an error.