66import { beforeAll , beforeEach , describe , expect , it , vi } from 'vitest'
77import { flushPromises , mount } from '@vue/test-utils'
88
9- const loadStateMock = vi . fn ( )
109const axiosGetMock = vi . fn ( )
10+ const fetchEffectivePoliciesMock = vi . fn ( async ( ) => { } )
11+ const getEffectiveValueMock = vi . fn ( ( policyKey : string ) => {
12+ if ( policyKey === 'identification_documents' ) {
13+ return true
14+ }
1115
12- vi . mock ( '@nextcloud/initial-state' , ( ) => ( {
13- loadState : ( ...args : unknown [ ] ) => loadStateMock ( ...args ) ,
14- } ) )
16+ if ( policyKey === 'approval_group' ) {
17+ return [ ]
18+ }
19+
20+ return null
21+ } )
22+ const saveSystemPolicyMock = vi . fn ( async ( _policyKey : string , value : string ) => ( { effectiveValue : value } ) )
1523
1624vi . mock ( '@nextcloud/axios' , ( ) => ( {
1725 default : {
@@ -21,13 +29,13 @@ vi.mock('@nextcloud/axios', () => ({
2129
2230vi . mock ( '@nextcloud/l10n' , ( ) => globalThis . mockNextcloudL10n ( ) )
2331
24- const OCP = {
25- AppConfig : {
26- setValue : vi . fn ( ) ,
27- } ,
28- }
29-
30- ; ( globalThis as typeof globalThis & { OCP : typeof OCP } ) . OCP = OCP
32+ vi . mock ( '../../../store/policies' , ( ) => ( {
33+ usePoliciesStore : ( ) => ( {
34+ fetchEffectivePolicies : fetchEffectivePoliciesMock ,
35+ getEffectiveValue : getEffectiveValueMock ,
36+ saveSystemPolicy : saveSystemPolicyMock ,
37+ } ) ,
38+ } ) )
3139
3240let IdentificationDocuments : unknown
3341
@@ -37,28 +45,13 @@ beforeAll(async () => {
3745
3846describe ( 'IdentificationDocuments' , ( ) => {
3947 beforeEach ( ( ) => {
40- loadStateMock . mockReset ( )
4148 axiosGetMock . mockReset ( )
42- OCP . AppConfig . setValue . mockClear ( )
49+ fetchEffectivePoliciesMock . mockClear ( )
50+ getEffectiveValueMock . mockClear ( )
51+ saveSystemPolicyMock . mockClear ( )
4352 } )
4453
4554 it ( 'saves groups on update:modelValue' , async ( ) => {
46- loadStateMock . mockImplementation ( ( _app : string , key : string , fallback : unknown ) => {
47- if ( key === 'approval_group' ) {
48- return [ ]
49- }
50- if ( key === 'effective_policies' ) {
51- return {
52- policies : {
53- identification_documents : {
54- effectiveValue : true ,
55- } ,
56- } ,
57- }
58- }
59- return fallback
60- } )
61-
6255 axiosGetMock . mockImplementation ( ( url : string ) => {
6356 if ( url . includes ( 'cloud/groups/details' ) ) {
6457 return Promise . resolve ( {
@@ -95,6 +88,6 @@ describe('IdentificationDocuments', () => {
9588 ncSelect . vm . $emit ( 'update:modelValue' , [ { id : 'grpA' , displayname : 'Group A' } ] )
9689 await flushPromises ( )
9790
98- expect ( OCP . AppConfig . setValue ) . toHaveBeenCalledWith ( 'libresign' , ' approval_group', '["grpA"]' )
91+ expect ( saveSystemPolicyMock ) . toHaveBeenCalledWith ( 'approval_group' , '["grpA"]' , false )
9992 } )
10093} )
0 commit comments