test-utils: make optional actor object
Signed-off-by: Vincenzo Scamporlino <vincenzos@spotify.com>
This commit is contained in:
@@ -108,7 +108,7 @@ export namespace mockCredentials {
|
||||
*/
|
||||
export function user(
|
||||
userEntityRef: string = DEFAULT_MOCK_USER_ENTITY_REF,
|
||||
options?: { actor?: string },
|
||||
options?: { actor?: { subject: string } },
|
||||
): BackstageCredentials<BackstageUserPrincipal> {
|
||||
validateUserEntityRef(userEntityRef);
|
||||
return {
|
||||
@@ -134,14 +134,14 @@ export namespace mockCredentials {
|
||||
*/
|
||||
export function token(
|
||||
userEntityRef?: string,
|
||||
options?: { actor?: string },
|
||||
options?: { actor?: { subject: string } },
|
||||
): string {
|
||||
if (userEntityRef) {
|
||||
validateUserEntityRef(userEntityRef);
|
||||
return `${MOCK_USER_TOKEN_PREFIX}${JSON.stringify({
|
||||
sub: userEntityRef,
|
||||
...(options?.actor && {
|
||||
actor: options.actor,
|
||||
actor: { subject: options.actor.subject },
|
||||
}),
|
||||
} satisfies UserTokenPayload)}`;
|
||||
}
|
||||
|
||||
@@ -596,7 +596,7 @@ describe('createRouter', () => {
|
||||
expect(mockApplyConditions).toHaveBeenCalledWith(
|
||||
'plugin-1',
|
||||
mockCredentials.user('user:default/spiderman', {
|
||||
actor: 'some-service',
|
||||
actor: { subject: 'some-service' },
|
||||
}),
|
||||
[
|
||||
expect.objectContaining({
|
||||
@@ -611,7 +611,7 @@ describe('createRouter', () => {
|
||||
expect(mockApplyConditions).toHaveBeenCalledWith(
|
||||
'plugin-2',
|
||||
mockCredentials.user('user:default/spiderman', {
|
||||
actor: 'some-service',
|
||||
actor: { subject: 'some-service' },
|
||||
}),
|
||||
[
|
||||
expect.objectContaining({
|
||||
@@ -729,7 +729,7 @@ describe('createRouter', () => {
|
||||
|
||||
function userTokenIssuedByService() {
|
||||
return mockCredentials.user.token('user:default/spiderman', {
|
||||
actor: 'some-service',
|
||||
actor: { subject: 'some-service' },
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user