From d57e5f182cd983f4f1007993fa4a13c705072449 Mon Sep 17 00:00:00 2001 From: Alex Crome Date: Mon, 5 Sep 2022 23:20:18 +0100 Subject: [PATCH] Add initial test around cache Signed-off-by: Alex Crome --- ...eInstanceGithubCredentialsProvider.test.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packages/integration/src/github/SingleInstanceGithubCredentialsProvider.test.ts b/packages/integration/src/github/SingleInstanceGithubCredentialsProvider.test.ts index 1dcc45c1ef..3d58ffbb61 100644 --- a/packages/integration/src/github/SingleInstanceGithubCredentialsProvider.test.ts +++ b/packages/integration/src/github/SingleInstanceGithubCredentialsProvider.test.ts @@ -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'); + } + }); });