提交 4ef2ef93 编写于 作者: T Tomas Vik

test: convert credentials provider integration test to unit test

上级 79036184
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);
});
});
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);
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册