diff --git a/src/doctor/doctor.controller.spec.ts b/src/doctor/doctor.controller.spec.ts index b39ed10b42f108bc73ea6b4cbd560921c155bb05..481350acb70ca8b6a170185db20f9df0a48e7561 100644 --- a/src/doctor/doctor.controller.spec.ts +++ b/src/doctor/doctor.controller.spec.ts @@ -43,7 +43,7 @@ describe('DoctorController', () => { it('should create a doctor and return success with doctorId', async () => { const createDoctorDto: CreateDoctorDto = { doctorName: 'Dr. Test', - doctorQualificationId: 'qual-uuid-xyz', + doctorQualificationId: 'c6f3dc4a-7e2f-4f9b-a77b-bbccffe42388', doctorSpecialityId: 'spec-uuid-abc', emailId: 'dr.test@example.com', contactNo: '1234567890', doctorRegNo: 'REG12345', @@ -63,7 +63,7 @@ describe('DoctorController', () => { it('should return error response if service throws an error', async () => { const createDoctorDto: CreateDoctorDto = { doctorName: 'Dr. Error', - doctorQualificationId: 'qual-uuid-err-xyz', + doctorQualificationId: 'c6f3dc4a-7e2f-4f9b-a77b-bbccffe42388', doctorSpecialityId: 'spec-uuid-err-abc', emailId: 'dr.error@example.com', contactNo: '0987654321', doctorRegNo: 'REG67890', @@ -148,7 +148,8 @@ describe('updateDoctors', () => { doctorQualificationId: '58c1b3f1-0007-4444-aaaa-000000000007', contactNo: '7208806389', hprCode: 'HPR-111', emailId: 'prathviraj@abc.com', - panNo: 'SLEUS7686D', address: 'Mumbai', + panNo: 'SLEUS7686D', + address: 'Mumbai', stateId: 'f77da58f-422f-4b26-b6ab-ab02fe9cd00d', cityId: 'e9af1491-7b1e-4010-9542-af36700d5f89', pincode: '2c1fe645-989c-4705-91ef-36f3c78c0d08', @@ -166,3 +167,27 @@ describe('updateDoctors', () => { expect(result).toEqual(response); }); }); + +describe('CreateDoctorDto validation', () => { + it('should validate doctorQualificationId as a UUID', async () => { + const { validate } = await import('class-validator'); + const dto = new CreateDoctorDto(); + dto.doctorQualificationId = 'c6f3dc4a-7e2f-4f9b-a77b-bbccffe42388'; + // Add required fields to pass validation + dto.doctorName = 'Dr. Valid'; + dto.doctorSpecialityId = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890'; + dto.emailId = 'dr.valid@example.com'; + dto.contactNo = '1234567890'; + dto.doctorRegNo = 'REG12345'; + dto.hprCode = 'HPR123'; + dto.panNo = 'ABCDE1234F'; + dto.address = '123 Test St'; + dto.pincodeId = 'b1c2d3e4-f5a6-7890-bcde-fa1234567890'; + dto.latitude = 12.345678; + dto.longitude = 78.901234; + dto.created_by = '6f6b90a9-331e-4874-a374-ebf65a1bce2a'; + dto.updated_by = '6f6b90a9-331e-4874-a374-ebf65a1bce2a'; + const errors = await validate(dto); + expect(errors.length).toBe(0); + }); +}); diff --git a/src/doctor/doctor.service.spec.ts b/src/doctor/doctor.service.spec.ts index 090caa06b0f7626d4e5d42693a01886f837c7805..a65e857318ae7c4b6ec0bd64b3490014f298f8f0 100644 --- a/src/doctor/doctor.service.spec.ts +++ b/src/doctor/doctor.service.spec.ts @@ -98,6 +98,33 @@ describe('DoctorService', () => { }); describe('addDoctor', () => { + it('should set updated_by to created_by if updated_by is not provided', async () => { + const payload = { + doctorName: 'Dr. Fallback', + emailId: 'fallback@example.com', + contactNo: '9876543210', + doctorQualificationId: 'uuid-qual', + doctorSpecialityId: 'uuid-spec', + doctorRegNo: 'REG999', + hprCode: 'HPR999', + panNo: 'ZZZZZ9999Z', + address: 'Fallback St', + pincodeId: 'uuid-pincode', + latitude: 10.1234, + longitude: 20.5678, + created_by: 'creator-fallback-uuid', + // updated_by is intentionally omitted + }; + (mockPrismaService.doctor_master.create as jest.Mock).mockResolvedValue({ id: 'mock-id' }); + await service.addDoctor(payload as any); + expect(mockPrismaService.doctor_master.create).toHaveBeenCalledWith( + expect.objectContaining({ + data: expect.objectContaining({ + updated_by: payload.created_by, + }), + }) + ); + }); const baseDoctorDto: CreateDoctorDto = { doctorName: 'Dr. Test User', emailId: 'test.user@example.com', contactNo: '1234567890', doctorRegNo: 'REG123',