@@ -11,7 +11,6 @@ import { saveItemAndMembership } from '../../../itemMembership/test/fixtures/mem
1111import { saveMember } from '../../../member/test/fixtures/members' ;
1212import { savePublicItem } from '../../test/fixtures/items' ;
1313import { ItemGeolocation } from './ItemGeolocation' ;
14- import { ItemGeolocationNotFound } from './errors' ;
1514
1615// mock datasource
1716jest . mock ( '../../../../plugins/datasource' ) ;
@@ -114,13 +113,13 @@ describe('Item Geolocation', () => {
114113 } ) ;
115114 } ) ;
116115
117- it ( 'Throws if no geolocation' , async ( ) => {
116+ it ( 'Return null if no geolocation' , async ( ) => {
118117 const res = await app . inject ( {
119118 method : HttpMethod . GET ,
120119 url : `${ ITEMS_ROUTE_PREFIX } /${ item . id } /geolocation` ,
121120 } ) ;
122- expect ( res . statusCode ) . toBe ( StatusCodes . NOT_FOUND ) ;
123- expect ( res . json ( ) ) . toMatchObject ( new ItemGeolocationNotFound ( expect . anything ( ) ) ) ;
121+ expect ( res . statusCode ) . toBe ( StatusCodes . OK ) ;
122+ expect ( res . json ( ) ) . toBeNull ( ) ;
124123 } ) ;
125124
126125 it ( 'Throws if id is not a uuid' , async ( ) => {
@@ -228,6 +227,51 @@ describe('Item Geolocation', () => {
228227 expect ( res . json ( ) ) . toHaveLength ( 3 ) ;
229228 expectItemGeolocations ( res . json ( ) , [ geoloc1 , geoloc2 , geoloc3 ] ) ;
230229 } ) ;
230+
231+ it ( 'Get item geolocations within parent item' , async ( ) => {
232+ const { item : parentItem } = await saveItemAndMembership ( { member : actor } ) ;
233+ const { item : item1 } = await saveItemAndMembership ( {
234+ item : { name : 'hello bye' } ,
235+ member : actor ,
236+ parentItem,
237+ } ) ;
238+ const geoloc1 = await repository . save ( { item : item1 , lat : 1 , lng : 2 , country : 'de' } ) ;
239+ const { item : item2 } = await saveItemAndMembership ( {
240+ item : { description : 'hello bye' } ,
241+ member : actor ,
242+ parentItem,
243+ } ) ;
244+ const geoloc2 = await repository . save ( { item : item2 , lat : 1 , lng : 2 , country : 'de' } ) ;
245+ const { item : item3 } = await saveItemAndMembership ( {
246+ item : { name : 'bye hello' } ,
247+ member : actor ,
248+ } ) ;
249+ await repository . save ( { item : item3 , lat : 1 , lng : 2 , country : 'de' } ) ;
250+
251+ const res = await app . inject ( {
252+ method : HttpMethod . GET ,
253+ url : `${ ITEMS_ROUTE_PREFIX } /geolocation?parentItemId=${ parentItem . id } ` ,
254+ } ) ;
255+ expect ( res . statusCode ) . toBe ( StatusCodes . OK ) ;
256+ expect ( res . json ( ) ) . toHaveLength ( 2 ) ;
257+ expectItemGeolocations ( res . json ( ) , [ geoloc1 , geoloc2 ] ) ;
258+ } ) ;
259+
260+ it ( 'Throw for incorrect parent item id' , async ( ) => {
261+ const res = await app . inject ( {
262+ method : HttpMethod . GET ,
263+ url : `${ ITEMS_ROUTE_PREFIX } /geolocation?lat1=1&lat2=1&lng1=1&lng2=2&parentItemId=incorrect-id` ,
264+ } ) ;
265+ expect ( res . statusCode ) . toBe ( StatusCodes . BAD_REQUEST ) ;
266+ } ) ;
267+
268+ it ( 'Throw if no parent item id and no lat lng' , async ( ) => {
269+ const res = await app . inject ( {
270+ method : HttpMethod . GET ,
271+ url : `${ ITEMS_ROUTE_PREFIX } /geolocation` ,
272+ } ) ;
273+ expect ( res . statusCode ) . toBe ( StatusCodes . BAD_REQUEST ) ;
274+ } ) ;
231275 } ) ;
232276 } ) ;
233277
0 commit comments