This repository was archived by the owner on Apr 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathGithubURLs.ts
More file actions
95 lines (84 loc) · 3.71 KB
/
GithubURLs.ts
File metadata and controls
95 lines (84 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/// <reference path="../../_ref.d.ts" />
'use strict';
import fs = require('fs');
import path = require('path');
import Promise = require('bluebird');
import chai = require('chai');
var assert = chai.assert;
import fileIO = require('../../xm/fileIO');
import helper = require('../../test/helper');
import gitHelper = require('../../test/git/gitHelper');
import GitUtil = require('../../git/gitUtil');
import GithubURLs = require('../../git/GithubURLs');
import GithubRepo = require('../../git/GithubRepo');
describe('GithubRepo / GithubURLs', () => {
var repo: GithubRepo;
var urls: GithubURLs;
var gitTest = gitHelper.getGitTestInfo();
after(() => {
repo = null;
urls = null;
gitTest = null;
});
describe('GithubRepo', () => {
it('should be defined', () => {
assert.isFunction(GithubRepo, 'GithubRepo.constructor');
});
it('should throw on bad params', () => {
assert.throws(() => {
repo = new GithubRepo({repoOwner: null, repoProject: null, githubHost: null}, null, null);
});
});
it('should be constructor', () => {
repo = new GithubRepo({repoOwner: 'foo', repoProject: 'bar', githubHost: 'https://github.com'}, 'baz', gitTest.opts);
urls = repo.urls;
assert.ok(urls, 'instance');
});
});
describe('GithubURLs', () => {
it('should be defined', () => {
assert.isFunction(GithubURLs, 'GithubURLs.constructor');
});
it('should throw on bad params', () => {
assert.throws(() => {
urls = new GithubURLs(null);
});
});
it('should return replaced urls', () => {
urls = new GithubRepo({repoOwner: 'foo', repoProject: 'bar', githubHost: 'https://github.com'}, 'baz', gitTest.opts).urls;
var api = 'https://api.github.com/repos/foo/bar';
var raw = 'https://raw.githubusercontent.com/foo/bar';
var base = 'https://github.com/foo/bar';
var rawFile = raw + '/2ece23298f06d9fb45772fdb1d38086918c80f44/sub/folder/file.txt';
assert.strictEqual(urls.api(), api, 'api');
assert.strictEqual(urls.base(), base, 'base');
assert.strictEqual(urls.rawFile('2ece23298f06d9fb45772fdb1d38086918c80f44', 'sub/folder/file.txt'), rawFile, 'rawFile');
});
it('should return correctly replaced urls if repoConfig is modified after repo creation', () => {
var repoConfig = {repoOwner: 'foo', repoProject: 'bar', githubHost: 'https://github.com'};
urls = new GithubRepo(repoConfig, 'baz', gitTest.opts).urls;
repoConfig.repoOwner = 'correctOwner';
repoConfig.repoProject = 'correctProject';
var api = 'https://api.github.com/repos/correctOwner/correctProject';
var raw = 'https://raw.githubusercontent.com/correctOwner/correctProject';
var base = 'https://github.com/correctOwner/correctProject';
assert.strictEqual(urls.api(), api, 'api');
assert.strictEqual(urls.base(), base, 'base');
});
it('should return no trailing slash', () => {
urls = new GithubRepo({repoOwner: 'foo', repoProject: 'bar', githubHost: 'https://github.com'}, 'baz', gitTest.opts).urls;
assert.notMatch(urls.apiBranches(), /\/$/, 'apiBranches');
assert.notMatch(urls.apiBranch('abc'), /\/$/, 'apiBranch');
});
it('should handle enterprise github urls', () => {
urls = new GithubRepo({repoOwner: 'foo', repoProject: 'bar', githubHost: 'https://github.mycompany.com'}, 'baz', gitTest.opts).urls;
var api = 'https://github.mycompany.com/api/v3/repos/foo/bar';
var raw = 'https://github.mycompany.com/foo/bar/raw';
var base = 'https://github.mycompany.com/foo/bar';
var rawFile = raw + '/2ece23298f06d9fb45772fdb1d38086918c80f44/sub/folder/file.txt';
assert.strictEqual(urls.api(), api, 'api');
assert.strictEqual(urls.base(), base, 'base');
assert.strictEqual(urls.rawFile('2ece23298f06d9fb45772fdb1d38086918c80f44', 'sub/folder/file.txt'), rawFile, 'rawFile');
});
});
});