Skip to content

Commit 697ce8f

Browse files
committed
test(policy-workbench): verify persisted group rule hydration
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 0e44983 commit 697ce8f

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

src/tests/views/Settings/PolicyWorkbench/useRealPolicyWorkbench.spec.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ vi.mock('@nextcloud/router', () => ({
2424

2525
const saveSystemPolicy = vi.fn()
2626
const saveGroupPolicy = vi.fn()
27+
const fetchGroupPolicy = vi.fn()
2728
const saveUserPolicyForUser = vi.fn()
2829
const clearGroupPolicy = vi.fn()
2930
const clearUserPolicyForUser = vi.fn()
@@ -33,6 +34,7 @@ vi.mock('../../../../store/policies', () => ({
3334
usePoliciesStore: () => ({
3435
saveSystemPolicy,
3536
saveGroupPolicy,
37+
fetchGroupPolicy,
3638
saveUserPolicyForUser,
3739
clearGroupPolicy,
3840
clearUserPolicyForUser,
@@ -47,11 +49,13 @@ describe('useRealPolicyWorkbench', () => {
4749
axiosGet.mockReset()
4850
saveSystemPolicy.mockReset()
4951
saveGroupPolicy.mockReset()
52+
fetchGroupPolicy.mockReset()
5053
saveUserPolicyForUser.mockReset()
5154
clearGroupPolicy.mockReset()
5255
clearUserPolicyForUser.mockReset()
5356
getPolicy.mockReset()
5457
getPolicy.mockReturnValue({ effectiveValue: 'parallel' })
58+
fetchGroupPolicy.mockResolvedValue(null)
5559
axiosGet.mockImplementation((url: string) => {
5660
if (url === 'cloud/groups/details') {
5761
return Promise.resolve({
@@ -87,6 +91,40 @@ describe('useRealPolicyWorkbench', () => {
8791
})
8892
})
8993

94+
it('hydrates persisted group rules when opening a setting', async () => {
95+
fetchGroupPolicy.mockImplementation(async (groupId: string) => {
96+
if (groupId !== 'finance') {
97+
return null
98+
}
99+
100+
return {
101+
policyKey: 'signature_flow',
102+
scope: 'group',
103+
targetId: 'finance',
104+
value: 'ordered_numeric',
105+
allowChildOverride: false,
106+
visibleToChild: true,
107+
allowedValues: ['ordered_numeric'],
108+
}
109+
})
110+
111+
const state = createRealPolicyWorkbenchState()
112+
state.openSetting('signature_flow')
113+
114+
await vi.waitFor(() => {
115+
expect(fetchGroupPolicy).toHaveBeenCalledWith('finance', 'signature_flow')
116+
expect(state.visibleGroupRules).toHaveLength(1)
117+
})
118+
119+
expect(fetchGroupPolicy).toHaveBeenCalledWith('finance', 'signature_flow')
120+
expect(state.visibleGroupRules).toHaveLength(1)
121+
expect(state.visibleGroupRules[0]).toMatchObject({
122+
targetId: 'finance',
123+
value: 'ordered_numeric',
124+
allowChildOverride: false,
125+
})
126+
})
127+
90128
it('loads real group targets from OCS when opening the group editor', async () => {
91129
const state = createRealPolicyWorkbenchState()
92130
state.openSetting('signature_flow')

0 commit comments

Comments
 (0)