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

Feature testing #44

Merged
merged 2 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleFileExtensions: ["js", "json", "ts"],
rootDir: "./",
testRegex: ".test.ts$",
transform: { "^.+\\.(t|j)s$": "ts-jest" },
collectCoverageFrom: ["**/*.(t|j)s"],
coverageDirectory: "../coverage",
testEnvironment: "node"
};
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand"
},
"dependencies": {
"@nestjs/axios": "^0.1.0",
Expand Down
52 changes: 52 additions & 0 deletions test/appointment/initiate-call_suspended-patient_reject.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { ErrorApplicationServiceDecorator } from "../../src/core/application/application-service/decoratos/error-decorator/error-application.service.decorator";
import { LoggingApplicationServiceDecorator } from "../../src/core/application/application-service/decoratos/logging-decorator/logging-application.service.decorator";
import { NotifierApplicationServiceDecorator } from "../../src/core/application/application-service/decoratos/notifier-decorator/notifier.application.service.decorator";
import { NestLogger } from "../../src/core/infrastructure/logger/nest-logger";
import { NotifierMock } from "../../test/core/adapters-mocks/notifier.mock";
import { AppointmentObjectMother } from "../../test/core/objects-mother/appointment.object-mother";
import { DoctorObjectMother } from "../../test/core/objects-mother/doctor.object-mother";
import { PatientObjectMother } from "../../test/core/objects-mother/patient.object-mother";
import { AppointmentRepositoryMock } from "../../test/core/repository-mocks/appointment.repository.mock";
import { DoctorRepositoryMock } from "../../test/core/repository-mocks/doctor.repository.mock";
import { PatientRepositoryMock } from "../../test/core/repository-mocks/patient.repository.mock";
import { InitiateAppointmentCallApplicationService, InitiateAppointmentCallApplicationServiceDto } from "../../src/appointment/application/services/initiate-appointment-call.application.service";

describe("Iniciar una llamada a paciente suspendido", () => {
it("debe ser rechazada", async () => {
//Arrange
const patient = PatientObjectMother.createSuspendedPatient();
const doctor = DoctorObjectMother.createActiveDoctor();
const appointment = AppointmentObjectMother.createAcceptedAppointment(patient.Id, doctor.Id, doctor.Specialties[0]);

const patientRepositoryMock = new PatientRepositoryMock();
await patientRepositoryMock.saveAggregate(patient);

const doctorRepositoryMock = new DoctorRepositoryMock();
await doctorRepositoryMock.saveAggregate(doctor);

const appointmentRepositoryMock = new AppointmentRepositoryMock();
await appointmentRepositoryMock.saveAggregate(appointment);

const dto = { id: appointment.Id.Value, doctorId: doctor.Id.Value };

const service = new ErrorApplicationServiceDecorator(
new NotifierApplicationServiceDecorator(
new LoggingApplicationServiceDecorator(
new InitiateAppointmentCallApplicationService(appointmentRepositoryMock, doctorRepositoryMock, patientRepositoryMock),
new NestLogger()
),
new NotifierMock(
async (data: InitiateAppointmentCallApplicationServiceDto) => {
return { message: "Lamando al paciente." }
}
)
)
);

//Act
const result = await service.execute(dto);

//Assert
expect(() => !result.IsSuccess)
})
});
17 changes: 17 additions & 0 deletions test/core/adapters-mocks/notifier.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { NotificationHandler } from "../../../src/core/application/notification-handlers/notification-handler";
import { Logger } from "@nestjs/common";

export interface NotifierDto {
message: string;
}

export class NotifierMock<D> extends NotificationHandler<D, NotifierDto>{
async send(data: D): Promise<void> {
const payload: NotifierDto = await this.messageMapper(data);

Logger.debug(
"\x1b[33m[" + this.constructor.name + "] " +
"\x1b[35m" + "Notificación Mock enviada con " + payload.message
);
}
}
136 changes: 136 additions & 0 deletions test/core/objects-mother/appointment.object-mother.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import { Appointment } from "../../../src/appointment/domain/appointment";
import { AppointmentDate } from "../../../src/appointment/domain/value-objects/appointment-date";
import { AppointmentDescription } from "../../../src/appointment/domain/value-objects/appointment-description";
import { AppointmentDoctor } from "../../../src/appointment/domain/value-objects/appointment-doctor";
import { AppointmentDuration } from "../../../src/appointment/domain/value-objects/appointment-duration";
import { AppointmentId } from "../../../src/appointment/domain/value-objects/appointment-id";
import { AppointmentPatient } from "../../../src/appointment/domain/value-objects/appointment-patient";
import { AppointmentStatus } from "../../../src/appointment/domain/value-objects/appointment-status";
import { AppointmentStatusEnum } from "../../../src/appointment/domain/value-objects/appointment-status.enum";
import { AppointmentType } from "../../../src/appointment/domain/value-objects/appointment-type";
import { AppointmentTypeEnum } from "../../../src/appointment/domain/value-objects/appointment-type.enum";
import { UUIDGenerator } from "../../../src/core/infrastructure/uuid/uuid-generator";
import { DoctorId } from "../../../src/doctor/domain/value-objects/doctor-id";
import { DoctorSpecialty } from "../../../src/doctor/domain/value-objects/doctor-specialty";
import { PatientId } from "../../../src/patient/domain/value-objects/patient-id";

export class AppointmentObjectMother {
static createRequestedAppointment(patientId: PatientId, doctorId: DoctorId, doctorSpecialty: DoctorSpecialty) {
const uuid = new UUIDGenerator();

const appointment = Appointment.create(
AppointmentId.create(uuid.generate()),
null,
AppointmentDescription.create("Cita agendada."),
null,
AppointmentStatus.create(AppointmentStatusEnum.REQUESTED),
AppointmentType.create(AppointmentTypeEnum.VIRTUAL),
AppointmentPatient.create(patientId),
AppointmentDoctor.create(doctorId, doctorSpecialty)
);

return appointment;
}

static createScheduledAppointment(patientId: PatientId, doctorId: DoctorId, doctorSpecialty: DoctorSpecialty) {
const uuid = new UUIDGenerator();

const appointment = Appointment.create(
AppointmentId.create(uuid.generate()),
AppointmentDate.create(new Date(Date.now())),
AppointmentDescription.create("Cita agendada."),
AppointmentDuration.create(5),
AppointmentStatus.create(AppointmentStatusEnum.SCHEDULED),
AppointmentType.create(AppointmentTypeEnum.VIRTUAL),
AppointmentPatient.create(patientId),
AppointmentDoctor.create(doctorId, doctorSpecialty)
);

return appointment;
}

static createRejectedAppointment(patientId: PatientId, doctorId: DoctorId, doctorSpecialty: DoctorSpecialty) {
const uuid = new UUIDGenerator();

const appointment = Appointment.create(
AppointmentId.create(uuid.generate()),
AppointmentDate.create(new Date(Date.now())),
AppointmentDescription.create("Cita agendada."),
AppointmentDuration.create(5),
AppointmentStatus.create(AppointmentStatusEnum.REJECTED),
AppointmentType.create(AppointmentTypeEnum.VIRTUAL),
AppointmentPatient.create(patientId),
AppointmentDoctor.create(doctorId, doctorSpecialty)
);

return appointment;
}

static createAcceptedAppointment(patientId: PatientId, doctorId: DoctorId, doctorSpecialty: DoctorSpecialty) {
const uuid = new UUIDGenerator();

const appointment = Appointment.create(
AppointmentId.create(uuid.generate()),
AppointmentDate.create(new Date(Date.now())),
AppointmentDescription.create("Cita agendada."),
AppointmentDuration.create(5),
AppointmentStatus.create(AppointmentStatusEnum.ACCEPTED),
AppointmentType.create(AppointmentTypeEnum.VIRTUAL),
AppointmentPatient.create(patientId),
AppointmentDoctor.create(doctorId, doctorSpecialty)
);

return appointment;
}

static createCanceledAppointment(patientId: PatientId, doctorId: DoctorId, doctorSpecialty: DoctorSpecialty) {
const uuid = new UUIDGenerator();

const appointment = Appointment.create(
AppointmentId.create(uuid.generate()),
AppointmentDate.create(new Date(Date.now())),
AppointmentDescription.create("Cita agendada."),
AppointmentDuration.create(5),
AppointmentStatus.create(AppointmentStatusEnum.CANCELED),
AppointmentType.create(AppointmentTypeEnum.VIRTUAL),
AppointmentPatient.create(patientId),
AppointmentDoctor.create(doctorId, doctorSpecialty)
);

return appointment;
}

static createInitiatedAppointment(patientId: PatientId, doctorId: DoctorId, doctorSpecialty: DoctorSpecialty) {
const uuid = new UUIDGenerator();

const appointment = Appointment.create(
AppointmentId.create(uuid.generate()),
AppointmentDate.create(new Date(Date.now())),
AppointmentDescription.create("Cita agendada."),
AppointmentDuration.create(5),
AppointmentStatus.create(AppointmentStatusEnum.INICIATED),
AppointmentType.create(AppointmentTypeEnum.VIRTUAL),
AppointmentPatient.create(patientId),
AppointmentDoctor.create(doctorId, doctorSpecialty)
);

return appointment;
}

static createCompletedAppointment(patientId: PatientId, doctorId: DoctorId, doctorSpecialty: DoctorSpecialty) {
const uuid = new UUIDGenerator();

const appointment = Appointment.create(
AppointmentId.create(uuid.generate()),
AppointmentDate.create(new Date(Date.now())),
AppointmentDescription.create("Cita agendada."),
AppointmentDuration.create(5),
AppointmentStatus.create(AppointmentStatusEnum.COMPLETED),
AppointmentType.create(AppointmentTypeEnum.VIRTUAL),
AppointmentPatient.create(patientId),
AppointmentDoctor.create(doctorId, doctorSpecialty)
);

return appointment;
}
}
63 changes: 63 additions & 0 deletions test/core/objects-mother/doctor.object-mother.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { UUIDGenerator } from "../../../src/core/infrastructure/uuid/uuid-generator";
import { Doctor } from "../../../src/doctor/domain/doctor";
import { DoctorGender } from "../../../src/doctor/domain/value-objects/doctor-gender";
import { DoctorGenderEnum } from "../../../src/doctor/domain/value-objects/doctor-gender.enum";
import { DoctorId } from "../../../src/doctor/domain/value-objects/doctor-id";
import { DoctorLocation } from "../../../src/doctor/domain/value-objects/doctor-location";
import { DoctorNames } from "../../../src/doctor/domain/value-objects/doctor-names";
import { DoctorRating } from "../../../src/doctor/domain/value-objects/doctor-rating";
import { DoctorSpecialty } from "../../../src/doctor/domain/value-objects/doctor-specialty";
import { DoctorSpecialtyEnum } from "../../../src/doctor/domain/value-objects/doctor-specialty.enum";
import { DoctorStatus } from "../../../src/doctor/domain/value-objects/doctor-status";
import { DoctorStatusEnum } from "../../../src/doctor/domain/value-objects/doctor-status.enum";
import { DoctorSurnames } from "../../../src/doctor/domain/value-objects/doctor-surnames";

export class DoctorObjectMother {
static createActiveDoctor() {
const uuid = new UUIDGenerator();

const dto = { specialties: [DoctorSpecialtyEnum.CARDIOLOGY, DoctorSpecialtyEnum.NEPHROLOGY] };

const specialties: DoctorSpecialty[] = [];
dto.specialties.forEach((specialty) => {
specialties.push(DoctorSpecialty.create(specialty));
});

const doctor = Doctor.create(
DoctorId.create(uuid.generate()),
DoctorNames.create("First Name", "Middle Name"),
DoctorSurnames.create("First Surname", "Second Surname"),
DoctorLocation.create(10, 10),
DoctorRating.create(0),
DoctorGender.create(DoctorGenderEnum.MALE),
DoctorStatus.create(DoctorStatusEnum.ACTIVE),
specialties
);

return doctor;
}

static createBlockedDoctor() {
const uuid = new UUIDGenerator();

const dto = { specialties: [DoctorSpecialtyEnum.CARDIOLOGY, DoctorSpecialtyEnum.NEPHROLOGY] };

const specialties: DoctorSpecialty[] = [];
dto.specialties.forEach((specialty) => {
specialties.push(DoctorSpecialty.create(specialty));
});

const doctor = Doctor.create(
DoctorId.create(uuid.generate()),
DoctorNames.create("First Name", "Middle Name"),
DoctorSurnames.create("First Surname", "Second Surname"),
DoctorLocation.create(10, 10),
DoctorRating.create(0),
DoctorGender.create(DoctorGenderEnum.MALE),
DoctorStatus.create(DoctorStatusEnum.BLOCKED),
specialties
);

return doctor;
}
}
29 changes: 29 additions & 0 deletions test/core/objects-mother/medical-record.object-mother.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Appointment } from "../../../src/appointment/domain/appointment";
import { UUIDGenerator } from "../../../src/core/infrastructure/uuid/uuid-generator";
import { MedicalRecord } from "../../../src/medical-record/domain/medical-record";
import { MedicalRecordAppointment } from "../../../src/medical-record/domain/value-objects/medical-record-appointment";
import { MedicalRecordDate } from "../../../src/medical-record/domain/value-objects/medical-record-date";
import { MedicalRecordDoctor } from "../../../src/medical-record/domain/value-objects/medical-record-doctor";
import { MedicalRecordID } from "../../../src/medical-record/domain/value-objects/medical-record-id";
import { MedicalRecordPatient } from "../../../src/medical-record/domain/value-objects/medical-record-patient";

export class MedicalRecordObjectMother {
static createMedicalRecord(appointment: Appointment) {
const uuid = new UUIDGenerator();

const medicalRecord: MedicalRecord = MedicalRecord.create(
MedicalRecordID.create(uuid.generate()),
MedicalRecordDate.create(new Date(Date.now())),
null,
null,
MedicalRecordPatient.create(appointment.Patient.Id),
MedicalRecordAppointment.create(appointment.Id),
null,
null,
null,
MedicalRecordDoctor.create(appointment.Doctor.Id, appointment.Doctor.Specialty)
)

return medicalRecord;
}
}
Loading