-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from jembi/feat/add-server-config-id-to-user
Feat/add server config id to user
- Loading branch information
Showing
15 changed files
with
179 additions
and
50 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
prisma/migrations/20240919145939_added_server_config_id_to_user/migration.sql
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,5 @@ | ||
-- AlterTable | ||
ALTER TABLE "user" ADD COLUMN "server_config_id" TEXT; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "user" ADD CONSTRAINT "user_server_config_id_fkey" FOREIGN KEY ("server_config_id") REFERENCES "server_config"("id") ON DELETE SET NULL ON UPDATE CASCADE; |
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
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ import { NextRequest, NextResponse } from 'next/server'; | |
import { POST } from '@/app/api/v1/users/route'; | ||
import { getUserProfile } from '@/app/utils/authentication'; | ||
import { handleApiValidationError } from '@/app/utils/error-handler'; | ||
import { mapEntityToModel } from '@/mappers/server-config-mapper'; | ||
import { mapDtoToModel, mapModelToDto } from '@/mappers/user-mapper'; | ||
import { HapiFhirServiceFactory } from '@/services/hapi-fhir-factory'; | ||
import { IHapiFhirService } from '@/services/hapi-fhir.interface'; | ||
|
@@ -62,7 +63,7 @@ describe('POST /api/users', () => { | |
|
||
const mockRoute = '/api/v1/users'; | ||
let mockService: jest.Mocked<IHapiFhirService>; | ||
(getUserProfile as jest.Mock).mockResolvedValue(true); | ||
(getUserProfile as jest.Mock).mockResolvedValue({ email: '[email protected]' }); | ||
|
||
HapiFhirServiceFactory.getService = jest.fn().mockReturnValue(mockService); | ||
|
||
|
@@ -74,7 +75,13 @@ describe('POST /api/users', () => { | |
(mapDtoToModel as jest.Mock).mockReturnValue(mockUserModel); | ||
(addUserUseCase as jest.Mock).mockResolvedValue(mockUserModel); | ||
(mapModelToDto as jest.Mock).mockReturnValue(mockUserDto); | ||
(searchPatientUseCase as jest.Mock).mockResolvedValue('patient id'); | ||
(searchPatientUseCase as jest.Mock).mockResolvedValue({ | ||
patient: { id: 'patient id' }, | ||
serverConfig: mapEntityToModel({ | ||
id: 'server-config-id', | ||
endpoint_url: 'http://test.com', | ||
}), | ||
}); | ||
|
||
const request = mockRequest(mockCreateUserDto); | ||
const response = await POST(request); | ||
|
@@ -88,6 +95,13 @@ describe('POST /api/users', () => { | |
|
||
it('should handle validation errors and return status 400', async () => { | ||
const error = new Error('Validation error'); | ||
(searchPatientUseCase as jest.Mock).mockResolvedValue({ | ||
patient: { id: 'patient id' }, | ||
serverConfig: mapEntityToModel({ | ||
id: 'server-config-id', | ||
endpoint_url: 'http://test.com', | ||
}), | ||
}); | ||
(addUserUseCase as jest.Mock).mockRejectedValue(error); | ||
(handleApiValidationError as jest.Mock).mockReturnValue( | ||
NextResponse.json({ message: 'Validation error' }, { status: 400 }), | ||
|
@@ -109,6 +123,13 @@ describe('POST /api/users', () => { | |
|
||
it('should handle unexpected errors and return status 500', async () => { | ||
const error = new Error('Unexpected error'); | ||
(searchPatientUseCase as jest.Mock).mockResolvedValue({ | ||
patient: { id: 'patient id' }, | ||
serverConfig: mapEntityToModel({ | ||
id: 'server-config-id', | ||
endpoint_url: 'http://test.com', | ||
}), | ||
}); | ||
(addUserUseCase as jest.Mock).mockRejectedValue(error); | ||
(handleApiValidationError as jest.Mock).mockReturnValue( | ||
NextResponse.json({ message: 'Unexpected error' }, { status: 500 }), | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
export class CreateUserDto { | ||
userId: string; | ||
patientId: string; | ||
serverConfigId?: string; | ||
} | ||
|
||
/** | ||
|
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
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { ServerConfigEntity } from '@/entities/server_config'; | ||
import { ServerConfigModel } from '@/domain/models/server-config'; | ||
|
||
import { IHapiFhirService } from './hapi-fhir.interface'; | ||
import { HapiFhirService } from './hapi-fhir.service'; | ||
|
||
export class HapiFhirServiceFactory { | ||
static getService(serverConfig: ServerConfigEntity): IHapiFhirService { | ||
return new HapiFhirService(serverConfig.endpoint_url); | ||
static getService(serverConfig: ServerConfigModel): IHapiFhirService { | ||
return new HapiFhirService(serverConfig.getEndpointUrl()); | ||
} | ||
} |
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
Oops, something went wrong.