client-ui
Version:
Testing implementation of nodeJs Backend, angular frontend, and hopefully in a way that this can be deployed to s3/cloudfront
107 lines (98 loc) • 3.61 kB
JavaScript
/* global inject */
describe('Shared Util', function() {
var server = 'http://qloans:8080/v1/';
beforeEach(function() {
angular.mock.module('clientApp', function($provide) {
$provide.constant('rootConstants', {
'server': server
});
$provide.service('$state', function() {
});
});
});
beforeEach(function() {
inject(function($injector) {
});
});
var util;
beforeEach(inject(function(_util_) {
util = _util_;
}));
afterEach(function() {
});
describe('conditionalSet', function() {
it('should set if defined', function() {
var obj = {};
var key = 'someVal';
var testObj = {one: 'two'};
util.conditionalSet(obj, key, testObj.one);
assert.equal(obj[key], testObj.one);
});
it('should not set if defined', function() {
var obj = {};
var key = 'someVal';
var testObj = {one: 'two'};
util.conditionalSet(obj, key, testObj.two);
assert.equal(obj[key], undefined);
});
});
describe('padInteger', function() {
it('should work with numbers', function() {
assert.equal(util.padInteger(5, 2), "05");
});
it('should work with strings', function() {
assert.equal(util.padInteger("5", 2), "05");
});
});
describe('validDate', function() {
it('should work with date', function() {
assert.equal(util.validDate(1991, 4, 13), true);
});
it('should return false for dates that can"t happen', function() {
var valid = util.validDate(1991, 2, 31);
assert.equal(valid, false);
});
it('should return false for booleans', function() {
assert.equal(util.validDate(false), false);
});
it('should return false for letters', function() {
assert.equal(util.validDate("abc"), false);
});
});
describe('validBirthdate', function() {
it('Should return a date ISO for a 19 yr old date', function() {
var date = new Date();
var year = date.getFullYear();
year -= 19;
date.setYear(year);
var month = date.getMonth() + 1;
var day = date.getDate();
var validBirthdate = util.validBirthdate(month, day, year, 19);
assert.equal(typeof validBirthdate, "string");
var newDate = new Date(validBirthdate);
assert.equal(newDate.getFullYear(), year);
assert.equal(newDate.getMonth() + 1, month);
assert.equal(newDate.getDate(), day);
});
it('Should return false for a 17 yr old date', function() {
var date = new Date();
var year = date.getFullYear();
year -= 17;
date.setYear(year);
var month = date.getMonth() + 1;
var day = date.getDate();
var validBirthdate = util.validBirthdate(month, day, year);
assert.equal(validBirthdate, false);
});
it('should return false for an invalid 19 yr old date', function() {
var date = new Date();
var year = date.getFullYear();
year -= 19;
date.setYear(year);
var month = date.getMonth() + 1;
var day = date.getDate();
var validBirthdate = util.validBirthdate(2, 31, year);
assert.equal(validBirthdate, false);
});
});
});