|
1 | | -import { mock } from 'vitest-mock-extended' |
| 1 | +import { mock, mockDeep } from 'vitest-mock-extended' |
2 | 2 | import { createApp, defineComponent, App } from 'vue' |
3 | | -import { useAppsStore, useConfigStore } from '@opencloud-eu/web-pkg' |
| 3 | +import { |
| 4 | + CapabilityStore, |
| 5 | + ClientService, |
| 6 | + ConfigStore, |
| 7 | + useAppsStore, |
| 8 | + useConfigStore, |
| 9 | + useUpdatesStore |
| 10 | +} from '@opencloud-eu/web-pkg' |
4 | 11 | import { |
5 | 12 | initializeApplications, |
6 | 13 | announceApplicationsReady, |
7 | 14 | announceCustomScripts, |
8 | 15 | announceCustomStyles, |
9 | | - announceConfiguration |
| 16 | + announceConfiguration, |
| 17 | + announceUpdates |
10 | 18 | } from '../../../src/container/bootstrap' |
11 | 19 | import { buildApplication, loadApplication } from '../../../src/container/application' |
12 | | -import { createTestingPinia } from '@opencloud-eu/web-test-helpers' |
| 20 | +import { createTestingPinia, mockAxiosResolve } from '@opencloud-eu/web-test-helpers' |
13 | 21 |
|
14 | 22 | vi.mock('../../../src/container/application') |
15 | 23 |
|
@@ -217,3 +225,46 @@ describe('announceConfiguration', () => { |
217 | 225 | expect(configStore.options.embed.enabled).toStrictEqual(false) |
218 | 226 | }) |
219 | 227 | }) |
| 228 | + |
| 229 | +describe('announceUpdates', () => { |
| 230 | + it('does not contact the update server, if capability is turned off', async () => { |
| 231 | + const configStore = mockDeep<ConfigStore>({ serverUrl: 'https://demo.opencloud.eu' }) |
| 232 | + const capabilityStore = mockDeep<CapabilityStore>({ |
| 233 | + capabilities: { |
| 234 | + core: { 'check-for-updates': false } |
| 235 | + }, |
| 236 | + status: { productversion: '3.5.0', edition: 'rolling' } |
| 237 | + }) |
| 238 | + const updatesStore = useUpdatesStore() |
| 239 | + const clientService = mockDeep<ClientService>() |
| 240 | + |
| 241 | + clientService.httpAuthenticated.get.mockResolvedValue(mockAxiosResolve({})) |
| 242 | + await announceUpdates({ clientService, updatesStore, configStore, capabilityStore }) |
| 243 | + expect(clientService.httpUnAuthenticated.get).not.toHaveBeenCalled() |
| 244 | + }) |
| 245 | + |
| 246 | + it('sends the correct params to the update server', async () => { |
| 247 | + const configStore = mockDeep<ConfigStore>({ serverUrl: 'https://demo.opencloud.eu' }) |
| 248 | + const capabilityStore = mockDeep<CapabilityStore>({ |
| 249 | + capabilities: { |
| 250 | + core: { 'check-for-updates': true } |
| 251 | + }, |
| 252 | + status: { productversion: '3.5.0', edition: 'rolling' } |
| 253 | + }) |
| 254 | + const updatesStore = useUpdatesStore() |
| 255 | + const clientService = mockDeep<ClientService>() |
| 256 | + |
| 257 | + clientService.httpAuthenticated.get.mockResolvedValue(mockAxiosResolve({})) |
| 258 | + await announceUpdates({ clientService, updatesStore, configStore, capabilityStore }) |
| 259 | + expect(clientService.httpUnAuthenticated.get).toHaveBeenCalledWith( |
| 260 | + 'https://update.opencloud.eu/server.json', |
| 261 | + { |
| 262 | + params: { |
| 263 | + edition: 'rolling', |
| 264 | + server: 'feb937bb3019600cd682a7fc66d17a37540d9b3060ffa415373f2ad81f9f3b3a', |
| 265 | + version: '3.5.0' |
| 266 | + } |
| 267 | + } |
| 268 | + ) |
| 269 | + }) |
| 270 | +}) |
0 commit comments