44 */
55
66import { getCurrentUser } from '@nextcloud/auth'
7+ import axios from '@nextcloud/axios'
8+ import { generateOcsUrl } from '@nextcloud/router'
79import { createPinia , setActivePinia } from 'pinia'
810import { beforeEach , describe , expect , it , vi } from 'vitest'
911import BrowserStorage from '../../services/BrowserStorage.js'
1012import { getTalkConfig } from '../../services/CapabilitiesManager.ts'
11- import { setPlaySounds } from '../../services/settingsService.ts'
1213
1314vi . mock ( '@nextcloud/auth' , ( ) => ( {
1415 getCurrentUser : vi . fn ( ) ,
1516} ) )
17+ vi . mock ( '@nextcloud/axios' , ( ) => ( {
18+ default : {
19+ post : vi . fn ( ( ) => Promise . resolve ( ) ) ,
20+ } ,
21+ } ) )
1622vi . mock ( '../../services/BrowserStorage.js' , ( ) => ( {
1723 default : {
1824 getItem : vi . fn ( ) ,
@@ -22,9 +28,6 @@ vi.mock('../../services/BrowserStorage.js', () => ({
2228vi . mock ( '../../services/CapabilitiesManager.ts' , ( ) => ( {
2329 getTalkConfig : vi . fn ( ) ,
2430} ) )
25- vi . mock ( '../../services/settingsService.ts' , ( ) => ( {
26- setPlaySounds : vi . fn ( ( ) => Promise . resolve ( ) ) ,
27- } ) )
2831
2932/**
3033 * The initial value is computed when the module is loaded, so load it fresh for every test
@@ -100,25 +103,28 @@ describe('soundsStore', () => {
100103 getTalkConfig . mockReturnValue ( true )
101104 const store = await loadSoundsStore ( )
102105 await store . setShouldPlaySounds ( false )
103- expect ( setPlaySounds ) . toHaveBeenCalledWith ( true , 'no' )
106+ expect ( axios . post ) . toHaveBeenCalledWith (
107+ generateOcsUrl ( 'apps/spreed/api/v1/settings/user' ) ,
108+ { key : 'play_sounds' , value : 'no' } ,
109+ )
104110 expect ( BrowserStorage . setItem ) . not . toHaveBeenCalled ( )
105111 expect ( store . shouldPlaySounds ) . toBe ( false )
106112 } )
107113
108- it ( 'leaves the value to browser storage when the server has no capability ' , async ( ) => {
114+ it ( 'saves to browser storage instead on older servers, since they cannot hand it back ' , async ( ) => {
109115 const store = await loadSoundsStore ( )
110116 await store . setShouldPlaySounds ( false )
111- expect ( setPlaySounds ) . toHaveBeenCalledWith ( false , 'no' )
112- expect ( BrowserStorage . setItem ) . not . toHaveBeenCalled ( )
117+ expect ( axios . post ) . not . toHaveBeenCalled ( )
118+ expect ( BrowserStorage . setItem ) . toHaveBeenCalledWith ( 'play_sounds' , 'no' )
113119 expect ( store . shouldPlaySounds ) . toBe ( false )
114120 } )
115121
116- it ( 'saves guests to browser storage through the settings service only ' , async ( ) => {
122+ it ( 'saves guests to browser storage' , async ( ) => {
117123 getCurrentUser . mockReturnValue ( null )
118124 const store = await loadSoundsStore ( )
119125 await store . setShouldPlaySounds ( true )
120- expect ( setPlaySounds ) . toHaveBeenCalledWith ( false , 'yes' )
121- expect ( BrowserStorage . setItem ) . not . toHaveBeenCalled ( )
126+ expect ( axios . post ) . not . toHaveBeenCalled ( )
127+ expect ( BrowserStorage . setItem ) . toHaveBeenCalledWith ( 'play_sounds' , 'yes' )
122128 } )
123129 } )
124130} )
0 commit comments