1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | return new (P || (P = Promise))(function (resolve, reject) {
|
4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
7 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8 | });
|
9 | };
|
10 | var __generator = (this && this.__generator) || function (thisArg, body) {
|
11 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
12 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
13 | function verb(n) { return function (v) { return step([n, v]); }; }
|
14 | function step(op) {
|
15 | if (f) throw new TypeError("Generator is already executing.");
|
16 | while (_) try {
|
17 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
18 | if (y = 0, t) op = [op[0] & 2, t.value];
|
19 | switch (op[0]) {
|
20 | case 0: case 1: t = op; break;
|
21 | case 4: _.label++; return { value: op[1], done: false };
|
22 | case 5: _.label++; y = op[1]; op = [0]; continue;
|
23 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
24 | default:
|
25 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
26 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
27 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
28 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
29 | if (t[2]) _.ops.pop();
|
30 | _.trys.pop(); continue;
|
31 | }
|
32 | op = body.call(thisArg, _);
|
33 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
34 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
35 | }
|
36 | };
|
37 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
38 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
39 | };
|
40 | var _this = this;
|
41 | Object.defineProperty(exports, "__esModule", { value: true });
|
42 | var git_1 = __importDefault(require("../git"));
|
43 | var authenticate = jest.fn();
|
44 | var listLabelsOnIssue = jest.fn();
|
45 | var createRelease = jest.fn();
|
46 | var getLatestRelease = jest.fn();
|
47 | var getUser = jest.fn();
|
48 | var getByUsername = jest.fn();
|
49 | var getPr = jest.fn();
|
50 | var createStatus = jest.fn();
|
51 | var createComment = jest.fn();
|
52 | var listComments = jest.fn();
|
53 | var deleteComment = jest.fn();
|
54 | var listCommits = jest.fn();
|
55 | var getProject = jest.fn();
|
56 | var listLabelsForRepo = jest.fn();
|
57 | var issuesAndPullRequests = jest.fn();
|
58 | var createLabel = jest.fn();
|
59 | var updateLabel = jest.fn();
|
60 | var addLabels = jest.fn();
|
61 | var list = jest.fn();
|
62 | var lock = jest.fn();
|
63 | var errorHook = jest.fn();
|
64 | var get = jest.fn();
|
65 | var update = jest.fn();
|
66 | var paginate = jest.fn();
|
67 | jest.mock('@octokit/rest', function () {
|
68 | var instance = function () { return ({
|
69 | authenticate: authenticate,
|
70 | paginate: paginate,
|
71 | pulls: {
|
72 | get: getPr,
|
73 | listCommits: { endpoint: listCommits },
|
74 | list: list
|
75 | },
|
76 | issues: {
|
77 | listLabelsOnIssue: listLabelsOnIssue,
|
78 | createComment: createComment,
|
79 | listComments: listComments,
|
80 | deleteComment: deleteComment,
|
81 | listLabelsForRepo: listLabelsForRepo,
|
82 | createLabel: createLabel,
|
83 | updateLabel: updateLabel,
|
84 | addLabels: addLabels,
|
85 | lock: lock,
|
86 | get: get,
|
87 | update: update
|
88 | },
|
89 | repos: {
|
90 | createStatus: createStatus,
|
91 | createRelease: createRelease,
|
92 | getLatestRelease: getLatestRelease,
|
93 | get: getProject
|
94 | },
|
95 | search: {
|
96 | users: getUser,
|
97 | issuesAndPullRequests: issuesAndPullRequests
|
98 | },
|
99 | users: {
|
100 | getByUsername: getByUsername
|
101 | },
|
102 | hook: {
|
103 | error: errorHook
|
104 | }
|
105 | }); };
|
106 | instance.plugin = function () { return instance; };
|
107 | return instance;
|
108 | });
|
109 | jest.mock('@octokit/graphql', function () { return function () { return ({
|
110 | status: 'success'
|
111 | }); }; });
|
112 | var options = {
|
113 | owner: 'Adam Dierkens',
|
114 | repo: 'test',
|
115 | token: 'MyToken'
|
116 | };
|
117 | describe('github', function () {
|
118 | beforeEach(function () {
|
119 | authenticate.mockClear();
|
120 | listLabelsOnIssue.mockClear();
|
121 | createRelease.mockClear();
|
122 | getLatestRelease.mockClear();
|
123 | getUser.mockClear();
|
124 | getPr.mockClear();
|
125 | createStatus.mockClear();
|
126 | createComment.mockClear();
|
127 | listComments.mockClear();
|
128 | deleteComment.mockClear();
|
129 | listLabelsForRepo.mockClear();
|
130 | addLabels.mockClear();
|
131 | });
|
132 | describe('getLabels', function () {
|
133 | test('successful', function () { return __awaiter(_this, void 0, void 0, function () {
|
134 | var gh, _a;
|
135 | return __generator(this, function (_b) {
|
136 | switch (_b.label) {
|
137 | case 0:
|
138 | gh = new git_1.default(options);
|
139 | listLabelsOnIssue.mockReturnValueOnce({
|
140 | data: [
|
141 | { name: 'minor' },
|
142 | { name: 'documentation' },
|
143 | { name: 'major' },
|
144 | { name: 'internal' }
|
145 | ]
|
146 | });
|
147 | _a = expect;
|
148 | return [4 , gh.getLabels(123)];
|
149 | case 1:
|
150 | _a.apply(void 0, [_b.sent()]).toEqual([
|
151 | 'minor',
|
152 | 'documentation',
|
153 | 'major',
|
154 | 'internal'
|
155 | ]);
|
156 | return [2 ];
|
157 | }
|
158 | });
|
159 | }); });
|
160 | test('handles errors', function () { return __awaiter(_this, void 0, void 0, function () {
|
161 | var gh;
|
162 | return __generator(this, function (_a) {
|
163 | gh = new git_1.default(options);
|
164 | expect(gh.getLabels(123)).rejects.toBeTruthy();
|
165 | return [2 ];
|
166 | });
|
167 | }); });
|
168 | });
|
169 | test('publish', function () { return __awaiter(_this, void 0, void 0, function () {
|
170 | var gh;
|
171 | return __generator(this, function (_a) {
|
172 | switch (_a.label) {
|
173 | case 0:
|
174 | gh = new git_1.default(options);
|
175 | return [4 , gh.publish('releaseNotes', 'tag')];
|
176 | case 1:
|
177 | _a.sent();
|
178 | expect(createRelease).toHaveBeenCalled();
|
179 | return [2 ];
|
180 | }
|
181 | });
|
182 | }); });
|
183 | test('graphql', function () { return __awaiter(_this, void 0, void 0, function () {
|
184 | var gh, result;
|
185 | return __generator(this, function (_a) {
|
186 | switch (_a.label) {
|
187 | case 0:
|
188 | gh = new git_1.default(options);
|
189 | return [4 , gh.graphql('{ someQuery }')];
|
190 | case 1:
|
191 | result = _a.sent();
|
192 | expect(result.status).toBe('success');
|
193 | return [2 ];
|
194 | }
|
195 | });
|
196 | }); });
|
197 | test('getFirstCommit ', function () { return __awaiter(_this, void 0, void 0, function () {
|
198 | var gh, _a;
|
199 | return __generator(this, function (_b) {
|
200 | switch (_b.label) {
|
201 | case 0:
|
202 | gh = new git_1.default(options);
|
203 | _a = expect;
|
204 | return [4 , gh.getFirstCommit()];
|
205 | case 1:
|
206 | _a.apply(void 0, [_b.sent()]).toBe('0b2af75d8b55c8869cda93d0e5589ad9f2677e18');
|
207 | return [2 ];
|
208 | }
|
209 | });
|
210 | }); });
|
211 | test('addLabelToPr ', function () { return __awaiter(_this, void 0, void 0, function () {
|
212 | var gh;
|
213 | return __generator(this, function (_a) {
|
214 | switch (_a.label) {
|
215 | case 0:
|
216 | gh = new git_1.default(options);
|
217 | return [4 , gh.addLabelToPr(123, 'foo bar')];
|
218 | case 1:
|
219 | _a.sent();
|
220 | expect(addLabels).toHaveBeenCalled();
|
221 | return [2 ];
|
222 | }
|
223 | });
|
224 | }); });
|
225 | test('lockIssue ', function () { return __awaiter(_this, void 0, void 0, function () {
|
226 | var gh;
|
227 | return __generator(this, function (_a) {
|
228 | switch (_a.label) {
|
229 | case 0:
|
230 | gh = new git_1.default(options);
|
231 | return [4 , gh.lockIssue(123)];
|
232 | case 1:
|
233 | _a.sent();
|
234 | expect(lock).toHaveBeenCalled();
|
235 | return [2 ];
|
236 | }
|
237 | });
|
238 | }); });
|
239 | test('getCommitDate ', function () { return __awaiter(_this, void 0, void 0, function () {
|
240 | var gh, _a;
|
241 | return __generator(this, function (_b) {
|
242 | switch (_b.label) {
|
243 | case 0:
|
244 | gh = new git_1.default(options);
|
245 | _a = expect;
|
246 | return [4 , gh.getCommitDate('0b2af75d8b55c8869cda93d0e5589ad9f2677e18')];
|
247 | case 1:
|
248 | _a.apply(void 0, [_b.sent()]).toBe('2018-12-03T15:19:38-0800');
|
249 | return [2 ];
|
250 | }
|
251 | });
|
252 | }); });
|
253 | test('getSha', function () { return __awaiter(_this, void 0, void 0, function () {
|
254 | var gh, _a;
|
255 | return __generator(this, function (_b) {
|
256 | switch (_b.label) {
|
257 | case 0:
|
258 | gh = new git_1.default(options);
|
259 | _a = expect;
|
260 | return [4 , gh.getSha()];
|
261 | case 1:
|
262 | _a.apply(void 0, [_b.sent()]).toBeDefined();
|
263 | return [2 ];
|
264 | }
|
265 | });
|
266 | }); });
|
267 | test('getLatestTagInBranch', function () { return __awaiter(_this, void 0, void 0, function () {
|
268 | var gh, _a;
|
269 | return __generator(this, function (_b) {
|
270 | switch (_b.label) {
|
271 | case 0:
|
272 | gh = new git_1.default(options);
|
273 | _a = expect;
|
274 | return [4 , gh.getLatestTagInBranch()];
|
275 | case 1:
|
276 | _a.apply(void 0, [_b.sent()]).toBeDefined();
|
277 | return [2 ];
|
278 | }
|
279 | });
|
280 | }); });
|
281 | test('getGitLog ', function () { return __awaiter(_this, void 0, void 0, function () {
|
282 | var gh, _a;
|
283 | return __generator(this, function (_b) {
|
284 | switch (_b.label) {
|
285 | case 0:
|
286 | gh = new git_1.default(options);
|
287 | _a = expect;
|
288 | return [4 , gh.getGitLog('0b2af75d8b55c8869cda93d0e5589ad9f2677e18', 'a7f6634429731055a5a44bae24ac88c5f9822e58')];
|
289 | case 1:
|
290 | _a.apply(void 0, [_b.sent()]).toMatchSnapshot();
|
291 | return [2 ];
|
292 | }
|
293 | });
|
294 | }); });
|
295 | test('getUser', function () { return __awaiter(_this, void 0, void 0, function () {
|
296 | var gh, _a;
|
297 | return __generator(this, function (_b) {
|
298 | switch (_b.label) {
|
299 | case 0:
|
300 | gh = new git_1.default(options);
|
301 | getPr.mockReturnValueOnce('asdfasdf');
|
302 | _a = expect;
|
303 | return [4 , gh.getPullRequest(22)];
|
304 | case 1:
|
305 | _a.apply(void 0, [_b.sent()]).toBe('asdfasdf');
|
306 | return [2 ];
|
307 | }
|
308 | });
|
309 | }); });
|
310 | test('createStatus', function () { return __awaiter(_this, void 0, void 0, function () {
|
311 | var gh, _a;
|
312 | return __generator(this, function (_b) {
|
313 | switch (_b.label) {
|
314 | case 0:
|
315 | gh = new git_1.default(options);
|
316 | createStatus.mockReturnValueOnce(true);
|
317 | _a = expect;
|
318 | return [4 , gh.createStatus({
|
319 | state: 'pending',
|
320 | sha: '',
|
321 | context: 'foo',
|
322 | target_url: 'google.com',
|
323 | description: 'testing'
|
324 | })];
|
325 | case 1:
|
326 | _a.apply(void 0, [_b.sent()]).toBeTruthy();
|
327 | return [2 ];
|
328 | }
|
329 | });
|
330 | }); });
|
331 | test('search', function () { return __awaiter(_this, void 0, void 0, function () {
|
332 | var gh;
|
333 | return __generator(this, function (_a) {
|
334 | switch (_a.label) {
|
335 | case 0:
|
336 | gh = new git_1.default(options);
|
337 | issuesAndPullRequests.mockReturnValueOnce({ data: true });
|
338 | return [4 , gh.searchRepo({
|
339 | q: 'is:pr is:open',
|
340 | order: 'desc'
|
341 | })];
|
342 | case 1:
|
343 | _a.sent();
|
344 | expect(issuesAndPullRequests).toHaveBeenCalledWith({
|
345 | q: 'repo:Adam Dierkens/test is:pr is:open',
|
346 | order: 'desc'
|
347 | });
|
348 | return [2 ];
|
349 | }
|
350 | });
|
351 | }); });
|
352 | test('getProject', function () { return __awaiter(_this, void 0, void 0, function () {
|
353 | var gh, _a;
|
354 | return __generator(this, function (_b) {
|
355 | switch (_b.label) {
|
356 | case 0:
|
357 | gh = new git_1.default(options);
|
358 | getProject.mockReturnValueOnce({ data: true });
|
359 | _a = expect;
|
360 | return [4 , gh.getProject()];
|
361 | case 1:
|
362 | _a.apply(void 0, [_b.sent()]).toBeTruthy();
|
363 | return [2 ];
|
364 | }
|
365 | });
|
366 | }); });
|
367 | describe('createComment', function () {
|
368 | test('should post comment if none exists', function () { return __awaiter(_this, void 0, void 0, function () {
|
369 | var gh;
|
370 | return __generator(this, function (_a) {
|
371 | switch (_a.label) {
|
372 | case 0:
|
373 | gh = new git_1.default(options);
|
374 | listComments.mockReturnValueOnce({ data: [] });
|
375 | return [4 , gh.createComment('Some long thing', 22, 'default')];
|
376 | case 1:
|
377 | _a.sent();
|
378 | expect(createComment).toHaveBeenCalled();
|
379 | return [2 ];
|
380 | }
|
381 | });
|
382 | }); });
|
383 | test('should delete old comment', function () { return __awaiter(_this, void 0, void 0, function () {
|
384 | var gh;
|
385 | return __generator(this, function (_a) {
|
386 | switch (_a.label) {
|
387 | case 0:
|
388 | gh = new git_1.default(options);
|
389 | listComments.mockReturnValueOnce({
|
390 | data: [
|
391 | {
|
392 | body: '<!-- GITHUB_RELEASE COMMENT: default -->\nSome cool message',
|
393 | id: 1337
|
394 | }
|
395 | ]
|
396 | });
|
397 | return [4 , gh.createComment('Some long thing', 22, 'default')];
|
398 | case 1:
|
399 | _a.sent();
|
400 | expect(deleteComment).toHaveBeenCalled();
|
401 | expect(deleteComment.mock.calls[0][0].comment_id).toBe(1337);
|
402 | expect(createComment).toHaveBeenCalled();
|
403 | return [2 ];
|
404 | }
|
405 | });
|
406 | }); });
|
407 | test('should be able to comment in different contexts', function () { return __awaiter(_this, void 0, void 0, function () {
|
408 | var gh;
|
409 | return __generator(this, function (_a) {
|
410 | switch (_a.label) {
|
411 | case 0:
|
412 | gh = new git_1.default(options);
|
413 | listComments.mockReturnValueOnce({
|
414 | data: [
|
415 | {
|
416 | body: '<!-- GITHUB_RELEASE COMMENT: default -->\nSome cool message',
|
417 | id: 1337
|
418 | }
|
419 | ]
|
420 | });
|
421 | return [4 , gh.createComment('Some long thing', 22, 'PERF')];
|
422 | case 1:
|
423 | _a.sent();
|
424 | expect(deleteComment).not.toHaveBeenCalled();
|
425 | expect(createComment).toHaveBeenCalled();
|
426 | listComments.mockReturnValueOnce({
|
427 | data: [
|
428 | {
|
429 | body: '<!-- GITHUB_RELEASE COMMENT: default -->\nSome cool message',
|
430 | id: 1337
|
431 | },
|
432 | {
|
433 | body: '<!-- GITHUB_RELEASE COMMENT: PERF -->\nSome cool message',
|
434 | id: 1000
|
435 | }
|
436 | ]
|
437 | });
|
438 | return [4 , gh.createComment('Some new thing', 22, 'PERF')];
|
439 | case 2:
|
440 | _a.sent();
|
441 | expect(deleteComment).toHaveBeenCalled();
|
442 | expect(deleteComment.mock.calls[0][0].comment_id).toBe(1000);
|
443 | return [2 ];
|
444 | }
|
445 | });
|
446 | }); });
|
447 | });
|
448 | describe('addToPrBody', function () {
|
449 | test('should add to PR body if none exists', function () { return __awaiter(_this, void 0, void 0, function () {
|
450 | var gh;
|
451 | return __generator(this, function (_a) {
|
452 | switch (_a.label) {
|
453 | case 0:
|
454 | gh = new git_1.default(options);
|
455 | get.mockReturnValueOnce({ data: { body: '# My Content' } });
|
456 | return [4 , gh.addToPrBody('Some long thing', 22)];
|
457 | case 1:
|
458 | _a.sent();
|
459 | expect(update).toHaveBeenCalledWith(expect.objectContaining({
|
460 | body: '# My Content\n<!-- GITHUB_RELEASE PR BODY: default -->\nSome long thing\n<!-- GITHUB_RELEASE PR BODY: default -->\n'
|
461 | }));
|
462 | return [2 ];
|
463 | }
|
464 | });
|
465 | }); });
|
466 | test('should add to PR body if none exists', function () { return __awaiter(_this, void 0, void 0, function () {
|
467 | var gh;
|
468 | return __generator(this, function (_a) {
|
469 | switch (_a.label) {
|
470 | case 0:
|
471 | gh = new git_1.default(options);
|
472 | get.mockReturnValueOnce({ data: { body: '# My Content' } });
|
473 | return [4 , gh.addToPrBody('', 22)];
|
474 | case 1:
|
475 | _a.sent();
|
476 | expect(update).toHaveBeenCalledWith(expect.objectContaining({
|
477 | body: '# My Content'
|
478 | }));
|
479 | return [2 ];
|
480 | }
|
481 | });
|
482 | }); });
|
483 | test('should overwrite old context', function () { return __awaiter(_this, void 0, void 0, function () {
|
484 | var gh;
|
485 | return __generator(this, function (_a) {
|
486 | switch (_a.label) {
|
487 | case 0:
|
488 | gh = new git_1.default(options);
|
489 | get.mockReturnValueOnce({
|
490 | data: {
|
491 | body: '# My Content\n<!-- GITHUB_RELEASE PR BODY: default -->\n\n\nSome long thing\nand more\n<!-- GITHUB_RELEASE PR BODY: default -->\n'
|
492 | }
|
493 | });
|
494 | return [4 , gh.addToPrBody('Something else', 22)];
|
495 | case 1:
|
496 | _a.sent();
|
497 | expect(update).toHaveBeenCalledWith(expect.objectContaining({
|
498 | body: '# My Content\n<!-- GITHUB_RELEASE PR BODY: default -->\nSomething else\n<!-- GITHUB_RELEASE PR BODY: default -->\n'
|
499 | }));
|
500 | return [2 ];
|
501 | }
|
502 | });
|
503 | }); });
|
504 | test('should be able to add to body in different contexts', function () { return __awaiter(_this, void 0, void 0, function () {
|
505 | var gh;
|
506 | return __generator(this, function (_a) {
|
507 | switch (_a.label) {
|
508 | case 0:
|
509 | gh = new git_1.default(options);
|
510 | get.mockReturnValueOnce({
|
511 | data: {
|
512 | body: '# My Content\n<!-- GITHUB_RELEASE PR BODY: default -->\nSomething else\n<!-- GITHUB_RELEASE PR BODY: default -->\n'
|
513 | }
|
514 | });
|
515 | return [4 , gh.addToPrBody('Some long thing', 22, 'PERF')];
|
516 | case 1:
|
517 | _a.sent();
|
518 | expect(update).toHaveBeenCalledWith(expect.objectContaining({
|
519 | body: '# My Content\n<!-- GITHUB_RELEASE PR BODY: default -->\nSomething else\n<!-- GITHUB_RELEASE PR BODY: default -->\n\n<!-- GITHUB_RELEASE PR BODY: PERF -->\nSome long thing\n<!-- GITHUB_RELEASE PR BODY: PERF -->\n'
|
520 | }));
|
521 | return [2 ];
|
522 | }
|
523 | });
|
524 | }); });
|
525 | test('should clear pr body section if message blank', function () { return __awaiter(_this, void 0, void 0, function () {
|
526 | var gh;
|
527 | return __generator(this, function (_a) {
|
528 | switch (_a.label) {
|
529 | case 0:
|
530 | gh = new git_1.default(options);
|
531 | get.mockReturnValueOnce({ data: { body: '# My Content' } });
|
532 | get.mockReturnValueOnce({
|
533 | data: {
|
534 | body: '# My Content\n<!-- GITHUB_RELEASE PR BODY: default -->\nSomething else\n<!-- GITHUB_RELEASE PR BODY: default -->'
|
535 | }
|
536 | });
|
537 | return [4 , gh.addToPrBody('Some long thing', 22)];
|
538 | case 1:
|
539 | _a.sent();
|
540 | update.mockClear();
|
541 | return [4 , gh.addToPrBody('', 22)];
|
542 | case 2:
|
543 | _a.sent();
|
544 | expect(update).toHaveBeenCalledWith(expect.objectContaining({
|
545 | body: '# My Content\n'
|
546 | }));
|
547 | return [2 ];
|
548 | }
|
549 | });
|
550 | }); });
|
551 | });
|
552 | test('getCommitsForPR', function () { return __awaiter(_this, void 0, void 0, function () {
|
553 | var gh;
|
554 | return __generator(this, function (_a) {
|
555 | switch (_a.label) {
|
556 | case 0:
|
557 | gh = new git_1.default(options);
|
558 | listCommits.mockReturnValueOnce({
|
559 | data: undefined
|
560 | });
|
561 | return [4 , gh.getCommitsForPR(22)];
|
562 | case 1:
|
563 | _a.sent();
|
564 | expect(listCommits).toHaveBeenCalled();
|
565 | return [2 ];
|
566 | }
|
567 | });
|
568 | }); });
|
569 | test('getCommitsForPR', function () { return __awaiter(_this, void 0, void 0, function () {
|
570 | var gh;
|
571 | return __generator(this, function (_a) {
|
572 | switch (_a.label) {
|
573 | case 0:
|
574 | gh = new git_1.default(options);
|
575 | list.mockReturnValueOnce({
|
576 | data: undefined
|
577 | });
|
578 | return [4 , gh.getPullRequests()];
|
579 | case 1:
|
580 | _a.sent();
|
581 | expect(listCommits).toHaveBeenCalled();
|
582 | return [2 ];
|
583 | }
|
584 | });
|
585 | }); });
|
586 | describe('getUserByUsername', function () {
|
587 | test('exists', function () { return __awaiter(_this, void 0, void 0, function () {
|
588 | var gh, _a;
|
589 | return __generator(this, function (_b) {
|
590 | switch (_b.label) {
|
591 | case 0:
|
592 | gh = new git_1.default(options);
|
593 | getByUsername.mockReturnValueOnce({
|
594 | data: { name: 'Andrew Lisowski' }
|
595 | });
|
596 | _a = expect;
|
597 | return [4 , gh.getUserByUsername('andrew')];
|
598 | case 1:
|
599 | _a.apply(void 0, [_b.sent()]).toEqual({
|
600 | name: 'Andrew Lisowski'
|
601 | });
|
602 | return [2 ];
|
603 | }
|
604 | });
|
605 | }); });
|
606 | test('not found', function () { return __awaiter(_this, void 0, void 0, function () {
|
607 | var gh, _a;
|
608 | return __generator(this, function (_b) {
|
609 | switch (_b.label) {
|
610 | case 0:
|
611 | gh = new git_1.default(options);
|
612 | getByUsername.mockRejectedValueOnce(Error);
|
613 | _a = expect;
|
614 | return [4 , gh.getUserByUsername('andrew')];
|
615 | case 1:
|
616 | _a.apply(void 0, [_b.sent()]).toBeUndefined();
|
617 | return [2 ];
|
618 | }
|
619 | });
|
620 | }); });
|
621 | });
|
622 | describe('getUserByEmail', function () {
|
623 | test('exists', function () { return __awaiter(_this, void 0, void 0, function () {
|
624 | var gh, _a;
|
625 | return __generator(this, function (_b) {
|
626 | switch (_b.label) {
|
627 | case 0:
|
628 | gh = new git_1.default(options);
|
629 | getUser.mockReturnValueOnce({
|
630 | data: { items: [{ login: 'hipstersmoothie' }] }
|
631 | });
|
632 | _a = expect;
|
633 | return [4 , gh.getUserByEmail('lisowski54@gmail.com')];
|
634 | case 1:
|
635 | _a.apply(void 0, [_b.sent()]).toEqual({
|
636 | login: 'hipstersmoothie'
|
637 | });
|
638 | return [2 ];
|
639 | }
|
640 | });
|
641 | }); });
|
642 | test('doesnt exist', function () { return __awaiter(_this, void 0, void 0, function () {
|
643 | var gh, _a;
|
644 | return __generator(this, function (_b) {
|
645 | switch (_b.label) {
|
646 | case 0:
|
647 | gh = new git_1.default(options);
|
648 | getUser.mockReturnValueOnce({
|
649 | data: undefined
|
650 | });
|
651 | _a = expect;
|
652 | return [4 , gh.getUserByEmail('lisowski54@gmail.com')];
|
653 | case 1:
|
654 | _a.apply(void 0, [_b.sent()]).toEqual({});
|
655 | return [2 ];
|
656 | }
|
657 | });
|
658 | }); });
|
659 | test('errors', function () { return __awaiter(_this, void 0, void 0, function () {
|
660 | var gh, _a;
|
661 | return __generator(this, function (_b) {
|
662 | switch (_b.label) {
|
663 | case 0:
|
664 | gh = new git_1.default(options);
|
665 | getByUsername.mockRejectedValueOnce(Error);
|
666 | _a = expect;
|
667 | return [4 , gh.getUserByEmail('lisowski54@gmail.com')];
|
668 | case 1:
|
669 | _a.apply(void 0, [_b.sent()]).toBeUndefined();
|
670 | return [2 ];
|
671 | }
|
672 | });
|
673 | }); });
|
674 | });
|
675 | describe('getLatestRelease', function () {
|
676 | test('has tag ', function () { return __awaiter(_this, void 0, void 0, function () {
|
677 | var gh, _a;
|
678 | return __generator(this, function (_b) {
|
679 | switch (_b.label) {
|
680 | case 0:
|
681 | gh = new git_1.default(options);
|
682 | getLatestRelease.mockReturnValueOnce({ data: { tag_name: '1.0.0' } });
|
683 | _a = expect;
|
684 | return [4 , gh.getLatestRelease()];
|
685 | case 1:
|
686 | _a.apply(void 0, [_b.sent()]).toBe('1.0.0');
|
687 | return [2 ];
|
688 | }
|
689 | });
|
690 | }); });
|
691 | test('no tags', function () { return __awaiter(_this, void 0, void 0, function () {
|
692 | var gh, _a;
|
693 | return __generator(this, function (_b) {
|
694 | switch (_b.label) {
|
695 | case 0:
|
696 | gh = new git_1.default(options);
|
697 | getLatestRelease.mockRejectedValueOnce({ status: 404 });
|
698 | _a = expect;
|
699 | return [4 , gh.getLatestRelease()];
|
700 | case 1:
|
701 | _a.apply(void 0, [_b.sent()]).toBe('0b2af75d8b55c8869cda93d0e5589ad9f2677e18');
|
702 | return [2 ];
|
703 | }
|
704 | });
|
705 | }); });
|
706 | test('handles errors', function () { return __awaiter(_this, void 0, void 0, function () {
|
707 | var gh;
|
708 | return __generator(this, function (_a) {
|
709 | gh = new git_1.default(options);
|
710 | expect(gh.getLatestRelease()).rejects.toBeTruthy();
|
711 | return [2 ];
|
712 | });
|
713 | }); });
|
714 | });
|
715 | describe('getProjectLabels ', function () {
|
716 | test('return labels', function () { return __awaiter(_this, void 0, void 0, function () {
|
717 | var gh, _a;
|
718 | return __generator(this, function (_b) {
|
719 | switch (_b.label) {
|
720 | case 0:
|
721 | gh = new git_1.default(options);
|
722 | listLabelsForRepo.mockReturnValueOnce({
|
723 | data: [{ name: 'first label' }, { name: 'second label' }]
|
724 | });
|
725 | _a = expect;
|
726 | return [4 , gh.getProjectLabels()];
|
727 | case 1:
|
728 | _a.apply(void 0, [_b.sent()]).toEqual([
|
729 | 'first label',
|
730 | 'second label'
|
731 | ]);
|
732 | return [2 ];
|
733 | }
|
734 | });
|
735 | }); });
|
736 | test('throw for errors', function () { return __awaiter(_this, void 0, void 0, function () {
|
737 | var gh;
|
738 | return __generator(this, function (_a) {
|
739 | gh = new git_1.default(options);
|
740 | expect(gh.getProjectLabels()).rejects.toBeTruthy();
|
741 | return [2 ];
|
742 | });
|
743 | }); });
|
744 | });
|
745 | describe('getPr ', function () {
|
746 | test('return pr', function () { return __awaiter(_this, void 0, void 0, function () {
|
747 | var gh, _a;
|
748 | return __generator(this, function (_b) {
|
749 | switch (_b.label) {
|
750 | case 0:
|
751 | gh = new git_1.default(options);
|
752 | get.mockReturnValueOnce({ success: true });
|
753 | _a = expect;
|
754 | return [4 , gh.getPr(123)];
|
755 | case 1:
|
756 | _a.apply(void 0, [_b.sent()]).toEqual({ success: true });
|
757 | return [2 ];
|
758 | }
|
759 | });
|
760 | }); });
|
761 | test('throw for errors', function () { return __awaiter(_this, void 0, void 0, function () {
|
762 | var gh;
|
763 | return __generator(this, function (_a) {
|
764 | switch (_a.label) {
|
765 | case 0:
|
766 | gh = new git_1.default(options);
|
767 | get.mockRejectedValueOnce(Error);
|
768 | return [4 /*yield*/, expect(gh.getPr(120)).rejects.toBeTruthy()];
|
769 | case 1:
|
770 | _a.sent();
|
771 | return [2 /*return*/];
|
772 | }
|
773 | });
|
774 | }); });
|
775 | });
|
776 | test('updateLabel', function () { return __awaiter(_this, void 0, void 0, function () {
|
777 | var gh;
|
778 | return __generator(this, function (_a) {
|
779 | switch (_a.label) {
|
780 | case 0:
|
781 | gh = new git_1.default(options);
|
782 | return [4 , gh.updateLabel('release', { name: 'Foo bar', description: 'test' })];
|
783 | case 1:
|
784 | _a.sent();
|
785 | expect(updateLabel).toHaveBeenCalledWith(expect.objectContaining({
|
786 | owner: 'Adam Dierkens',
|
787 | repo: 'test',
|
788 | current_name: 'Foo bar',
|
789 | description: 'test'
|
790 | }));
|
791 | return [2 ];
|
792 | }
|
793 | });
|
794 | }); });
|
795 | describe('createLabel', function () {
|
796 | test('should create a label', function () { return __awaiter(_this, void 0, void 0, function () {
|
797 | var gh;
|
798 | return __generator(this, function (_a) {
|
799 | switch (_a.label) {
|
800 | case 0:
|
801 | gh = new git_1.default(options);
|
802 | return [4 , gh.createLabel('release', { name: 'Foo bar', description: 'test' })];
|
803 | case 1:
|
804 | _a.sent();
|
805 | expect(createLabel).toHaveBeenCalledWith(expect.objectContaining({
|
806 | owner: 'Adam Dierkens',
|
807 | repo: 'test',
|
808 | name: 'Foo bar'
|
809 | }));
|
810 | return [2 ];
|
811 | }
|
812 | });
|
813 | }); });
|
814 | test('throw for errors', function () { return __awaiter(_this, void 0, void 0, function () {
|
815 | var gh;
|
816 | return __generator(this, function (_a) {
|
817 | gh = new git_1.default(options);
|
818 | expect(gh.getProjectLabels()).rejects.toBeTruthy();
|
819 | return [2 ];
|
820 | });
|
821 | }); });
|
822 | });
|
823 | describe('error hook', function () {
|
824 | test('strip authorization headers from error', function () {
|
825 | var error = function (headers) {
|
826 | if (headers === void 0) { headers = {}; }
|
827 | return ({
|
828 | name: 'Request failed',
|
829 | message: 'The request has failed',
|
830 | status: 404,
|
831 | headers: headers
|
832 | });
|
833 | };
|
834 |
|
835 | var gh = new git_1.default(options);
|
836 | expect(errorHook).toBeCalled();
|
837 | var errorHandler = errorHook.mock.calls[0][1];
|
838 | expect(errorHandler.bind(undefined, error({ authorization: 'token abc' }))).toThrow(error());
|
839 | });
|
840 | });
|
841 | });
|
842 |
|
\ | No newline at end of file |