Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/migrating sinon to 6.0.1 #4

Merged
merged 4 commits into from
Jun 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@
},
"devDependencies": {
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"coveralls": "^3.0.1",
"eslint": "^4.19.1",
"eslint": "^5.0.1",
"istanbul": "^0.4.5",
"mocha": "^5.2.0",
"mocha-lcov-reporter": "^1.3.0",
"proxyquire": "^2.0.1",
"sinon": "^4.2.2",
"sinon-stub-promise": "^4.0.0"
"sinon": "^6.0.1"
}
}
40 changes: 26 additions & 14 deletions test/Bitbucket.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let expect = require('chai').expect,
let chai = require('chai'),
sinon = require('sinon'),
proxyquire = require('proxyquire');
proxyquire = require('proxyquire'),
expect = chai.expect;

describe('Bitbucket', function() {
let Bitbucket,
Expand Down Expand Up @@ -94,7 +95,7 @@ describe('Bitbucket', function() {
let promise;

beforeEach(function() {
promise = sinon.stub().returnsPromise();
promise = sinon.stub();

Bitbucket = proxyquire('../lib/Bitbucket', {
'request-promise': promise
Expand All @@ -110,7 +111,9 @@ describe('Bitbucket', function() {
let result = client.obtainTokens();

// assert
expect(result.rejectValue.toString()).to.equal('Error: Can not fetch client tokens. Stack trace: foobar');
return result.catch((err) => {
expect(err.toString()).to.equal('Error: Can not fetch client tokens. Stack trace: foobar');
});
});

it('should throw an error if response is not valid JSON', function() {
Expand All @@ -122,7 +125,9 @@ describe('Bitbucket', function() {
let result = client.obtainTokens();

// assert
expect(result.rejectValue.toString()).to.equal('Error: Can not fetch client tokens. Stack trace: Error: Cannot parse tokens. Stack trace: SyntaxError: Unexpected token o in JSON at position 1');
return result.catch((err) => {
expect(err.toString()).to.equal('Error: Can not fetch client tokens. Stack trace: Error: Cannot parse tokens. Stack trace: SyntaxError: Unexpected token o in JSON at position 1');
});
});

it('should set access and refresh tokens if request is successful', function() {
Expand All @@ -135,19 +140,21 @@ describe('Bitbucket', function() {

// act
let client = new Bitbucket(clientId, clientSecret, accessToken, refreshToken);
client.obtainTokens();
let result = client.obtainTokens();

// assert
expect(client.accessToken).to.equal(response.access_token);
expect(client.refreshToken).to.equal(response.refresh_token);
return result.then(() => {
expect(client.accessToken).to.equal(response.access_token);
expect(client.refreshToken).to.equal(response.refresh_token);
});
});
});

describe('refreshTokens', function() {
let promise;

beforeEach(function() {
promise = sinon.stub().returnsPromise();
promise = sinon.stub();

Bitbucket = proxyquire('../lib/Bitbucket', {
'request-promise': promise
Expand All @@ -163,7 +170,9 @@ describe('Bitbucket', function() {
let result = client.refreshTokens();

// assert
expect(result.rejectValue.toString()).to.equal('Error: Can not refresh access token by given refresh: refreshToken. Stack trace: foobar');
return result.catch((err) => {
expect(err.toString()).to.equal('Error: Can not refresh access token by given refresh: refreshToken. Stack trace: foobar');
});
});

it('should throw an error if response is not valid JSON', function() {
Expand All @@ -175,8 +184,9 @@ describe('Bitbucket', function() {
let result = client.refreshTokens();

// assert
expect(result.rejectValue.toString()).to.equal('Error: Can not refresh access token by given refresh: refreshToken. Stack trace: Error: Cannot parse tokens. Stack trace: SyntaxError: Unexpected token o in JSON at position 1');

return result.catch((err) => {
expect(err.toString()).to.equal('Error: Can not refresh access token by given refresh: refreshToken. Stack trace: Error: Cannot parse tokens. Stack trace: SyntaxError: Unexpected token o in JSON at position 1');
});
});

it('should refresh access token by given refresh token', function() {
Expand All @@ -188,10 +198,12 @@ describe('Bitbucket', function() {

// act
let client = new Bitbucket(clientId, clientSecret, accessToken, refreshToken);
client.refreshTokens();
let result = client.refreshTokens();

// assert
expect(client.accessToken).to.equal(response.access_token);
return result.then(() => {
expect(client.accessToken).to.equal(response.access_token);
});
});
});

Expand Down
11 changes: 4 additions & 7 deletions test/Jira.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
let chai = require('chai'),
chaiAsPromised = require('chai-as-promised'),
sinon = require('sinon'),
sinonStubPromise = require('sinon-stub-promise'),
proxyquire = require('proxyquire'),
expect = chai.expect;

sinonStubPromise(sinon);
chai.use(chaiAsPromised);

describe('Jira', function() {
let Jira,
domain,
Expand Down Expand Up @@ -122,7 +117,7 @@ describe('Jira', function() {
let promise;

beforeEach(function() {
promise = sinon.stub().returnsPromise();
promise = sinon.stub();

Jira = proxyquire('../lib/Jira', {
'request-promise': promise
Expand Down Expand Up @@ -198,7 +193,9 @@ describe('Jira', function() {
let result = jira.transitionIssue(issueId, options);

// assert
expect(result.rejectValue.toString()).to.equal('Error: Can not transition issue FOO-666 to 323. Stack trace: bad request');
return result.catch((err) => {
expect(err.toString()).to.equal('Error: Can not transition issue FOO-666 to 323. Stack trace: bad request');
});
});

it('should return empty response if successful', function() {
Expand Down