UNPKG

client-ui

Version:

Testing implementation of nodeJs Backend, angular frontend, and hopefully in a way that this can be deployed to s3/cloudfront

469 lines (462 loc) 17.8 kB
describe('Equifax Service', function() { var equifaxService; var server = 'http://qloans:8080/v1/'; var $httpBackend; var $rootScope; var $timeout; beforeEach(function() { angular.mock.module('clientApp', function($provide) { $provide.constant('rootConstants', { 'server': server }); $provide.service('$state', function() { }); $provide.service('$stateProvider', function() { }); }); }); // Get Service beforeEach(function() { inject(function($injector, _$rootScope_) { equifaxService = $injector.get('equifax'); $rootScope = $injector.get('$rootScope'); $timeout = $injector.get('$timeout'); }); }); describe('getBlackBox', function() { it('Should work if blackbox finishes before Fn is called', function(done){ var outputVal = "SOME_VALUE"; var self = this; equifaxService.retryInterval = 10; equifaxService.maxRetries = 1; window.ioGetBlackbox = function() { return { finished: true, blackbox: outputVal }; } equifaxService.getBlackBox() .then(function(successResponse) { assert.equal(successResponse, outputVal); done(); }, function(error) { // this should never get called assert.equal(false, true); }); $rootScope.$digest(); }); it('Should work if a retry has to happen', function(done){ var outputVal = "SOME_VALUE"; window.ioGetBlackbox = function() { return { finished: false }; }; $timeout(function() { window.ioGetBlackbox = function() { return { finished: true, blackbox: outputVal } } }); equifaxService.getBlackBox() .then(function(successResponse) { assert.equal(successResponse, outputVal); done(); }, function(error) { // this should never get called assert.equal(false, true); }); $timeout.flush(); }); it('Should gracefully output an error if there are too many retries', function(done){ var outputVal = "SOME_VALUE"; equifaxService.retryInterval = 1; equifaxService.maxRetries = 1; window.ioGetBlackbox = function() { return { finished: false }; } $timeout(function() { $timeout(function() { window.ioGetBlackbox = function() { return { finished: true, blackbox: outputVal } } }); }); equifaxService.getBlackBox() .then(function(successResponse) { done(); assert(successResponse, "NO_DOWNLOAD"); }, function(error) { // this should never get called assert.equal(false, true); }); $timeout.flush(); }); }); describe("mapQuizAnswers", function() { var input; beforeEach(function() { input = { "attributes": { "transactionKey": "_transactionKey" }, "Quiz": { "attributes": { "quizId": "_quizId" }, "Question": [ { "attributes": { "questionId": "1" }, "QuestionText": "What is the age range of the head of your household?", "userAnswer": { attributes: { "answerId": "1" } }, "AnswerChoice": [ { "attributes": { "answerId": "1" }, "$value": "45 - 54 years old" }, { "attributes": { "answerId": "2" }, "$value": "55 - 64 years old" }, { "attributes": { "answerId": "3" }, "$value": "65 - 74 years old" }, { "attributes": { "answerId": "4" }, "$value": "75 or more years" }, { "attributes": { "answerId": "5" }, "$value": "NONE OF THE ABOVE" } ] }, { "attributes": { "questionId": "2" }, "QuestionText": "How many adults 18 or over live in your household?", "userAnswer": { attributes: { "answerId": "3" } }, "AnswerChoice": [ { "attributes": { "answerId": "1" }, "$value": "2" }, { "attributes": { "answerId": "2" }, "$value": "3" }, { "attributes": { "answerId": "3" }, "$value": "4" }, { "attributes": { "answerId": "4" }, "$value": "5" }, { "attributes": { "answerId": "5" }, "$value": "NONE OF THE ABOVE" } ] }, { "attributes": { "questionId": "3" }, "QuestionText": "How long have you lived at your current address?", "userAnswer": { attributes: { "answerId": "4" } }, "AnswerChoice": [ { "attributes": { "answerId": "1" }, "$value": "4 - 5 years" }, { "attributes": { "answerId": "2" }, "$value": "6 - 7 years" }, { "attributes": { "answerId": "3" }, "$value": "8 - 9 years" }, { "attributes": { "answerId": "4" }, "$value": "10 - 11 years" }, { "attributes": { "answerId": "5" }, "$value": "NONE OF THE ABOVE" } ] } ] } }; }) it("Should create an object that matches the api documentation", function(done) { var output = { "QuizAnswerRequest": { "attributes": { "transactionKey": "_transactionKey", "quizId": "_quizId" }, "Answer": [ { "attributes": { "questionId": "1", "answerId": "1" } }, { "attributes": { "questionId": "2", "answerId": "3" } }, { "attributes": { "questionId": "3", "answerId": "4" } } ] } }; equifaxService.mapQuizAnswers(input, function(err, outputTest) { expect(output).to.deep.equal(outputTest); done(); }); }); it("Should gracefully return an error if there isn't a question node", function(done) { input.Quiz = {}; var output = { "QuizAnswerRequest": { "attributes": { "transactionKey": "_transactionKey", "quizId": "_quizId" }, "Answer": [ { "attributes": { "questionId": "1", "answerId": "1" } }, { "attributes": { "questionId": "2", "answerId": "3" } }, { "attributes": { "questionId": "3", "answerId": "4" } } ] } }; equifaxService.mapQuizAnswers(input, function(err, outputTest) { assert(err); expect(outputTest).to.equal(undefined); done(); }); }); it("Should gracefully return an error if there isnt a transactionKey", function(done) { input.attributes = {}; var output = { "QuizAnswerRequest": { "attributes": { "transactionKey": "_transactionKey", "quizId": "_quizId" }, "Answer": [ { "attributes": { "questionId": "1", "answerId": "1" } }, { "attributes": { "questionId": "2", "answerId": "3" } }, { "attributes": { "questionId": "3", "answerId": "4" } } ] } }; equifaxService.mapQuizAnswers(input, function(err, outputTest) { assert(err); expect(outputTest).to.equal(undefined); done(); }); }); it("Should be ok if there is no quiz id", function(done) { input.Quiz.attributes = {}; var output = { "QuizAnswerRequest": { "attributes": { "transactionKey": "_transactionKey", "quizId": "No quiz id" }, "Answer": [ { "attributes": { "questionId": "1", "answerId": "1" } }, { "attributes": { "questionId": "2", "answerId": "3" } }, { "attributes": { "questionId": "3", "answerId": "4" } } ] } }; equifaxService.mapQuizAnswers(input, function(err, outputTest) { expect(output).to.deep.equal(outputTest); done(); }); }); it("Should return an error if userAnswer is not set", function(done) { delete(input.Quiz.Question[0].userAnswer); var output = { "QuizAnswerRequest": { "attributes": { "transactionKey": "_transactionKey", "quizId": "No quiz id" }, "Answer": [ { "attributes": { "questionId": "1", "answerId": "1" } }, { "attributes": { "questionId": "2", "answerId": "3" } }, { "attributes": { "questionId": "3", "answerId": "4" } } ] } }; equifaxService.mapQuizAnswers(input, function(err, outputTest) { assert(err); expect(outputTest).to.equal(undefined); done(); }); }); it("Should return an error if userAnswer is not set", function(done) { input.Quiz.Question[0].attributes = {}; var output = { "QuizAnswerRequest": { "attributes": { "transactionKey": "_transactionKey", "quizId": "No quiz id" }, "Answer": [ { "attributes": { "questionId": "1", "answerId": "1" } }, { "attributes": { "questionId": "2", "answerId": "3" } }, { "attributes": { "questionId": "3", "answerId": "4" } } ] } }; equifaxService.mapQuizAnswers(input, function(err, outputTest) { assert(err); expect(outputTest).to.equal(undefined); done(); }); }); }); });