Add initial test around cache

Signed-off-by: Alex Crome <afscrome@users.noreply.github.com>
This commit is contained in:
Alex Crome
2022-09-05 23:20:18 +01:00
parent d0e8705afd
commit d57e5f182c
@@ -400,4 +400,36 @@ describe('SingleInstanceGithubCredentialsProvider tests', () => {
}),
).resolves.not.toThrow();
});
it('should cache access token', async () => {
octokit.apps.listInstallations.mockResolvedValueOnce({
headers: {
etag: '123',
},
data: [
{
id: 1,
repository_selection: 'all',
account: {
login: 'backstage',
},
},
],
} as RestEndpointMethodTypes['apps']['listInstallations']['response']);
octokit.apps.createInstallationAccessToken.mockResolvedValueOnce({
data: {
expires_at: DateTime.local().plus({ hours: 1 }).toString(),
token: 'secret_token',
},
} as RestEndpointMethodTypes['apps']['createInstallationAccessToken']['response']);
for (let i = 0; i < 2; i++) {
const { token, headers } = await github.getCredentials({
url: 'https://github.com/backstage',
});
expect(headers).toEqual({ Authorization: 'Bearer secret_token' });
expect(token).toEqual('secret_token');
}
});
});