-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some tests for the BankID Service methods
- Loading branch information
Showing
2 changed files
with
53 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
// Require dependencies. | ||
var assert = require('chai').assert; | ||
var sinon = require('sinon'); | ||
var soapStub = require('soap/soap-stub'); | ||
'use strict'; | ||
|
||
// Require things to test. | ||
var BankID = require('../lib/BankID'); | ||
var helpers = require('./helpers'); | ||
var expect = require('chai').expect; | ||
var BankIDService = require('../lib/BankIDService'); | ||
var BankIdError = require('../lib/BankIDError'); | ||
|
||
// Create the test client stub. | ||
var clientStub = { | ||
Authenticate: sinon.stub(), | ||
Collect: sinon.stub(), | ||
Sign: sinon.stub(), | ||
}; | ||
|
||
clientStub.Authenticate.respondWithError = soapStub.createRespondingStub({}); | ||
describe('BankID Service', function () { | ||
|
||
soapStub.registerClient('BankID Stub Client', BankID.buildBankIDApiUrl('test'), clientStub); | ||
describe('createBankIDError', function () { | ||
|
||
describe('BankID Service', function () { | ||
var clientStub; | ||
var service; | ||
it('should create a new BankIDError when the BankID API returns an error object', function () { | ||
var error = BankIDService.createBankIDError(helpers.simulateBankIDError()); | ||
expect(error).to.be.instanceOf(BankIdError); | ||
}); | ||
|
||
beforeEach(function () { | ||
clientStub = soapStub.getStub('BankID Stub Client'); | ||
soapStub.reset(); | ||
service = new BankIDService(clientStub); | ||
it('should return the initial error object if not a BankID error', function () { | ||
var notBankIdError = new Error('Not a BankID error'); | ||
var error = BankIDService.createBankIDError(notBankIdError); | ||
expect(error).to.equal(notBankIdError); | ||
}); | ||
}); | ||
|
||
it('should handle error responses', function (done) { | ||
clientStub.Authenticate.respondWithError(); | ||
service.authenticate({}, done); | ||
describe('isValidSSN', function () { | ||
|
||
it('should return true on a ssn with 12 digits', function () { | ||
expect(BankIDService.isValidSSN('199001011337')).to.equal(true); | ||
}); | ||
|
||
it('should return false on a ssn that does not have 12 digits', function () { | ||
expect(BankIDService.isValidSSN('19900101')).to.equal(false); | ||
expect(BankIDService.isValidSSN('19900101133700')).to.equal(false); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Creates a mock error object that looks similar to an error recieved from | ||
* the BankID API. | ||
* | ||
* @return {object} | ||
*/ | ||
exports.simulateBankIDError = function () { | ||
const error = new Error('Some error message'); | ||
|
||
error.root = { | ||
Envelope: { | ||
Body: { | ||
Fault: { | ||
detail: { | ||
RpFault: { | ||
faultStatus: 'SOME_FAULT_STATUS', | ||
detailedDescription: 'Some detailed description', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
return error; | ||
} |