UNPKG

client-ui

Version:

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

103 lines (94 loc) 3.5 kB
Function.prototype.bind = Function.prototype.bind || function (thisp) { var fn = this; return function () { return fn.apply(thisp, arguments); }; }; describe('Shared Client', 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) { $httpBackend = $injector.get('$httpBackend'); store = $injector.get('aiStorage'); }); }) var client ,$httpBackend ,store; beforeEach(inject(function(_client_) { client = _client_; if (store.get('client')) { store.remove('client'); } })); afterEach(function() { $httpBackend.verifyNoOutstandingExpectation(); $httpBackend.verifyNoOutstandingRequest(); }); describe('createClient', function() { it('should should set the contents of the message to the client store and return those same contents', function(){ var content = {client: true}; $httpBackend .expectPOST(server + 'signup/', content) .respond(200, content); client.createClient(content) .then(function(clientData) { assert.deepEqual(clientData, content); assert.deepEqual(store.get('client'), content); }, function(error) { }); $httpBackend.flush(); }); it('should not modify the client store on failure', function(){ var content = {client: true}; var message = 'There was a failure'; $httpBackend .expectPOST(server + 'signup/', content) .respond(400, message); client.createClient(content) .then(function(clientData) { }, function(error) { assert.equal(error, message); assert.deepEqual(store.get('client'), null); }); $httpBackend.flush(); }); }); describe('getClient', function() { it('should should set the contents of the message to the client store and return those same contents', function(){ var content = {client: true}; $httpBackend .expectGET(server + 'clients/client') .respond(200, content); client.getClient() .then(function(clientData) { assert.deepEqual(clientData, content); assert.deepEqual(store.get('client'), content); }, function(error) { }); $httpBackend.flush(); }); it('should not modify the client store on failure', function(){ var message = 'There was a failure'; $httpBackend .expectGET(server + 'clients/client') .respond(400, message); client.getClient() .then(function(clientData) { }, function(error) { assert.equal(error, message); assert.deepEqual(store.get('client'), null); }); $httpBackend.flush(); }); }); });