Elio Bischof 51febd7e4e
test(e2e): test authorizations (#4342)
* add specs that cover the b2b demo

* update cypress

* test handling manager roles

* use shared mocha contexts

* use beforeEach instead of before

* improve readability

* improve application test

* remove static waits

* remove old awaitDesired

* test owned project authorizations

* simplify ensure.ts

* test granted projects authz

* disable prevSubject for shouldNotExist

* await non-existence, then expect no error

* update dependencies

* fix tests from scratch

* fix settings tests from scratch

* Apply suggestions from code review

Co-authored-by: Max Peintner <max@caos.ch>

* Implement code review suggestions

* use spread operator

* settings properties must match

* add check settings object

* revert spread operator

Co-authored-by: Max Peintner <max@caos.ch>
2022-10-11 15:29:23 +02:00

77 lines
2.3 KiB
TypeScript

import { ensureItemDoesntExist, ensureItemExists } from './ensure';
import { findFromList, searchSomething } from './search';
import { API } from './types';
export function ensureHumanIsNotOrgMember(api: API, username: string): Cypress.Chainable<number> {
return ensureItemDoesntExist(
api,
`${api.mgmtBaseURL}/orgs/me/members/_search`,
(member: any) => (<string>member.preferredLoginName).startsWith(username),
(member) => `${api.mgmtBaseURL}/orgs/me/members/${member.userId}`,
);
}
export function ensureHumanIsOrgMember(api: API, username: string, roles: string[]): Cypress.Chainable<number> {
return searchSomething(
api,
`${api.mgmtBaseURL}/users/_search`,
'POST',
findFromList((user) => {
return user.userName == username;
}),
).then((user) => {
return ensureItemExists(
api,
`${api.mgmtBaseURL}/orgs/me/members/_search`,
(member: any) => member.userId == user.entity.id,
`${api.mgmtBaseURL}/orgs/me/members`,
{
userId: user.entity.id,
roles: roles,
},
);
});
}
export function ensureHumanIsNotProjectMember(
api: API,
projectId: string,
username: string,
grantId?: number,
): Cypress.Chainable<number> {
return ensureItemDoesntExist(
api,
`${api.mgmtBaseURL}/projects/${projectId}/${grantId ? `grants/${grantId}/` : ''}members/_search`,
(member: any) => (<string>member.preferredLoginName).startsWith(username),
(member) => `${api.mgmtBaseURL}/projects/${projectId}${grantId ? `grants/${grantId}/` : ''}/members/${member.userId}`,
);
}
export function ensureHumanIsProjectMember(
api: API,
projectId: string,
username: string,
roles: string[],
grantId?: number,
): Cypress.Chainable<number> {
return searchSomething(
api,
`${api.mgmtBaseURL}/users/_search`,
'POST',
findFromList((user) => {
return user.userName == username;
}),
).then((user) => {
return ensureItemExists(
api,
`${api.mgmtBaseURL}/projects/${projectId}/${grantId ? `grants/${grantId}/` : ''}members/_search`,
(member: any) => member.userId == user.entity.id,
`${api.mgmtBaseURL}/projects/${projectId}/${grantId ? `grants/${grantId}/` : ''}members`,
{
userId: user.entity.id,
roles: roles,
},
);
});
}