Skip to content

Commit 20cd0ec

Browse files
committed
fix(sounds): adjust test scenarios
- setPlaySounds mock was unnecessary, since it skipped BrowserStorage call - mock axios.post instead Assisted-by: ClaudeCode:claude-sonnet-5 Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
1 parent fc22ff9 commit 20cd0ec

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

‎src/stores/__tests__/sounds.spec.js‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@
44
*/
55

66
import { getCurrentUser } from '@nextcloud/auth'
7+
import axios from '@nextcloud/axios'
8+
import { generateOcsUrl } from '@nextcloud/router'
79
import { createPinia, setActivePinia } from 'pinia'
810
import { beforeEach, describe, expect, it, vi } from 'vitest'
911
import BrowserStorage from '../../services/BrowserStorage.js'
1012
import { getTalkConfig } from '../../services/CapabilitiesManager.ts'
11-
import { setPlaySounds } from '../../services/settingsService.ts'
1213

1314
vi.mock('@nextcloud/auth', () => ({
1415
getCurrentUser: vi.fn(),
1516
}))
17+
vi.mock('@nextcloud/axios', () => ({
18+
default: {
19+
post: vi.fn(() => Promise.resolve()),
20+
},
21+
}))
1622
vi.mock('../../services/BrowserStorage.js', () => ({
1723
default: {
1824
getItem: vi.fn(),
@@ -22,9 +28,6 @@ vi.mock('../../services/BrowserStorage.js', () => ({
2228
vi.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

Comments
 (0)