zitadel/e2e/cypress/support/api/grants.ts

33 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

import { Context } from 'support/commands';
2024-08-22 07:48:36 +00:00
import { ensureItemDoesntExist, ensureItemExists } from './ensure';
import { getOrgUnderTest } from './orgs';
2024-08-22 07:48:36 +00:00
import { API, Entity } from './types';
export function ensureProjectGrantExists(ctx: Context, foreignOrgId: string, foreignProjectId: string) {
return getOrgUnderTest(ctx).then((orgUnderTest) => {
return ensureItemExists(
ctx.api,
`${ctx.api.mgmtBaseURL}/projectgrants/_search`,
(grant: any) => grant.grantedOrgId == orgUnderTest && grant.projectId == foreignProjectId,
`${ctx.api.mgmtBaseURL}/projects/${foreignProjectId}/grants`,
{ granted_org_id: orgUnderTest },
foreignOrgId,
'grantId',
'grantId',
);
});
}
2024-08-22 07:48:36 +00:00
export function ensureProjectGrantDoesntExist(ctx: Context, projectId: number, foreignOrgId: string) {
return getOrgUnderTest(ctx).then((orgUnderTest) => {
console.log('removing grant to foreignOrgId', foreignOrgId, 'in orgUnderTest', orgUnderTest, 'projectId', projectId);
return ensureItemDoesntExist(
ctx.api,
`${ctx.api.mgmtBaseURL}/projectgrants/_search`,
(grant: any) => grant.grantedOrgId == foreignOrgId && grant.projectId == projectId,
(grant: any) => `${ctx.api.mgmtBaseURL}/projects/${projectId}/grants/${grant.grantId}`,
orgUnderTest.toString(),
);
});
}