Skip to content

Commit c416131

Browse files
committed
test(e2e): restore request access cleanup
Signed-off-by: Vitor Mattos <[email protected]>
1 parent 718e938 commit c416131

2 files changed

Lines changed: 74 additions & 24 deletions

File tree

playwright/e2e/multi-signer-sequential.spec.ts

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ const FOOTER_DISABLED_VALUE = JSON.stringify({
1818
validationSite: '',
1919
customizeFooterTemplate: false,
2020
})
21-
const FOOTER_ENABLED_VALUE = JSON.stringify({
22-
enabled: true,
23-
writeQrcodeOnFooter: true,
24-
validationSite: '',
25-
customizeFooterTemplate: false,
26-
})
2721

2822
type OriginalConfigSnapshot = {
2923
identifyMethods: string | null
@@ -92,20 +86,6 @@ async function addEmailSigner(
9286
await page.getByRole('button', { name: 'Save' }).click()
9387
}
9488

95-
96-
async function restoreAppConfig(
97-
requestContext: APIRequestContext,
98-
key: string,
99-
value: string | null,
100-
): Promise<void> {
101-
if (value === null) {
102-
await deleteAppConfig(requestContext, 'libresign', key)
103-
return
104-
}
105-
106-
await setAppConfig(requestContext, 'libresign', key, value)
107-
}
108-
10989
test('request signatures from two signers in sequential order', async ({ page, adminContext }) => {
11090
await test.step('configure signing environment', async () => {
11191
await login(
@@ -151,10 +131,11 @@ test('request signatures from two signers in sequential order', async ({ page, a
151131
await addEmailSigner(page, '[email protected]', 'Signer 02')
152132

153133
// Enable sequential signing.
154-
// The checkbox input is hidden by CSS; click the visible label text to toggle it.
155-
await expect(page.getByLabel('Sign in order')).toBeVisible()
156-
await page.getByLabel('Sign in order').check()
157-
await expect(page.getByLabel('Sign in order')).toBeChecked()
134+
// The hidden checkbox can be covered by the styled label in CI, so force the state change.
135+
const signInOrderSwitch = page.getByLabel('Sign in order')
136+
await expect(signInOrderSwitch).toBeVisible()
137+
await signInOrderSwitch.check({ force: true })
138+
await expect(signInOrderSwitch).toBeChecked()
158139

159140
// Send the signature request
160141
await page.getByRole('button', { name: 'Request signatures' }).click()
@@ -229,3 +210,16 @@ test('request signatures from two signers in sequential order', async ({ page, a
229210
await expect(page.getByText('Signer 02')).toBeVisible()
230211
await expect(page.getByText('Not signed yet')).not.toBeVisible()
231212
})
213+
214+
async function restoreAppConfig(
215+
requestContext: APIRequestContext,
216+
key: string,
217+
value: string | null,
218+
): Promise<void> {
219+
if (value === null) {
220+
await deleteAppConfig(requestContext, 'libresign', key)
221+
return
222+
}
223+
224+
await setAppConfig(requestContext, 'libresign', key, value)
225+
}

playwright/e2e/policy-preferences-migrated-settings.spec.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
2531
const adminUser = 'admin'
2632
const 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+
137193
async function savePreferenceAsDisabled(page: Page, section: Locator, policyKey: string): Promise<void> {
138194
const disabledOption = section.getByText('Disabled', { exact: true }).first()
139195

0 commit comments

Comments
 (0)