1
+ import { IAlbumRepository } from 'src/interfaces/album.interface' ;
1
2
import { IMapRepository } from 'src/interfaces/map.interface' ;
2
3
import { IPartnerRepository } from 'src/interfaces/partner.interface' ;
3
4
import { MapService } from 'src/services/map.service' ;
5
+ import { albumStub } from 'test/fixtures/album.stub' ;
4
6
import { assetStub } from 'test/fixtures/asset.stub' ;
5
7
import { authStub } from 'test/fixtures/auth.stub' ;
8
+ import { partnerStub } from 'test/fixtures/partner.stub' ;
6
9
import { newTestService } from 'test/utils' ;
7
10
import { Mocked } from 'vitest' ;
8
11
9
12
describe ( MapService . name , ( ) => {
10
13
let sut : MapService ;
11
14
15
+ let albumMock : Mocked < IAlbumRepository > ;
12
16
let mapMock : Mocked < IMapRepository > ;
13
17
let partnerMock : Mocked < IPartnerRepository > ;
14
18
15
19
beforeEach ( ( ) => {
16
- ( { sut, mapMock, partnerMock } = newTestService ( MapService ) ) ;
20
+ ( { sut, albumMock , mapMock, partnerMock } = newTestService ( MapService ) ) ;
17
21
} ) ;
18
22
19
23
describe ( 'getMapMarkers' , ( ) => {
@@ -35,5 +39,62 @@ describe(MapService.name, () => {
35
39
expect ( markers ) . toHaveLength ( 1 ) ;
36
40
expect ( markers [ 0 ] ) . toEqual ( marker ) ;
37
41
} ) ;
42
+
43
+ it ( 'should include partner assets' , async ( ) => {
44
+ const asset = assetStub . withLocation ;
45
+ const marker = {
46
+ id : asset . id ,
47
+ lat : asset . exifInfo ! . latitude ! ,
48
+ lon : asset . exifInfo ! . longitude ! ,
49
+ city : asset . exifInfo ! . city ,
50
+ state : asset . exifInfo ! . state ,
51
+ country : asset . exifInfo ! . country ,
52
+ } ;
53
+ partnerMock . getAll . mockResolvedValue ( [ partnerStub . adminToUser1 ] ) ;
54
+ mapMock . getMapMarkers . mockResolvedValue ( [ marker ] ) ;
55
+
56
+ const markers = await sut . getMapMarkers ( authStub . user1 , { withPartners : true } ) ;
57
+
58
+ expect ( mapMock . getMapMarkers ) . toHaveBeenCalledWith (
59
+ [ authStub . user1 . user . id , partnerStub . adminToUser1 . sharedById ] ,
60
+ expect . arrayContaining ( [ ] ) ,
61
+ { withPartners : true } ,
62
+ ) ;
63
+ expect ( markers ) . toHaveLength ( 1 ) ;
64
+ expect ( markers [ 0 ] ) . toEqual ( marker ) ;
65
+ } ) ;
66
+
67
+ it ( 'should include assets from shared albums' , async ( ) => {
68
+ const asset = assetStub . withLocation ;
69
+ const marker = {
70
+ id : asset . id ,
71
+ lat : asset . exifInfo ! . latitude ! ,
72
+ lon : asset . exifInfo ! . longitude ! ,
73
+ city : asset . exifInfo ! . city ,
74
+ state : asset . exifInfo ! . state ,
75
+ country : asset . exifInfo ! . country ,
76
+ } ;
77
+ partnerMock . getAll . mockResolvedValue ( [ ] ) ;
78
+ mapMock . getMapMarkers . mockResolvedValue ( [ marker ] ) ;
79
+ albumMock . getOwned . mockResolvedValue ( [ albumStub . empty ] ) ;
80
+ albumMock . getShared . mockResolvedValue ( [ albumStub . sharedWithUser ] ) ;
81
+
82
+ const markers = await sut . getMapMarkers ( authStub . user1 , { withSharedAlbums : true } ) ;
83
+
84
+ expect ( markers ) . toHaveLength ( 1 ) ;
85
+ expect ( markers [ 0 ] ) . toEqual ( marker ) ;
86
+ } ) ;
87
+ } ) ;
88
+
89
+ describe ( 'reverseGeocode' , ( ) => {
90
+ it ( 'should reverse geocode a location' , async ( ) => {
91
+ mapMock . reverseGeocode . mockResolvedValue ( { city : 'foo' , state : 'bar' , country : 'baz' } ) ;
92
+
93
+ await expect ( sut . reverseGeocode ( { lat : 42 , lon : 69 } ) ) . resolves . toEqual ( [
94
+ { city : 'foo' , state : 'bar' , country : 'baz' } ,
95
+ ] ) ;
96
+
97
+ expect ( mapMock . reverseGeocode ) . toHaveBeenCalledWith ( { latitude : 42 , longitude : 69 } ) ;
98
+ } ) ;
38
99
} ) ;
39
100
} ) ;
0 commit comments