-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): add http controllet to get dataViz collection
- Loading branch information
Showing
4 changed files
with
87 additions
and
16 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
36 changes: 36 additions & 0 deletions
36
packages/api/src/interfaces/http/dataViz/amountsVsProgrammeRegion.http.test.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,36 @@ | ||
import { | ||
AMOUNTS_VS_PROGRAMME_REGION_DBOS, | ||
AMOUNTS_VS_PROGRAMME_REGION_ENTITIES, | ||
} from "../../../modules/dataViz/amountsVsProgrammeRegion/__fixtures__/amountsVSProgrammeRegion.fixture"; | ||
import amountsVsProgrammeRegionService from "../../../modules/dataViz/amountsVsProgrammeRegion/amountsVsProgrammeRegion.service"; | ||
import { AmountsVsProgrammeRegionHttp } from "./amountsVsProgrammeRegion.http"; | ||
|
||
const controller = new AmountsVsProgrammeRegionHttp(); | ||
|
||
const AMOUNTS_VS_PROGRAMME_REGION_DATA = AMOUNTS_VS_PROGRAMME_REGION_DBOS.map(({ _id, ...rest }) => rest); | ||
|
||
describe("AmountsVsProgrammeRegionHttp", () => { | ||
let getAmountsVsProgrammeRegionSpy: jest.SpyInstance; | ||
beforeAll(() => { | ||
getAmountsVsProgrammeRegionSpy = jest | ||
.spyOn(amountsVsProgrammeRegionService, "getAmountsVsProgrammeRegion") | ||
.mockResolvedValue(AMOUNTS_VS_PROGRAMME_REGION_DATA); | ||
}); | ||
|
||
afterAll(() => { | ||
getAmountsVsProgrammeRegionSpy.mockRestore(); | ||
}); | ||
|
||
describe("getAmountsVsProgrammeRegion", () => { | ||
it("should call service", async () => { | ||
await controller.getAmountsVsProgrammeRegion(); | ||
expect(getAmountsVsProgrammeRegionSpy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it("should return data", async () => { | ||
const expected = { montantVsProgrammeRegionData: AMOUNTS_VS_PROGRAMME_REGION_ENTITIES }; | ||
const actual = await controller.getAmountsVsProgrammeRegion(); | ||
expect(actual).toEqual(expected); | ||
}); | ||
}); | ||
}); |
23 changes: 23 additions & 0 deletions
23
packages/api/src/interfaces/http/dataViz/amountsVsProgrammeRegion.http.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,23 @@ | ||
import { Controller, Get, Route, Security, Response, Tags } from "tsoa"; | ||
import { GetMontantsVsProgrammeRegionResponseDto } from "dto"; | ||
import { HttpErrorInterface } from "../../../shared/errors/httpErrors/HttpError"; | ||
|
||
import amountsVsProgrammeRegionService from "../../../modules/dataViz/amountsVsProgrammeRegion/amountsVsProgrammeRegion.service"; | ||
|
||
// ici je dois mettre plutôt /dataviz/amount-vs-programme-region ? | ||
@Route("montant-vs-programme-region") | ||
@Security("jwt") | ||
@Tags("dv-montantVsProgrammeRegion Controller") | ||
export class AmountsVsProgrammeRegionHttp extends Controller { | ||
/** | ||
* Get information about dv-montantVsProgrammeRegion collection | ||
* No parameters | ||
*/ | ||
|
||
@Get("/") | ||
@Response<HttpErrorInterface>("404") | ||
public async getAmountsVsProgrammeRegion(): Promise<GetMontantsVsProgrammeRegionResponseDto> { | ||
const montantVsProgrammeRegionData = await amountsVsProgrammeRegionService.getAmountsVsProgrammeRegion(); | ||
return { montantVsProgrammeRegionData }; | ||
} | ||
} |
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