Skip to content

Commit

Permalink
Add tests for github/gitlab exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Jan 8, 2019
1 parent 06464c9 commit e550c90
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/github.js
Expand Up @@ -4,6 +4,7 @@ const sinon = require('sinon');
const proxyquire = require('proxyquire');
const GitHubApi = require('@octokit/rest');
const githubRequestMock = require('./mock/github.request');
const { GitHubClientError } = require('../lib/errors');

const githubRequestStub = sinon.stub().callsFake(githubRequestMock);
const githubApi = new GitHubApi();
Expand Down Expand Up @@ -107,3 +108,31 @@ test('github release (override host)', async t => {
GitHubApiStub.resetHistory();
t.end();
});

test('github client error', async t => {
const stub = sinon.stub(githubApi.repos, 'createRelease');
const githubErr = new Error('Not found');
githubErr.status = 404;
stub.throws(githubErr);

const remoteUrl = 'https://github.com/webpro/release-it-test';
const version = '2.0.1';
const tagName = 'v${version}';

const github = new GitHub({
release: true,
remoteUrl,
tagName
});

try {
await github.release({ version });
} catch (err) {
t.ok(err instanceof GitHubClientError);
t.equal(err.message, '404 (Not found)');
}

GitHubApiStub.resetHistory();
githubRequestStub.resetHistory();
t.end();
});
24 changes: 24 additions & 0 deletions test/gitlab.js
Expand Up @@ -76,3 +76,27 @@ test('gitlab release (self-managed)', async t => {
gotStub.resetHistory();
t.end();
});

test('http error', async t => {
gotStub.throws(new Error('Not found'));

const remoteUrl = 'https://gitlab.com/webpro/release-it-test';
const version = '2.0.1';
const tagName = 'v${version}';

const gitlab = new GitLab({
release: true,
remoteUrl,
tagName
});

try {
await gitlab.release({ version });
} catch (err) {
t.ok(err instanceof Error);
t.equal(err.message, 'Not found');
}

gotStub.resetHistory();
t.end();
});

0 comments on commit e550c90

Please sign in to comment.