-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(CC-125): created delete patient appointment registry endpoint an…
…d its e2e
- Loading branch information
1 parent
eb45ed8
commit 86cba82
Showing
11 changed files
with
210 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...try/delete-patient-appointment-registry/delete-patient-appointment-registry.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Controller, Delete, Param } from '@nestjs/common'; | ||
import { ApiTags } from '@nestjs/swagger'; | ||
import { GlobalAppHttpException } from '../../../../../../shared/errors/globalAppHttpException'; | ||
import { | ||
DeletePatientAppointmentRegistryInputDto, | ||
DeletePatientAppointmentRegistryOutputDto, | ||
} from './dto'; | ||
import { NestjsDeletePatientAppointmentRegistryService } from './nestjs-delete-patient-appointment-registry.service'; | ||
|
||
@ApiTags('Delete Patient Appointment Registry') | ||
@Controller({ | ||
path: 'appointment-registry', | ||
}) | ||
export class DeletePatientAppointmentRegistryController { | ||
constructor( | ||
private deletePatientAppointmentRegistryService: NestjsDeletePatientAppointmentRegistryService, | ||
) {} | ||
|
||
@Delete(':id/delete') | ||
async execute( | ||
@Param() | ||
{ id }: DeletePatientAppointmentRegistryInputDto, | ||
): Promise<DeletePatientAppointmentRegistryOutputDto> { | ||
try { | ||
await this.deletePatientAppointmentRegistryService.execute({ id }); | ||
|
||
return { message: 'Appointment registry deleted successfully' }; | ||
} catch (error: unknown) { | ||
throw new GlobalAppHttpException(error); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...istry/delete-patient-appointment-registry/delete-patient-appointment-registry.e2e-spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import request from 'supertest'; | ||
|
||
import { INestApplication } from '@nestjs/common'; | ||
|
||
import { setupE2ETest } from '../../../../../../../../tests/utils/e2e-tests-initial-setup'; | ||
import { PatientAppointmentRegistryEntity } from '../../../../../../core/domains/patient-appointment-registry/entities/registry/entity'; | ||
|
||
describe.only('[E2E] - Delete Appointment Registry', () => { | ||
let app: INestApplication; | ||
|
||
let access_token: string; | ||
|
||
let patientAppointmentRegistry: PatientAppointmentRegistryEntity; | ||
|
||
beforeAll(async () => { | ||
const setup = await setupE2ETest(); | ||
|
||
app = setup.app; | ||
|
||
access_token = setup.access_token; | ||
|
||
patientAppointmentRegistry = setup.patientAppointmentRegistry; | ||
}); | ||
|
||
it('should delete a patient appointment registry', async () => { | ||
const response = await request(app.getHttpServer()) | ||
.delete(`/appointment-registry/${patientAppointmentRegistry.id}/delete`) | ||
.set('Authorization', `Bearer ${access_token}`); | ||
|
||
expect(response.status).toEqual(200); | ||
expect(response.body).toEqual({ | ||
message: 'Appointment registry deleted successfully', | ||
}); | ||
}); | ||
|
||
it('should return 404 if the appointment registry does not exist', async () => { | ||
const response = await request(app.getHttpServer()) | ||
.delete(`/appointment-registry/${patientAppointmentRegistry.id}/delete`) | ||
.set('Authorization', `Bearer ${access_token}`); | ||
|
||
expect(response.status).toEqual(404); | ||
expect(response.body.message).toEqual('registry not found'); | ||
}); | ||
|
||
it('should return 401 if the user is not authenticated', async () => { | ||
const response = await request(app.getHttpServer()).delete( | ||
`/appointment-registry/${patientAppointmentRegistry.id}/delete`, | ||
); | ||
|
||
expect(response.status).toEqual(401); | ||
expect(response.body.message).toEqual('Invalid JWT token'); | ||
}); | ||
}); |
11 changes: 11 additions & 0 deletions
11
...ers/api/use-cases/patient-appointment-registry/delete-patient-appointment-registry/dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { IsString } from 'class-validator'; | ||
|
||
export class DeletePatientAppointmentRegistryInputDto { | ||
@IsString() | ||
id!: string; | ||
} | ||
|
||
export class DeletePatientAppointmentRegistryOutputDto { | ||
@IsString() | ||
message!: string; | ||
} |
12 changes: 12 additions & 0 deletions
12
...delete-patient-appointment-registry/nestjs-delete-patient-appointment-registry.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { PatientAppointmentRegistryDatabaseRepository } from '../../../../../../core/domains/patient-appointment-registry/repositories/database-repository'; | ||
import { DeletePatientAppointmentRegistryService } from '../../../../../../core/domains/patient-appointment-registry/use-cases/delete-appointment-registry/delete-appointment-registry.service'; | ||
|
||
@Injectable() | ||
export class NestjsDeletePatientAppointmentRegistryService extends DeletePatientAppointmentRegistryService { | ||
constructor( | ||
patientAppointmentRegistryDatabaseRepository: PatientAppointmentRegistryDatabaseRepository, | ||
) { | ||
super(patientAppointmentRegistryDatabaseRepository); | ||
} | ||
} |
33 changes: 23 additions & 10 deletions
33
apps/core-rest-api/src/app/adapters/database/mappers/postgres-prisma-registry-mapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
apps/core-rest-api/tests/factories/make-patient-appointment-registry.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
import { PostgreSqlPrismaOrmService } from '../../src/app/adapters/database/infra/prisma/prisma.service'; | ||
import { PatientAppointmentRegistryEntity } from '../../src/app/core/domains/patient-appointment-registry/entities/registry/entity'; | ||
import { CreatePatientAppointmentRegistryDto } from '../../src/app/core/domains/patient-appointment-registry/use-cases/create-appointment-registry/create-appointment-registry-dto'; | ||
|
||
export function makePatientAppointmentRegistry( | ||
override: Partial<CreatePatientAppointmentRegistryDto> = {}, | ||
): PatientAppointmentRegistryEntity { | ||
const newAppointment = new PatientAppointmentRegistryEntity({ | ||
psychologistId: faker.string.uuid(), | ||
patientId: faker.string.uuid(), | ||
registry: { | ||
observations: faker.lorem.paragraph(), | ||
}, | ||
...override, | ||
}); | ||
|
||
return newAppointment; | ||
} | ||
|
||
@Injectable() | ||
export class PatientAppointmentRegistryFactory { | ||
constructor(private postgreSqlPrismaOrmService: PostgreSqlPrismaOrmService) {} | ||
|
||
async makePrismaPatientAppointmentRegistry( | ||
patientAppointmentRegistry: Partial<CreatePatientAppointmentRegistryDto> = {}, | ||
): Promise<PatientAppointmentRegistryEntity> { | ||
const newPrismaPatientAppointmentRegistry = makePatientAppointmentRegistry( | ||
patientAppointmentRegistry, | ||
); | ||
|
||
await this.postgreSqlPrismaOrmService['patientAppointmentRegistry'].create({ | ||
data: { | ||
id: newPrismaPatientAppointmentRegistry.id, | ||
patientId: newPrismaPatientAppointmentRegistry.patientId, | ||
psychologistId: newPrismaPatientAppointmentRegistry.psychologistId, | ||
registry: { | ||
observations: newPrismaPatientAppointmentRegistry.registry.observations, | ||
}, | ||
}, | ||
}); | ||
|
||
return newPrismaPatientAppointmentRegistry; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters