1 describe('app.cars', function() {
7 var carResponseSuccess = {
11 var carsResponseSuccess = [
14 var carsResponseError = 'Error: connect ECONNREFUSED';
18 beforeEach(function() {
21 inject(function(_$httpBackend_, _$log_, _cars_, _API_) {
22 $httpBackend = _$httpBackend_;
29 describe('cars service', function () {
31 it('should invoke GET all cars without error', function () {
34 $httpBackend.expectGET(API.CARS).respond(200, carsResponseSuccess);
35 cars.getAll().then(function(resp) {
40 expect(carsResponseSuccess).toEqual(respValue);
43 it('should invoke GET all cars with error', function () {
46 $httpBackend.expectGET(API.CARS).respond(400, carsResponseError);
47 cars.getAll().then(function() {}, function(reason) {
52 expect(carsResponseError).toEqual(reasonValue);
55 it('should invoke GET car by id without error', function () {
58 $httpBackend.expectGET(API.CAR.replace(':carId', id)).respond(200, carResponseSuccess);
59 cars.getById(id).then(function(resp) {
60 respValue = resp.data;
65 expect(carResponseSuccess).toEqual(respValue);
68 it('should invoke GET car by id with error', function () {
71 $httpBackend.expectGET(API.CAR.replace(':carId', id)).respond(400, carsResponseError);
72 cars.getById(id).then(function() {}, function(reason) {
73 reasonValue = reason.data;
78 expect(carsResponseError).toEqual(reasonValue);
83 afterEach(function() {
84 $httpBackend.verifyNoOutstandingExpectation();
85 $httpBackend.verifyNoOutstandingRequest();