Skip to content

Commit b6d3dcd

Browse files
committed
test(settings): align docmdp settings assertions
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent e1cfc4f commit b6d3dcd

1 file changed

Lines changed: 117 additions & 43 deletions

File tree

src/tests/views/Settings/DocMDP.spec.ts

Lines changed: 117 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
77
import { flushPromises, mount } from '@vue/test-utils'
8+
import { createPinia, setActivePinia } from 'pinia'
89

910
type DocMDPLevel = {
1011
value: number
@@ -15,6 +16,7 @@ type DocMDPLevel = {
1516
type DocMDPVm = {
1617
enabled: boolean
1718
selectedLevel?: DocMDPLevel
19+
canEdit?: boolean
1820
onEnabledChange: () => void
1921
}
2022

@@ -53,21 +55,30 @@ beforeAll(async () => {
5355

5456
describe('DocMDP', () => {
5557
beforeEach(() => {
58+
setActivePinia(createPinia())
5659
loadStateMock.mockReset()
5760
generateOcsUrlMock.mockClear()
5861
axiosPostMock.mockClear()
5962
})
6063

61-
it('uses typed backend config on load', async () => {
64+
it('loads effective docmdp policy from bootstrap state', async () => {
6265
loadStateMock.mockImplementation((_app: string, key: string, fallback: unknown) => {
63-
if (key === 'docmdp_config') {
66+
if (key === 'effective_policies') {
6467
return {
65-
enabled: false,
66-
defaultLevel: 2,
67-
availableLevels: [
68-
{ value: 1, label: 'L1', description: 'D1' },
69-
{ value: 2, label: 'L2', description: 'D2' },
70-
],
68+
policies: {
69+
docmdp: {
70+
policyKey: 'docmdp',
71+
effectiveValue: 2,
72+
allowedValues: [0, 1, 2, 3],
73+
sourceScope: 'system',
74+
visible: true,
75+
editableByCurrentActor: true,
76+
canSaveAsUserDefault: false,
77+
canUseAsRequestOverride: false,
78+
preferenceWasCleared: false,
79+
blockedBy: null,
80+
},
81+
},
7182
}
7283
}
7384
return fallback
@@ -87,21 +98,28 @@ describe('DocMDP', () => {
8798
const vm = wrapper.vm as unknown as DocMDPVm
8899
await flushPromises()
89100

90-
expect(vm.enabled).toBe(false)
101+
expect(vm.enabled).toBe(true)
91102
expect(vm.selectedLevel?.value).toBe(2)
92103
})
93104

94-
it('respects backend default config when storage is empty', async () => {
105+
it('disables controls when effective policy is not editable', async () => {
95106
loadStateMock.mockImplementation((_app: string, key: string, fallback: unknown) => {
96-
if (key === 'docmdp_config') {
107+
if (key === 'effective_policies') {
97108
return {
98-
enabled: true,
99-
defaultLevel: 2,
100-
availableLevels: [
101-
{ value: 0, label: 'L0', description: 'D0' },
102-
{ value: 1, label: 'L1', description: 'D1' },
103-
{ value: 2, label: 'L2', description: 'D2' },
104-
],
109+
policies: {
110+
docmdp: {
111+
policyKey: 'docmdp',
112+
effectiveValue: 1,
113+
allowedValues: [1],
114+
sourceScope: 'group',
115+
visible: true,
116+
editableByCurrentActor: false,
117+
canSaveAsUserDefault: false,
118+
canUseAsRequestOverride: false,
119+
preferenceWasCleared: false,
120+
blockedBy: 'group',
121+
},
122+
},
105123
}
106124
}
107125
return fallback
@@ -122,24 +140,52 @@ describe('DocMDP', () => {
122140
await flushPromises()
123141

124142
expect(vm.enabled).toBe(true)
125-
expect(vm.selectedLevel?.value).toBe(2)
143+
expect(vm.selectedLevel?.value).toBe(1)
144+
expect(vm.canEdit).toBe(false)
126145
})
127146

128-
it('changes selected level and persists selected radio value', async () => {
147+
it('changes selected level and persists to system policy endpoint', async () => {
129148
loadStateMock.mockImplementation((_app: string, key: string, fallback: unknown) => {
130-
if (key === 'docmdp_config') {
149+
if (key === 'effective_policies') {
131150
return {
132-
enabled: true,
133-
defaultLevel: 1,
134-
availableLevels: [
135-
{ value: 1, label: 'L1', description: 'D1' },
136-
{ value: 2, label: 'L2', description: 'D2' },
137-
{ value: 3, label: 'L3', description: 'D3' },
138-
],
151+
policies: {
152+
docmdp: {
153+
policyKey: 'docmdp',
154+
effectiveValue: 1,
155+
allowedValues: [0, 1, 2, 3],
156+
sourceScope: 'system',
157+
visible: true,
158+
editableByCurrentActor: true,
159+
canSaveAsUserDefault: false,
160+
canUseAsRequestOverride: false,
161+
preferenceWasCleared: false,
162+
blockedBy: null,
163+
},
164+
},
139165
}
140166
}
141167
return fallback
142168
})
169+
axiosPostMock.mockResolvedValue({
170+
data: {
171+
ocs: {
172+
data: {
173+
policy: {
174+
policyKey: 'docmdp',
175+
effectiveValue: 3,
176+
allowedValues: [0, 1, 2, 3],
177+
sourceScope: 'system',
178+
visible: true,
179+
editableByCurrentActor: true,
180+
canSaveAsUserDefault: false,
181+
canUseAsRequestOverride: false,
182+
preferenceWasCleared: false,
183+
blockedBy: null,
184+
},
185+
},
186+
},
187+
},
188+
})
143189

144190
const wrapper = mount(DocMDP as never, {
145191
global: {
@@ -161,25 +207,53 @@ describe('DocMDP', () => {
161207

162208
expect(vm.selectedLevel?.value).toBe(3)
163209
expect(axiosPostMock).toHaveBeenCalled()
164-
const lastCall = axiosPostMock.mock.calls[axiosPostMock.mock.calls.length - 1] as [string, { enabled: boolean, defaultLevel: number }]
165-
expect(lastCall[1].defaultLevel).toBe(3)
210+
const lastCall = axiosPostMock.mock.calls[axiosPostMock.mock.calls.length - 1] as [string, { value: number }]
211+
expect(lastCall[0]).toBe('/apps/libresign/api/v1/policies/system/docmdp')
212+
expect(lastCall[1].value).toBe(3)
166213
})
167214

168-
it('uses preferred level 2 when enabling without explicit selected level', async () => {
215+
it('saves value 0 when disabling docmdp', async () => {
169216
loadStateMock.mockImplementation((_app: string, key: string, fallback: unknown) => {
170-
if (key === 'docmdp_config') {
217+
if (key === 'effective_policies') {
171218
return {
172-
enabled: false,
173-
defaultLevel: 2,
174-
availableLevels: [
175-
{ value: 0, label: 'L0', description: 'D0' },
176-
{ value: 1, label: 'L1', description: 'D1' },
177-
{ value: 2, label: 'L2', description: 'D2' },
178-
],
219+
policies: {
220+
docmdp: {
221+
policyKey: 'docmdp',
222+
effectiveValue: 2,
223+
allowedValues: [0, 1, 2, 3],
224+
sourceScope: 'system',
225+
visible: true,
226+
editableByCurrentActor: true,
227+
canSaveAsUserDefault: false,
228+
canUseAsRequestOverride: false,
229+
preferenceWasCleared: false,
230+
blockedBy: null,
231+
},
232+
},
179233
}
180234
}
181235
return fallback
182236
})
237+
axiosPostMock.mockResolvedValue({
238+
data: {
239+
ocs: {
240+
data: {
241+
policy: {
242+
policyKey: 'docmdp',
243+
effectiveValue: 0,
244+
allowedValues: [0, 1, 2, 3],
245+
sourceScope: 'system',
246+
visible: true,
247+
editableByCurrentActor: true,
248+
canSaveAsUserDefault: false,
249+
canUseAsRequestOverride: false,
250+
preferenceWasCleared: false,
251+
blockedBy: null,
252+
},
253+
},
254+
},
255+
},
256+
})
183257

184258
const wrapper = mount(DocMDP as never, {
185259
global: {
@@ -195,12 +269,12 @@ describe('DocMDP', () => {
195269
const vm = wrapper.vm as unknown as DocMDPVm
196270
await flushPromises()
197271

198-
expect(vm.selectedLevel?.value).toBe(2)
199-
vm.enabled = true
272+
vm.enabled = false
200273
vm.onEnabledChange()
201274
await flushPromises()
202275

203-
const lastCall = axiosPostMock.mock.calls[axiosPostMock.mock.calls.length - 1] as [string, { enabled: boolean, defaultLevel: number }]
204-
expect(lastCall[1]).toMatchObject({ enabled: true, defaultLevel: 2 })
276+
const lastCall = axiosPostMock.mock.calls[axiosPostMock.mock.calls.length - 1] as [string, { value: number }]
277+
expect(lastCall[0]).toBe('/apps/libresign/api/v1/policies/system/docmdp')
278+
expect(lastCall[1].value).toBe(0)
205279
})
206280
})

0 commit comments

Comments
 (0)