Skip to content

Commit

Permalink
fixup! Do not throw other then unauthorised error on token refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
vinokurig committed Nov 15, 2023
1 parent a128840 commit 901d8b4
Showing 1 changed file with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,7 @@ describe('OAuth service', () => {
try {
await OAuthService.refreshTokenIfNeeded(devWorkspace);
} catch (e: any) {
expect(e.response.data.responseData.attributes.oauth_authentication_url).toBe(
'https://git-lub/oauth/url',
);
fail('it should not reach here');
}

expect(refreshFactoryOauthTokenSpy).toHaveBeenCalledWith('origin:project');
Expand Down Expand Up @@ -225,10 +223,53 @@ describe('OAuth service', () => {
try {
await OAuthService.refreshTokenIfNeeded(devWorkspace);
} catch (e: any) {
expect(e.response.status).toBe(401);
fail('it should not reach here');
}

expect(refreshFactoryOauthTokenSpy).toHaveBeenCalledWith('origin:project');
expect(mockOpenOAuthPage).not.toHaveBeenCalled();
});

it('should redirect to oauth window if error has OAuth response', async () => {
const status = { mainUrl: 'https://mainUrl' };
const projects = [
{
name: 'project',
git: {
remotes: {
origin: 'origin:project',
},
},
},
];
const devWorkspace = new DevWorkspaceBuilder()
.withStatus(status)
.withProjects(projects)
.build();

refreshFactoryOauthTokenSpy.mockRejectedValueOnce({
isAxiosError: false,
code: '401',
response: {
status: 401,
data: {
attributes: {
oauth_provider: 'git-lab',
oauth_authentication_url: 'https://git-lub/oauth/url',
},
},
},
} as AxiosError);

jest.spyOn(common.helpers.errors, 'includesAxiosResponse').mockImplementation(() => true);

try {
await OAuthService.refreshTokenIfNeeded(devWorkspace);
} catch (e: any) {
expect(e.response.status).toBe(401);
}

expect(refreshFactoryOauthTokenSpy).toHaveBeenCalledWith('origin:project');
expect(mockOpenOAuthPage).toHaveBeenCalled();
});
});

0 comments on commit 901d8b4

Please sign in to comment.