Skip to content

Commit 5be68ab

Browse files
committed
Fix tests
1 parent bdf629e commit 5be68ab

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

src/lib/github/v4/get-invalid-access-token-message.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ export function getInvalidAccessTokenMessage({
4040

4141
if (repoNotFound) {
4242
const hasRequiredScopes = isEmpty(
43-
difference(requiredScopes.split(','), grantedScopes.split(',')),
43+
difference(
44+
requiredScopes.split(',').map((s) => s.trim()),
45+
grantedScopes.split(',').map((s) => s.trim()),
46+
),
4447
);
4548

4649
// user does not have permission to the repo

src/lib/github/v4/get-invalid-access-token-message.unit.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,29 @@ describe('getInvalidAccessTokenMessage', () => {
100100
`);
101101
});
102102

103+
it('should ignore whitespace when comparing scopes', () => {
104+
const result = {
105+
statusCode: 200,
106+
responseHeaders: new Headers({
107+
'x-oauth-scopes': 'gist, read:org, repo, workflow',
108+
'x-accepted-oauth-scopes': 'repo',
109+
}),
110+
error: {
111+
graphQLErrors: [
112+
{ originalError: { type: 'NOT_FOUND' }, path: ['repository'] },
113+
],
114+
},
115+
} as unknown as OperationResultWithMeta;
116+
117+
return expect(
118+
getInvalidAccessTokenMessage({
119+
result,
120+
repoOwner: 'elastic',
121+
repoName: 'kibana',
122+
}),
123+
).toBe(`The repository "elastic/kibana" doesn't exist`);
124+
});
125+
103126
it('should not handle unknown cases', () => {
104127
const result = {
105128
statusCode: 500,

src/test/cli/error-handling-non-interactive-mode.private.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe('non interactive (json) error handling', () => {
9292
const error = backportResult.results[0] as ErrorResult;
9393
expect(error.status).toBe('error');
9494
expect(error.errorMessage).toEqual(
95-
'The repository "backport-org/backport-e2e-foo" doesn\'t exist',
95+
`The repository "backport-org/backport-e2e-foo" doesn't exist`,
9696
);
9797
});
9898

0 commit comments

Comments
 (0)