@@ -96,11 +96,6 @@ const instrumentDataSource = container.resolve(
9696 Tokens . InstrumentDataSource
9797) as InstrumentDataSource ;
9898
99- const mockRemoveScientistFromInstruments = jest . spyOn (
100- instrumentDataSource ,
101- 'removeScientistFromInstruments'
102- ) ;
103-
10499const mockAssignScientistToInstruments = jest . spyOn (
105100 instrumentDataSource ,
106101 'assignScientistToInstruments'
@@ -132,7 +127,6 @@ beforeAll(() => {
132127
133128beforeEach ( ( ) => {
134129 mockAssignScientistToInstruments . mockClear ( ) ;
135- mockRemoveScientistFromInstruments . mockClear ( ) ;
136130 mockGetRequiredInstrumentForRole . mockClear ( ) ;
137131} ) ;
138132
@@ -230,108 +224,23 @@ test('When a user requests multiple instruments, only new existing ones are adde
230224 expect ( result ) . toEqual ( [ lsfInstrument . id ] ) ;
231225} ) ;
232226
233- // getInstrumentsToRemove
234- test ( 'When a user has an instrument they have not requested, the instrument is removed' , async ( ) => {
235- const requiredInstruments : string [ ] = [ ] ;
236- const currentInstruments = [ isisInstrument ] ;
237-
238- const result = await userAuthorization . getInstrumentsToRemove (
239- requiredInstruments ,
240- currentInstruments
241- ) ;
242-
243- expect ( result ) . toEqual ( [ isisInstrument . id ] ) ;
244- } ) ;
245-
246- test ( 'When a user has an instrument they have requested, no instrument is removed' , async ( ) => {
247- const requiredInstruments = [ isisInstrument . name ] ;
248- const currentInstruments = [ isisInstrument ] ;
249-
250- const result = await userAuthorization . getInstrumentsToRemove (
251- requiredInstruments ,
252- currentInstruments
253- ) ;
254-
255- expect ( result ) . toEqual ( [ ] ) ;
256- } ) ;
257-
258- test ( 'When a user does not have an instrument they requested, no instrument is removed' , async ( ) => {
259- const requiredInstruments = [ isisInstrument . name ] ;
260- const currentInstruments : Instrument [ ] = [ ] ;
261-
262- const result = await userAuthorization . getInstrumentsToRemove (
263- requiredInstruments ,
264- currentInstruments
265- ) ;
266-
267- expect ( result ) . toEqual ( [ ] ) ;
268- } ) ;
269-
270- test ( 'When a user requests a nonexisting instrument, all other instruments are removed' , async ( ) => {
271- const requiredInstruments = [ nonExistingInstrumentName ] ;
272- const currentInstruments = [ isisInstrument , lsfInstrument ] ;
273-
274- const result = await userAuthorization . getInstrumentsToRemove (
275- requiredInstruments ,
276- currentInstruments
277- ) ;
278-
279- expect ( result ) . toEqual ( [ isisInstrument . id , lsfInstrument . id ] ) ;
280- } ) ;
281-
282- test ( 'When a user requests multiple instrument, only non requested ones are removed' , async ( ) => {
283- const requiredInstruments = [ isisInstrument . name ] ;
284- const currentInstruments : Instrument [ ] = [ isisInstrument , lsfInstrument ] ;
285-
286- const result = await userAuthorization . getInstrumentsToRemove (
287- requiredInstruments ,
288- currentInstruments
289- ) ;
290-
291- expect ( result ) . toEqual ( [ lsfInstrument . id ] ) ;
292- } ) ;
293-
294227//autoAssignRemoveInstruments
295- test ( 'When a user requires an instrument but does not have it, the instrument is assigned and no instrument are removed' , async ( ) => {
296- await userAuthorization . autoAssignRemoveInstruments (
297- 0 ,
298- [ isisInstrument . name ] ,
299- [ ] ,
300- true
301- ) ;
228+ test ( 'When a user requires an instrument but does not have it, the instrument is assigned' , async ( ) => {
229+ await userAuthorization . autoAssignInstruments ( 0 , [ isisInstrument . name ] , [ ] ) ;
302230
303231 expect ( mockAssignScientistToInstruments ) . toHaveBeenCalledWith ( 0 , [
304232 isisInstrument . id ,
305233 ] ) ;
306- expect ( mockRemoveScientistFromInstruments ) . toHaveBeenCalledTimes ( 0 ) ;
307234} ) ;
308235
309- test ( 'When a user does not require an instrument but has it, no instrument is assigned and the instrument is removed' , async ( ) => {
310- await userAuthorization . autoAssignRemoveInstruments (
311- 0 ,
312- [ ] ,
313- [ isisInstrument ] ,
314- true
315- ) ;
316-
317- expect ( mockAssignScientistToInstruments ) . toHaveBeenCalledTimes ( 0 ) ;
318- expect ( mockRemoveScientistFromInstruments ) . toHaveBeenCalledWith ( 0 , [
319- isisInstrument . id ,
320- ] ) ;
321- } ) ;
322-
323- test ( 'When a user requires an instrument but has a different one, the requested instrument is assigned and the current instrument is removed' , async ( ) => {
324- await userAuthorization . autoAssignRemoveInstruments (
236+ test ( 'When a user requires an instrument but has a different one, the requested instrument is assigned and the current instrument stays the same' , async ( ) => {
237+ await userAuthorization . autoAssignInstruments (
325238 0 ,
326239 [ isisInstrument . name ] ,
327- [ lsfInstrument ] ,
328- true
240+ [ lsfInstrument ]
329241 ) ;
330242
331243 expect ( mockAssignScientistToInstruments ) . toHaveBeenCalledWith ( 0 , [
332244 isisInstrument . id ,
333245 ] ) ;
334- expect ( mockRemoveScientistFromInstruments ) . toHaveBeenCalledWith ( 0 , [
335- lsfInstrument . id ,
336- ] ) ;
337246} ) ;
0 commit comments