parsePath unit tests

This commit is contained in:
Laura Liberda 2021-02-22 19:32:10 +01:00
parent 5a363e66e2
commit cc87a02aae

View file

@ -0,0 +1,63 @@
import { parsePath } from '../utils';
import { ENTITY_TYPE } from '../types';
test('parsePath gitlab issue', () => {
const path = parsePath('https://git.sakamoto.pl/laudompat/haruhi-dl/-/issues/33#note_169');
expect(path.domain).toEqual('git.sakamoto.pl');
expect(path.path).toEqual('laudompat/haruhi-dl');
expect(path.entity).toEqual(ENTITY_TYPE.ISSUE);
expect(path.entityID).toEqual('33');
});
test('parsePath github issue', () => {
const path = parsePath('https://github.com/haruhi-dl/haruhi-dl/issues/1#issue-802641781');
expect(path.domain).toEqual('github.com');
expect(path.path).toEqual('haruhi-dl/haruhi-dl');
expect(path.entity).toEqual(ENTITY_TYPE.ISSUE);
expect(path.entityID).toEqual('1');
});
test('parsePath gitlab merge request', () => {
const path = parsePath(
'https://gitlab.com/gitlab-org/5-minute-production-app/examples/expressjs-app/-/merge_requests/1',
);
expect(path.domain).toEqual('gitlab.com');
expect(path.path).toEqual('gitlab-org/5-minute-production-app/examples/expressjs-app');
expect(path.entity).toEqual(ENTITY_TYPE.MERGE_REQUEST);
expect(path.entityID).toEqual('1');
});
test('parsePath github merge request', () => {
const path = parsePath('https://github.com/AliasIO/wappalyzer/pull/3438#issue-509001361');
expect(path.domain).toEqual('github.com');
expect(path.path).toEqual('AliasIO/wappalyzer');
expect(path.entity).toEqual(ENTITY_TYPE.MERGE_REQUEST);
expect(path.entityID).toEqual('3438');
});
test('parsePath gitlab project', () => {
const path = parsePath('https://framagit.org/erupcja/uonetplus-hebe-api-docs?fbclid=xD');
expect(path.domain).toEqual('framagit.org');
expect(path.path).toEqual('erupcja/uonetplus-hebe-api-docs');
expect(path.entity).toBeNull();
expect(path.entityID).toBeNull();
});
test('parsePath gitlab project (trailing slash)', () => {
const path = parsePath('https://framagit.org/erupcja/uonetplus-hebe-api-docs/');
expect(path.domain).toEqual('framagit.org');
expect(path.path).toEqual('erupcja/uonetplus-hebe-api-docs');
expect(path.entity).toBeNull();
expect(path.entityID).toBeNull();
});
test('parsePath github project', () => {
const path = parsePath('https://github.com/haruhi-dl/haruhi-dl#readme');
expect(path.domain).toEqual('github.com');
expect(path.path).toEqual('haruhi-dl/haruhi-dl');
expect(path.entity).toBeNull();
expect(path.entityID).toBeNull();
});
test('parsePath github project (trailing slash)', () => {
const path = parsePath('https://github.com/haruhi-dl/haruhi-dl/#readme');
expect(path.domain).toEqual('github.com');
expect(path.path).toEqual('haruhi-dl/haruhi-dl');
expect(path.entity).toBeNull();
expect(path.entityID).toBeNull();
});