Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion ui/e2e/live/helpers/setup-nav-39060.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,35 @@ export const SETUP = '/apps/setup';
export const AUDITOR_PERMISSION_SET = 'e2e_setup_auditor_39060';
const AUDITOR_CAPABILITIES = ['setup.access', 'view_all_audit_log'];

/**
* The package the auditor's permission set is saved into. A new metadata item
* names a writable package (objectstack ADR-0070 D1) and the showcase is
* provided by code, so this file authors a package of its own, the way the
* Studio live specs do. One fixed id, so every test (and every project run in
* parallel) authors or finds the same package and the same set.
*/
const AUDITOR_PACKAGE = 'com.e2e.setupauditor39060';

/** Author the auditor's package, or find it when an earlier test already did. */
async function authorAuditorPackage(admin: APIRequestContext): Promise<string> {
const exists = async () => (await admin.get(`${API}/api/v1/packages/${AUDITOR_PACKAGE}`)).ok();
if (await exists()) return AUDITOR_PACKAGE;
const res = await admin.post(`${API}/api/v1/packages`, {
data: { manifest: { id: AUDITOR_PACKAGE, name: 'E2E Setup Auditor', version: '0.1.0', type: 'app' } },
});
// A parallel test may have authored it between the read and the install,
// which answers 409; the package then exists, and that is all this needs.
expect(res.ok() || (await exists()), `authoring ${AUDITOR_PACKAGE}: ${await res.text()}`).toBe(true);
return AUDITOR_PACKAGE;
}

/**
* Author (or find) the auditor's permission set and sign a member holding it
* in. `admin` is the spec's `request` fixture (the global setup's admin).
*/
export async function signInAuditor(admin: APIRequestContext): Promise<LiveMember> {
const saved = await admin.put(`${API}/api/v1/meta/permission/${AUDITOR_PERMISSION_SET}`, {
const pkgId = await authorAuditorPackage(admin);
const saved = await admin.put(`${API}/api/v1/meta/permission/${AUDITOR_PERMISSION_SET}?package=${pkgId}`, {
data: {
name: AUDITOR_PERMISSION_SET,
label: 'E2E Setup Auditor',
Expand Down
Loading