diff --git a/src/gitlab/clone/gitlab_credentials_provider.test.ts b/src/gitlab/clone/gitlab_credentials_provider.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..b406a9640c519b5a2ca35b8d11a223b687cfce68 --- /dev/null +++ b/src/gitlab/clone/gitlab_credentials_provider.test.ts @@ -0,0 +1,25 @@ +import * as vscode from 'vscode'; +import { tokenService } from '../../services/token_service'; +import { GITLAB_URL } from '../../../test/integration/test_infrastructure/constants'; +import { gitlabCredentialsProvider } from './gitlab_credentials_provider'; + +jest.mock('../../services/token_service'); + +describe('GitLab Credentials Provider', () => { + beforeEach(() => { + tokenService.getInstanceUrls = () => [GITLAB_URL]; + tokenService.getToken = (url: string) => (url === GITLAB_URL ? 'password' : undefined); + }); + + it('getting credentials works', async () => { + expect( + (await gitlabCredentialsProvider.getCredentials(vscode.Uri.parse(GITLAB_URL)))?.password, + ).toBe('password'); + }); + + it('returns undefined for url without token', async () => { + expect( + await gitlabCredentialsProvider.getCredentials(vscode.Uri.parse('https://invalid.com')), + ).toBe(undefined); + }); +}); diff --git a/test/integration/gitlab_credentials_provider.test.ts b/test/integration/gitlab_credentials_provider.test.ts deleted file mode 100644 index c661c3f9f92d417548d7d455e1a697ccca285f30..0000000000000000000000000000000000000000 --- a/test/integration/gitlab_credentials_provider.test.ts +++ /dev/null @@ -1,47 +0,0 @@ -import * as assert from 'assert'; -import * as vscode from 'vscode'; -import { tokenService } from '../../src/services/token_service'; -import { GITLAB_URL } from './test_infrastructure/constants'; -import { gitlabCredentialsProvider } from '../../src/gitlab/clone/gitlab_credentials_provider'; - -const token = 'abcd-secret'; - -describe('GitLab Credentials Provider', () => { - before(async () => { - await tokenService.setToken(GITLAB_URL, token); - }); - - after(async () => { - await tokenService.setToken(GITLAB_URL, undefined); - }); - - it('getting credentials works', async () => { - assert.deepStrictEqual( - (await gitlabCredentialsProvider.getCredentials(vscode.Uri.parse(GITLAB_URL)))?.password, - token, - 'Username and token should be equal', - ); - }); - - it('returns undefined for url without token', async () => { - assert.deepStrictEqual( - await gitlabCredentialsProvider.getCredentials(vscode.Uri.parse('https://invalid.com')), - undefined, - 'there should be no user at invalid url', - ); - }); - - it('newly created token is used', async () => { - const temporaryToken = 'token'; - await tokenService.setToken('https://test2.gitlab.com', temporaryToken); - - assert.deepStrictEqual( - (await gitlabCredentialsProvider.getCredentials(vscode.Uri.parse('https://test2.gitlab.com'))) - ?.password, - temporaryToken, - 'Username and token should be equal', - ); - - await tokenService.setToken('https://test2.gitlab.com', undefined); - }); -});