Files
ocis/web/packages/web-pkg/tests/unit/services/client-maintenance-mode.spec.ts
Matteo f7453530f6 chore(web): [OCISDEV-1501] remove vault MFA session extension popup (#13085)
Remove the "Session expiring" extend/dismiss popup and its expiry
worker. Drop the frontend session_duration capability and config;
OCIS_MFA_SESSION_DURATION stays in use by the proxy.
2026-10-08 18:54:57 +02:00

102 lines
3.3 KiB
TypeScript

import { ClientService, useAuthStore, useConfigStore } from '../../../src/'
import { Language } from 'vue3-gettext'
import { createTestingPinia, writable } from '../../../src/testing'
import type { OnResponseArgs } from '@ownclouders/web-client'
/**
* `shouldResponseTriggerMaintenance` is deliberately left unmocked: the decision it encodes
* — which statuses and which endpoints count — is the thing under test here, and stubbing it
* would only assert that one function calls another.
*/
vi.mock('@ownclouders/web-client', async (importOriginal) => ({
...(await importOriginal<any>()),
graph: vi.fn(),
ocs: vi.fn(),
webdav: vi.fn()
}))
describe('ClientService maintenance mode', () => {
const language = { current: 'en' }
const serverUrl = 'someUrl'
let configStore: ReturnType<typeof useConfigStore>
let authStore: ReturnType<typeof useAuthStore>
let service: ClientService
let onResponse: (args: OnResponseArgs) => void
beforeEach(() => {
createTestingPinia({ initialState: { auth: { accessToken: 'token' } } })
vi.stubGlobal('fetch', vi.fn())
authStore = useAuthStore()
configStore = useConfigStore()
writable(configStore).serverUrl = serverUrl
configStore.setMaintenanceMode = vi.fn()
service = new ClientService({
configStore,
language: language as Language,
authStore
})
onResponse = service.handleResponse.bind(service)
})
it('clears maintenance mode for a successful response', () => {
onResponse({
response: new Response('{}', { status: 200 }),
status: 200,
requestUrl: 'some/url'
})
expect(configStore.setMaintenanceMode).toHaveBeenCalledWith(false)
})
it('sets maintenance mode for a 503', () => {
onResponse({
response: new Response('{}', { status: 503 }),
status: 503,
requestUrl: 'some/url'
})
expect(configStore.setMaintenanceMode).toHaveBeenCalledWith(true)
})
it('clears maintenance mode for a 404, since the server did answer', () => {
onResponse({
response: new Response('{}', { status: 404 }),
status: 404,
requestUrl: 'some/url'
})
expect(configStore.setMaintenanceMode).toHaveBeenCalledWith(false)
})
/**
* A transport failure has no response to read a status off, so it is reported as 500. As on
* master — where the axios error interceptor fell back to `error.response?.status || 500` —
* that is not a maintenance signal, so the flag is left alone rather than cleared.
*/
it('leaves maintenance state untouched for a transport failure', () => {
onResponse({ response: null, status: 500, requestUrl: 'some/url' })
expect(configStore.setMaintenanceMode).not.toHaveBeenCalled()
})
/**
* The allow-list is matched against the relative request url, which is why `onResponse`
* reports the caller's url rather than `response.url`. The notifications SSE endpoint
* answers 503 by design and must not raise the banner, so it is treated like any other
* non-maintenance response and clears the flag.
*/
it('exempts an allow-listed endpoint from a 503', () => {
onResponse({
response: new Response('{}', { status: 503 }),
status: 503,
requestUrl: 'ocs/v2.php/apps/notifications/api/v1/notifications/sse'
})
expect(configStore.setMaintenanceMode).toHaveBeenCalledWith(false)
})
})