@@ -13,6 +13,8 @@ const {
13
13
const utils = require ( '../../../src/components/utils' ) ;
14
14
const { Permissions, ResourceType, AuthType } = require ( '../../../src/components/constants' ) ;
15
15
16
+ // Mock out utils library and use a spy to observe behavior
17
+ jest . mock ( '../../../src/components/utils' ) ;
16
18
const SYSTEM_TIME = new Date ( '2024-03-08T19:00:00.000Z' ) ;
17
19
const mockResponse = ( ) => {
18
20
const res = { } ;
@@ -47,6 +49,7 @@ describe('createInvite', () => {
47
49
const bucketSearchPermissionSpy = jest . spyOn ( bucketPermissionService , 'searchPermissions' ) ;
48
50
const getCurrentIdentitySpy = jest . spyOn ( utils , 'getCurrentIdentity' ) ;
49
51
const getCurrentUserIdSpy = jest . spyOn ( userService , 'getCurrentUserId' ) ;
52
+ const addDashesToUuidSpy = jest . spyOn ( utils , 'addDashesToUuid' ) ;
50
53
const inviteCreateSpy = jest . spyOn ( inviteService , 'create' ) ;
51
54
const objectReadSpy = jest . spyOn ( objectService , 'read' ) ;
52
55
const objectSearchPermissionSpy = jest . spyOn ( objectPermissionService , 'searchPermissions' ) ;
@@ -58,6 +61,7 @@ describe('createInvite', () => {
58
61
beforeEach ( ( ) => {
59
62
getCurrentIdentitySpy . mockReturnValue ( USR_IDENTITY ) ;
60
63
getCurrentUserIdSpy . mockResolvedValue ( USR_ID ) ;
64
+ addDashesToUuidSpy . mockReturnValue ( RESOURCE ) ;
61
65
} ) ;
62
66
63
67
it ( 'should 422 when expiresAt is more than 7 days away' , async ( ) => {
@@ -113,7 +117,7 @@ describe('createInvite', () => {
113
117
it ( 'should 403 when no object manage permission found' , async ( ) => {
114
118
const req = {
115
119
body : { objectId : RESOURCE } ,
116
- currentUser : { AuthType : AuthType . BEARER }
120
+ currentUser : { authType : AuthType . BEARER }
117
121
} ;
118
122
119
123
objectReadSpy . mockResolvedValue ( { } ) ;
@@ -137,7 +141,7 @@ describe('createInvite', () => {
137
141
it ( 'should 403 when no object nor bucket manage permission found' , async ( ) => {
138
142
const req = {
139
143
body : { objectId : RESOURCE } ,
140
- currentUser : { AuthType : AuthType . BEARER }
144
+ currentUser : { authType : AuthType . BEARER }
141
145
} ;
142
146
143
147
bucketSearchPermissionSpy . mockResolvedValue ( [ ] ) ;
@@ -165,7 +169,7 @@ describe('createInvite', () => {
165
169
it ( 'should 201 when object manage permission found' , async ( ) => {
166
170
const req = {
167
171
body : { objectId : RESOURCE } ,
168
- currentUser : { AuthType : AuthType . BEARER }
172
+ currentUser : { authType : AuthType . BEARER }
169
173
} ;
170
174
171
175
inviteCreateSpy . mockResolvedValue ( { token : TOKEN } ) ;
@@ -195,7 +199,7 @@ describe('createInvite', () => {
195
199
const email = '[email protected] ' ;
196
200
const req = {
197
201
body : { objectId : RESOURCE , email : email } ,
198
- currentUser : { AuthType : AuthType . BEARER }
202
+ currentUser : { authType : AuthType . BEARER }
199
203
} ;
200
204
201
205
bucketSearchPermissionSpy . mockResolvedValue ( [ { } ] ) ;
@@ -229,7 +233,7 @@ describe('createInvite', () => {
229
233
const expiresAt = Math . floor ( new Date ( '2024-03-09T19:00:00.000Z' ) / 1000 ) ;
230
234
const req = {
231
235
body : { objectId : RESOURCE , expiresAt : expiresAt } ,
232
- currentUser : { AuthType : AuthType . BASIC }
236
+ currentUser : { authType : AuthType . BASIC }
233
237
} ;
234
238
235
239
inviteCreateSpy . mockResolvedValue ( { token : TOKEN } ) ;
@@ -277,7 +281,7 @@ describe('createInvite', () => {
277
281
it ( 'should 403 when no bucket manage permission found' , async ( ) => {
278
282
const req = {
279
283
body : { bucketId : RESOURCE } ,
280
- currentUser : { AuthType : AuthType . BEARER }
284
+ currentUser : { authType : AuthType . BEARER }
281
285
} ;
282
286
283
287
bucketReadSpy . mockResolvedValue ( { } ) ;
@@ -302,7 +306,7 @@ describe('createInvite', () => {
302
306
const email = '[email protected] ' ;
303
307
const req = {
304
308
body : { bucketId : RESOURCE , email : email } ,
305
- currentUser : { AuthType : AuthType . BEARER }
309
+ currentUser : { authType : AuthType . BEARER }
306
310
} ;
307
311
308
312
bucketReadSpy . mockResolvedValue ( { } ) ;
@@ -332,7 +336,7 @@ describe('createInvite', () => {
332
336
const expiresAt = Math . floor ( new Date ( '2024-03-09T19:00:00.000Z' ) / 1000 ) ;
333
337
const req = {
334
338
body : { bucketId : RESOURCE , expiresAt : expiresAt } ,
335
- currentUser : { AuthType : AuthType . BASIC }
339
+ currentUser : { authType : AuthType . BASIC }
336
340
} ;
337
341
338
342
bucketReadSpy . mockResolvedValue ( { bucketId : RESOURCE } ) ;
@@ -365,6 +369,7 @@ describe('useInvite', () => {
365
369
const bucketReadSpy = jest . spyOn ( bucketService , 'read' ) ;
366
370
const getCurrentIdentitySpy = jest . spyOn ( utils , 'getCurrentIdentity' ) ;
367
371
const getCurrentUserIdSpy = jest . spyOn ( userService , 'getCurrentUserId' ) ;
372
+ const addDashesToUuidSpy = jest . spyOn ( utils , 'addDashesToUuid' ) ;
368
373
const inviteDeleteSpy = jest . spyOn ( inviteService , 'delete' ) ;
369
374
const inviteReadSpy = jest . spyOn ( inviteService , 'read' ) ;
370
375
const objectAddPermissionsSpy = jest . spyOn ( objectPermissionService , 'addPermissions' ) ;
@@ -377,6 +382,7 @@ describe('useInvite', () => {
377
382
beforeEach ( ( ) => {
378
383
getCurrentIdentitySpy . mockReturnValue ( USR_IDENTITY ) ;
379
384
getCurrentUserIdSpy . mockResolvedValue ( USR_ID ) ;
385
+ addDashesToUuidSpy . mockReturnValue ( TOKEN ) ;
380
386
} ) ;
381
387
382
388
0 commit comments