@@ -28,6 +28,51 @@ app.use(router.routes())
2828
2929beforeEach ( jest . resetAllMocks )
3030describe ( 'property-base-service' , ( ) => {
31+ describe ( 'GET /propertyBase/buildings/by-building-code/:buildingCode' , ( ) => {
32+ it ( 'returns 200 and a building by code' , async ( ) => {
33+ const buildingMock = factory . building . build ( )
34+ const getBuildingSpy = jest
35+ . spyOn ( propertyBaseAdapter , 'getBuildingByCode' )
36+ . mockResolvedValueOnce ( { ok : true , data : buildingMock } )
37+
38+ const res = await request ( app . callback ( ) ) . get (
39+ `/propertyBase/buildings/by-building-code/${ buildingMock . code } `
40+ )
41+
42+ expect ( res . status ) . toBe ( 200 )
43+ expect ( getBuildingSpy ) . toHaveBeenCalledWith ( buildingMock . code )
44+ expect ( JSON . stringify ( res . body . content ) ) . toEqual (
45+ JSON . stringify ( buildingMock )
46+ )
47+ } )
48+
49+ it ( 'returns 404 if no building is found' , async ( ) => {
50+ const getBuildingSpy = jest
51+ . spyOn ( propertyBaseAdapter , 'getBuildingByCode' )
52+ . mockResolvedValueOnce ( { ok : false , err : 'not-found' } )
53+
54+ const res = await request ( app . callback ( ) ) . get (
55+ '/propertyBase/buildings/by-building-code/123-456'
56+ )
57+
58+ expect ( res . status ) . toBe ( 404 )
59+ expect ( getBuildingSpy ) . toHaveBeenCalledWith ( '123-456' )
60+ } )
61+
62+ it ( 'returns 500 if an error occurs' , async ( ) => {
63+ const getBuildingSpy = jest
64+ . spyOn ( propertyBaseAdapter , 'getBuildingByCode' )
65+ . mockResolvedValueOnce ( { ok : false , err : 'unknown' } )
66+
67+ const res = await request ( app . callback ( ) ) . get (
68+ '/propertyBase/buildings/by-building-code/123-456'
69+ )
70+
71+ expect ( res . status ) . toBe ( 500 )
72+ expect ( getBuildingSpy ) . toHaveBeenCalledWith ( '123-456' )
73+ } )
74+ } )
75+
3176 describe ( 'GET /propertyBase/companies' , ( ) => {
3277 it ( 'returns 200 and a list of companies' , async ( ) => {
3378 const companiesMock = factory . company . buildList ( 3 )
0 commit comments