@@ -22,6 +22,12 @@ import {
2222 setSystemPolicyEntry ,
2323} from '../support/policy-api'
2424
25+ type SystemPolicySnapshot = {
26+ exists : boolean
27+ value : unknown
28+ allowChildOverride : boolean
29+ }
30+
2531const adminUser = 'admin'
2632const adminPass = process . env . ADMIN_PASSWORD || 'admin'
2733
@@ -33,6 +39,11 @@ test.describe('Policy preferences: migrated settings', () => {
3339
3440 const adminCtx = await createAuthenticatedRequestContext ( adminUser , adminPass )
3541 let endUserCtx : APIRequestContext | null = null
42+ const originalGroupsRequestSign = await getSystemPolicySnapshot ( adminCtx , 'groups_request_sign' )
43+ const originalCollectMetadata = await getSystemPolicySnapshot ( adminCtx , 'collect_metadata' )
44+ const originalIdentificationDocuments = await getSystemPolicySnapshot ( adminCtx , 'identification_documents' )
45+ const originalDocmdp = await getSystemPolicySnapshot ( adminCtx , 'docmdp' )
46+ const originalSignatureText = await getSystemPolicySnapshot ( adminCtx , 'signature_text' )
3647 const signatureTextSystemValue = JSON . stringify ( {
3748 template : 'System template' ,
3849 template_font_size : 9 ,
@@ -119,6 +130,12 @@ test.describe('Policy preferences: migrated settings', () => {
119130 await endUserCtx . dispose ( )
120131 }
121132
133+ await restoreSystemPolicySnapshot ( adminCtx , 'groups_request_sign' , originalGroupsRequestSign )
134+ await restoreSystemPolicySnapshot ( adminCtx , 'collect_metadata' , originalCollectMetadata )
135+ await restoreSystemPolicySnapshot ( adminCtx , 'identification_documents' , originalIdentificationDocuments )
136+ await restoreSystemPolicySnapshot ( adminCtx , 'docmdp' , originalDocmdp )
137+ await restoreSystemPolicySnapshot ( adminCtx , 'signature_text' , originalSignatureText )
138+
122139 await policyRequest ( adminCtx , 'DELETE' , `/cloud/users/${ endUser } ` )
123140 await policyRequest ( adminCtx , 'DELETE' , `/cloud/groups/${ groupId } ` )
124141 await adminCtx . dispose ( )
@@ -134,6 +151,45 @@ async function sectionByTitle(page: Page, title: string): Promise<Locator> {
134151 return section
135152}
136153
154+ async function getSystemPolicySnapshot (
155+ ctx : APIRequestContext ,
156+ policyKey : string ,
157+ ) : Promise < SystemPolicySnapshot > {
158+ const response = await policyRequest ( ctx , 'GET' , `/apps/libresign/api/v1/policies/system/${ policyKey } ` )
159+ if ( response . httpStatus === 404 ) {
160+ return {
161+ exists : false ,
162+ value : null ,
163+ allowChildOverride : true ,
164+ }
165+ }
166+
167+ expect ( response . httpStatus , `getSystemPolicySnapshot(${ policyKey } ): expected 200 or 404 but got ${ response . httpStatus } ` ) . toBe ( 200 )
168+
169+ return {
170+ exists : true ,
171+ value : response . data . value ?? null ,
172+ allowChildOverride : response . data . allowChildOverride === true ,
173+ }
174+ }
175+
176+ async function restoreSystemPolicySnapshot (
177+ ctx : APIRequestContext ,
178+ policyKey : string ,
179+ snapshot : SystemPolicySnapshot ,
180+ ) : Promise < void > {
181+ if ( ! snapshot . exists ) {
182+ await setSystemPolicyEntry ( ctx , policyKey , null , true )
183+ return
184+ }
185+
186+ const response = await policyRequest ( ctx , 'POST' , `/apps/libresign/api/v1/policies/system/${ policyKey } ` , {
187+ value : snapshot . value ,
188+ allowChildOverride : snapshot . allowChildOverride ,
189+ } )
190+ expect ( response . httpStatus , `restoreSystemPolicySnapshot(${ policyKey } ): expected 200 but got ${ response . httpStatus } ` ) . toBe ( 200 )
191+ }
192+
137193async function savePreferenceAsDisabled ( page : Page , section : Locator , policyKey : string ) : Promise < void > {
138194 const disabledOption = section . getByText ( 'Disabled' , { exact : true } ) . first ( )
139195
0 commit comments