From cc87a02aaea73238bf618c17cd923885765acaff Mon Sep 17 00:00:00 2001 From: Laura Liberda Date: Mon, 22 Feb 2021 19:32:10 +0100 Subject: [PATCH] parsePath unit tests --- src/__tests__/utils.parsePath.ts | 63 ++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/__tests__/utils.parsePath.ts diff --git a/src/__tests__/utils.parsePath.ts b/src/__tests__/utils.parsePath.ts new file mode 100644 index 0000000..80e24ce --- /dev/null +++ b/src/__tests__/utils.parsePath.ts @@ -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(); +});