2011-07-17 08:05:43 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
describe("resource", function() {
|
2011-10-17 23:56:56 +00:00
|
|
|
var resource, CreditCard, callback;
|
|
|
|
|
|
2011-11-04 19:33:01 +00:00
|
|
|
function nakedExpect(obj) {
|
|
|
|
|
return expect(angular.fromJson(angular.toJson(obj)));
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
beforeEach(inject(function($http) {
|
|
|
|
|
resource = new ResourceFactory($http);
|
2011-10-17 23:56:56 +00:00
|
|
|
CreditCard = resource.route('/CreditCard/:id:verb', {id:'@id.key'}, {
|
|
|
|
|
charge:{
|
|
|
|
|
method:'POST',
|
|
|
|
|
params:{verb:'!charge'}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
callback = jasmine.createSpy();
|
|
|
|
|
})
|
|
|
|
|
);
|
2010-03-15 21:36:50 +00:00
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
afterEach(inject(function($httpBackend) {
|
2011-11-01 03:34:03 +00:00
|
|
|
$httpBackend.verifyNoOutstandingExpectation();
|
2011-10-19 17:47:17 +00:00
|
|
|
}));
|
|
|
|
|
|
2011-10-07 18:27:49 +00:00
|
|
|
it("should build resource", function() {
|
2011-08-05 23:24:12 +00:00
|
|
|
expect(typeof CreditCard).toBe('function');
|
|
|
|
|
expect(typeof CreditCard.get).toBe('function');
|
|
|
|
|
expect(typeof CreditCard.save).toBe('function');
|
|
|
|
|
expect(typeof CreditCard.remove).toBe('function');
|
|
|
|
|
expect(typeof CreditCard['delete']).toBe('function');
|
|
|
|
|
expect(typeof CreditCard.query).toBe('function');
|
2010-03-15 21:36:50 +00:00
|
|
|
});
|
|
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
it('should default to empty parameters', inject(function($httpBackend) {
|
|
|
|
|
$httpBackend.expect('GET', 'URL').respond({});
|
2010-03-16 21:48:11 +00:00
|
|
|
resource.route('URL').query();
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2010-03-16 21:48:11 +00:00
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
it('should ignore slashes of undefinend parameters', inject(function($httpBackend) {
|
2010-07-22 18:18:32 +00:00
|
|
|
var R = resource.route('/Path/:a/:b/:c');
|
2011-10-19 17:47:17 +00:00
|
|
|
|
2011-11-01 20:27:42 +00:00
|
|
|
$httpBackend.when('GET').respond('{}');
|
2011-10-19 17:47:17 +00:00
|
|
|
$httpBackend.expect('GET', '/Path');
|
|
|
|
|
$httpBackend.expect('GET', '/Path/1');
|
|
|
|
|
$httpBackend.expect('GET', '/Path/2/3');
|
|
|
|
|
$httpBackend.expect('GET', '/Path/4/5/6');
|
|
|
|
|
|
2010-07-22 18:18:32 +00:00
|
|
|
R.get({});
|
|
|
|
|
R.get({a:1});
|
|
|
|
|
R.get({a:2, b:3});
|
|
|
|
|
R.get({a:4, b:5, c:6});
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2010-07-22 18:18:32 +00:00
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
it('should correctly encode url params', inject(function($httpBackend) {
|
2011-02-11 01:57:42 +00:00
|
|
|
var R = resource.route('/Path/:a');
|
2011-10-19 17:47:17 +00:00
|
|
|
|
|
|
|
|
$httpBackend.expect('GET', '/Path/foo%231').respond('{}');
|
|
|
|
|
$httpBackend.expect('GET', '/Path/doh!@foo?bar=baz%231').respond('{}');
|
|
|
|
|
|
2011-02-11 01:57:42 +00:00
|
|
|
R.get({a: 'foo#1'});
|
|
|
|
|
R.get({a: 'doh!@foo', bar: 'baz#1'});
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2011-02-11 01:57:42 +00:00
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
it('should not encode @ in url params', inject(function($httpBackend) {
|
2011-04-01 04:45:28 +00:00
|
|
|
//encodeURIComponent is too agressive and doesn't follow http://www.ietf.org/rfc/rfc3986.txt
|
2011-02-17 00:48:21 +00:00
|
|
|
//with regards to the character set (pchar) allowed in path segments
|
|
|
|
|
//so we need this test to make sure that we don't over-encode the params and break stuff like
|
|
|
|
|
//buzz api which uses @self
|
|
|
|
|
|
|
|
|
|
var R = resource.route('/Path/:a');
|
2011-10-19 17:47:17 +00:00
|
|
|
$httpBackend.expect('GET', '/Path/doh@fo%20o?!do%26h=g%3Da+h&:bar=$baz@1').respond('{}');
|
2011-04-01 04:45:28 +00:00
|
|
|
R.get({a: 'doh@fo o', ':bar': '$baz@1', '!do&h': 'g=a h'});
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2011-02-17 00:48:21 +00:00
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
it('should encode & in url params', inject(function($httpBackend) {
|
2011-03-18 17:31:28 +00:00
|
|
|
var R = resource.route('/Path/:a');
|
2011-10-19 17:47:17 +00:00
|
|
|
$httpBackend.expect('GET', '/Path/doh&foo?bar=baz%261').respond('{}');
|
2011-03-18 17:31:28 +00:00
|
|
|
R.get({a: 'doh&foo', bar: 'baz&1'});
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2011-03-18 17:31:28 +00:00
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
it('should build resource with default param', inject(function($httpBackend) {
|
|
|
|
|
$httpBackend.expect('GET', '/Order/123/Line/456.visa?minimum=0.05').respond({id: 'abc'});
|
|
|
|
|
var LineItem = resource.route('/Order/:orderId/Line/:id:verb',
|
|
|
|
|
{orderId: '123', id: '@id.key', verb:'.visa', minimum: 0.05});
|
|
|
|
|
var item = LineItem.get({id: 456});
|
|
|
|
|
$httpBackend.flush();
|
2010-03-15 22:57:12 +00:00
|
|
|
nakedExpect(item).toEqual({id:'abc'});
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2010-03-15 22:57:12 +00:00
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
it("should build resource with action default param overriding default param", inject(function($httpBackend) {
|
|
|
|
|
$httpBackend.expect('GET', '/Customer/123').respond({id: 'abc'});
|
2011-09-02 13:50:10 +00:00
|
|
|
var TypeItem = resource.route('/:type/:typeId', {type: 'Order'},
|
|
|
|
|
{get: {method: 'GET', params: {type: 'Customer'}}});
|
2011-10-19 17:47:17 +00:00
|
|
|
var item = TypeItem.get({typeId: 123});
|
|
|
|
|
|
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
nakedExpect(item).toEqual({id: 'abc'});
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2011-09-02 13:50:10 +00:00
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
it("should create resource", inject(function($httpBackend) {
|
|
|
|
|
$httpBackend.expect('POST', '/CreditCard', '{"name":"misko"}').respond({id: 123, name: 'misko'});
|
2010-03-15 21:36:50 +00:00
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
var cc = CreditCard.save({name: 'misko'}, callback);
|
|
|
|
|
nakedExpect(cc).toEqual({name: 'misko'});
|
2011-05-31 08:32:54 +00:00
|
|
|
expect(callback).not.toHaveBeenCalled();
|
2011-10-19 17:47:17 +00:00
|
|
|
|
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
nakedExpect(cc).toEqual({id: 123, name: 'misko'});
|
2011-12-01 21:20:08 +00:00
|
|
|
expect(callback).toHaveBeenCalledOnce();
|
|
|
|
|
expect(callback.mostRecentCall.args[0]).toEqual(cc);
|
|
|
|
|
expect(callback.mostRecentCall.args[1]()).toEqual({});
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2010-03-15 21:36:50 +00:00
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
it("should read resource", inject(function($httpBackend) {
|
|
|
|
|
$httpBackend.expect('GET', '/CreditCard/123').respond({id: 123, number: '9876'});
|
|
|
|
|
var cc = CreditCard.get({id: 123}, callback);
|
|
|
|
|
|
2010-03-15 21:36:50 +00:00
|
|
|
expect(cc instanceof CreditCard).toBeTruthy();
|
|
|
|
|
nakedExpect(cc).toEqual({});
|
2011-05-31 08:32:54 +00:00
|
|
|
expect(callback).not.toHaveBeenCalled();
|
2011-10-19 17:47:17 +00:00
|
|
|
|
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
nakedExpect(cc).toEqual({id: 123, number: '9876'});
|
2011-12-01 21:20:08 +00:00
|
|
|
expect(callback.mostRecentCall.args[0]).toEqual(cc);
|
|
|
|
|
expect(callback.mostRecentCall.args[1]()).toEqual({});
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2010-03-15 21:36:50 +00:00
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
it("should read partial resource", inject(function($httpBackend) {
|
|
|
|
|
$httpBackend.expect('GET', '/CreditCard').respond([{id:{key:123}}]);
|
2010-09-15 17:27:58 +00:00
|
|
|
var ccs = CreditCard.query();
|
2011-10-19 17:47:17 +00:00
|
|
|
|
|
|
|
|
$httpBackend.flush();
|
2010-09-15 17:27:58 +00:00
|
|
|
expect(ccs.length).toEqual(1);
|
2011-10-19 17:47:17 +00:00
|
|
|
|
2010-09-15 17:27:58 +00:00
|
|
|
var cc = ccs[0];
|
2011-10-19 17:47:17 +00:00
|
|
|
expect(cc instanceof CreditCard).toBe(true);
|
|
|
|
|
expect(cc.number).toBeUndefined();
|
|
|
|
|
|
2011-11-01 20:40:51 +00:00
|
|
|
$httpBackend.expect('GET', '/CreditCard/123').respond({id: {key: 123}, number: '9876'});
|
2010-09-15 17:27:58 +00:00
|
|
|
cc.$get(callback);
|
2011-10-19 17:47:17 +00:00
|
|
|
$httpBackend.flush();
|
2011-12-01 21:20:08 +00:00
|
|
|
expect(callback.mostRecentCall.args[0]).toEqual(cc);
|
|
|
|
|
expect(callback.mostRecentCall.args[1]()).toEqual({});
|
2010-09-15 17:27:58 +00:00
|
|
|
expect(cc.number).toEqual('9876');
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2010-09-15 17:27:58 +00:00
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
it("should update resource", inject(function($httpBackend) {
|
|
|
|
|
$httpBackend.expect('POST', '/CreditCard/123', '{"id":{"key":123},"name":"misko"}').
|
|
|
|
|
respond({id: {key: 123}, name: 'rama'});
|
2010-03-15 21:36:50 +00:00
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
var cc = CreditCard.save({id: {key: 123}, name: 'misko'}, callback);
|
2010-03-15 21:36:50 +00:00
|
|
|
nakedExpect(cc).toEqual({id:{key:123}, name:'misko'});
|
2011-05-31 08:32:54 +00:00
|
|
|
expect(callback).not.toHaveBeenCalled();
|
2011-10-19 17:47:17 +00:00
|
|
|
$httpBackend.flush();
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2010-03-15 21:36:50 +00:00
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
it("should query resource", inject(function($httpBackend) {
|
|
|
|
|
$httpBackend.expect('GET', '/CreditCard?key=value').respond([{id: 1}, {id: 2}]);
|
2010-03-15 21:36:50 +00:00
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
var ccs = CreditCard.query({key: 'value'}, callback);
|
2010-03-15 21:36:50 +00:00
|
|
|
expect(ccs).toEqual([]);
|
2011-05-31 08:32:54 +00:00
|
|
|
expect(callback).not.toHaveBeenCalled();
|
2011-10-19 17:47:17 +00:00
|
|
|
|
|
|
|
|
$httpBackend.flush();
|
2010-03-15 21:36:50 +00:00
|
|
|
nakedExpect(ccs).toEqual([{id:1}, {id:2}]);
|
2011-12-01 21:20:08 +00:00
|
|
|
expect(callback.mostRecentCall.args[0]).toEqual(ccs);
|
|
|
|
|
expect(callback.mostRecentCall.args[1]()).toEqual({});
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2010-03-15 21:36:50 +00:00
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
it("should have all arguments optional", inject(function($httpBackend) {
|
|
|
|
|
$httpBackend.expect('GET', '/CreditCard').respond([{id:1}]);
|
|
|
|
|
|
2010-05-07 19:09:14 +00:00
|
|
|
var log = '';
|
2011-10-07 18:27:49 +00:00
|
|
|
var ccs = CreditCard.query(function() { log += 'cb;'; });
|
2011-10-19 17:47:17 +00:00
|
|
|
|
|
|
|
|
$httpBackend.flush();
|
2010-05-07 19:09:14 +00:00
|
|
|
nakedExpect(ccs).toEqual([{id:1}]);
|
|
|
|
|
expect(log).toEqual('cb;');
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2010-05-07 19:09:14 +00:00
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
it('should delete resource and call callback', inject(function($httpBackend) {
|
|
|
|
|
$httpBackend.expect('DELETE', '/CreditCard/123').respond({});
|
2010-03-15 21:36:50 +00:00
|
|
|
CreditCard.remove({id:123}, callback);
|
2011-05-31 08:32:54 +00:00
|
|
|
expect(callback).not.toHaveBeenCalled();
|
2011-10-19 17:47:17 +00:00
|
|
|
|
|
|
|
|
$httpBackend.flush();
|
2011-12-01 21:20:08 +00:00
|
|
|
nakedExpect(callback.mostRecentCall.args[0]).toEqual({});
|
|
|
|
|
expect(callback.mostRecentCall.args[1]()).toEqual({});
|
2011-04-04 23:04:37 +00:00
|
|
|
|
|
|
|
|
callback.reset();
|
2011-11-01 20:40:51 +00:00
|
|
|
$httpBackend.expect('DELETE', '/CreditCard/333').respond(204, null);
|
2011-04-04 23:04:37 +00:00
|
|
|
CreditCard.remove({id:333}, callback);
|
2011-05-31 08:32:54 +00:00
|
|
|
expect(callback).not.toHaveBeenCalled();
|
2011-10-19 17:47:17 +00:00
|
|
|
|
|
|
|
|
$httpBackend.flush();
|
2011-12-01 21:20:08 +00:00
|
|
|
nakedExpect(callback.mostRecentCall.args[0]).toEqual({});
|
|
|
|
|
expect(callback.mostRecentCall.args[1]()).toEqual({});
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2010-03-15 21:36:50 +00:00
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
it('should post charge verb', inject(function($httpBackend) {
|
|
|
|
|
$httpBackend.expect('POST', '/CreditCard/123!charge?amount=10', '{"auth":"abc"}').respond({success: 'ok'});
|
|
|
|
|
CreditCard.charge({id:123, amount:10}, {auth:'abc'}, callback);
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2010-03-15 21:36:50 +00:00
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
it('should post charge verb on instance', inject(function($httpBackend) {
|
|
|
|
|
$httpBackend.expect('POST', '/CreditCard/123!charge?amount=10',
|
|
|
|
|
'{"id":{"key":123},"name":"misko"}').respond({success: 'ok'});
|
2010-08-10 18:17:08 +00:00
|
|
|
|
|
|
|
|
var card = new CreditCard({id:{key:123}, name:'misko'});
|
|
|
|
|
card.$charge({amount:10}, callback);
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2010-08-10 18:17:08 +00:00
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
it('should create on save', inject(function($httpBackend) {
|
2011-12-01 21:20:08 +00:00
|
|
|
$httpBackend.expect('POST', '/CreditCard', '{"name":"misko"}').respond({id: 123}, {header1: 'a'});
|
2011-10-19 17:47:17 +00:00
|
|
|
|
2010-03-15 21:36:50 +00:00
|
|
|
var cc = new CreditCard();
|
2010-09-15 17:27:58 +00:00
|
|
|
expect(cc.$get).toBeDefined();
|
|
|
|
|
expect(cc.$query).toBeDefined();
|
2010-03-15 21:36:50 +00:00
|
|
|
expect(cc.$remove).toBeDefined();
|
|
|
|
|
expect(cc.$save).toBeDefined();
|
|
|
|
|
|
|
|
|
|
cc.name = 'misko';
|
|
|
|
|
cc.$save(callback);
|
|
|
|
|
nakedExpect(cc).toEqual({name:'misko'});
|
2011-10-19 17:47:17 +00:00
|
|
|
|
|
|
|
|
$httpBackend.flush();
|
2010-03-15 21:36:50 +00:00
|
|
|
nakedExpect(cc).toEqual({id:123});
|
2011-12-01 21:20:08 +00:00
|
|
|
expect(callback.mostRecentCall.args[0]).toEqual(cc);
|
|
|
|
|
expect(callback.mostRecentCall.args[1]()).toEqual({header1: 'a'});
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2010-03-15 21:36:50 +00:00
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
it('should not mutate the resource object if response contains no body', inject(function($httpBackend) {
|
2011-03-22 17:51:48 +00:00
|
|
|
var data = {id:{key:123}, number:'9876'};
|
2011-10-19 17:47:17 +00:00
|
|
|
$httpBackend.expect('GET', '/CreditCard/123').respond(data);
|
|
|
|
|
|
2011-03-22 17:51:48 +00:00
|
|
|
var cc = CreditCard.get({id:123});
|
2011-10-19 17:47:17 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
expect(cc instanceof CreditCard).toBe(true);
|
2011-03-22 17:51:48 +00:00
|
|
|
|
2011-11-01 20:40:51 +00:00
|
|
|
$httpBackend.expect('POST', '/CreditCard/123', toJson(data)).respond('');
|
2011-10-19 17:47:17 +00:00
|
|
|
var idBefore = cc.id;
|
2011-11-01 20:40:51 +00:00
|
|
|
|
2011-03-22 17:51:48 +00:00
|
|
|
cc.$save();
|
2011-10-19 17:47:17 +00:00
|
|
|
$httpBackend.flush();
|
2011-03-22 17:51:48 +00:00
|
|
|
expect(idBefore).toEqual(cc.id);
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2011-03-22 17:51:48 +00:00
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
it('should bind default parameters', inject(function($httpBackend) {
|
|
|
|
|
$httpBackend.expect('GET', '/CreditCard/123.visa?minimum=0.05').respond({id: 123});
|
2010-03-15 22:57:12 +00:00
|
|
|
var Visa = CreditCard.bind({verb:'.visa', minimum:0.05});
|
|
|
|
|
var visa = Visa.get({id:123});
|
2011-10-19 17:47:17 +00:00
|
|
|
$httpBackend.flush();
|
2010-03-15 22:57:12 +00:00
|
|
|
nakedExpect(visa).toEqual({id:123});
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2010-03-15 21:36:50 +00:00
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
it('should excersize full stack', inject(function($httpBackend, $resource) {
|
Introduced injector and $new to scope, and injection into link methods and controllers
- added angular.injector(scope, services, instanceCache) which returns inject
- inject method can return, instance, or call function which have $inject
property
- initialize services with $creation=[eager|eager-publish] this means that
only some of the services are now globally accessible
- upgraded $become on scope to use injector hence respect the $inject property
for injection
- $become should not be run multiple times and will most likely be removed
in future version
- added $new on scope to create a child scope
- $inject is respected on constructor function
- simplified scopes so that they no longer have separate __proto__ for
parent, api, behavior and instance this should speed up execution since
scope will now create one __proto__ chain per scope (not three).
BACKWARD COMPATIBILITY WARNING:
- services now need to have $inject instead of inject property for proper
injection this breaks backward compatibility
- not all services are now published into root scope
(only: $location, $cookie, $window)
- if you have widget/directive which uses services on scope
(such as this.$xhr), you will now have to inject that service in
(as it is not published on the root scope anymore)
2010-10-09 00:30:13 +00:00
|
|
|
var Person = $resource('/Person/:id');
|
2011-10-19 17:47:17 +00:00
|
|
|
|
|
|
|
|
$httpBackend.expect('GET', '/Person/123').respond('\n{\n"name":\n"misko"\n}\n');
|
2010-04-30 00:28:33 +00:00
|
|
|
var person = Person.get({id:123});
|
2011-10-19 17:47:17 +00:00
|
|
|
$httpBackend.flush();
|
2010-04-30 00:28:33 +00:00
|
|
|
expect(person.name).toEqual('misko');
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2010-04-30 00:28:33 +00:00
|
|
|
|
2011-07-22 19:56:45 +00:00
|
|
|
describe('failure mode', function() {
|
|
|
|
|
var ERROR_CODE = 500,
|
2011-08-18 19:07:04 +00:00
|
|
|
ERROR_RESPONSE = 'Server Error',
|
|
|
|
|
errorCB;
|
2011-07-22 19:56:45 +00:00
|
|
|
|
|
|
|
|
beforeEach(function() {
|
2011-11-24 11:53:04 +00:00
|
|
|
errorCB = jasmine.createSpy('error').andCallFake(function(response) {
|
|
|
|
|
expect(response.data).toBe(ERROR_RESPONSE);
|
|
|
|
|
expect(response.status).toBe(ERROR_CODE);
|
2011-10-19 17:47:17 +00:00
|
|
|
});
|
2010-05-19 18:51:17 +00:00
|
|
|
});
|
|
|
|
|
|
2011-11-24 11:53:04 +00:00
|
|
|
it('should call the error callback if provided on non 2xx response',
|
|
|
|
|
inject(function($httpBackend, $rootScope) {
|
2011-10-19 17:47:17 +00:00
|
|
|
$httpBackend.expect('GET', '/CreditCard/123').respond(ERROR_CODE, ERROR_RESPONSE);
|
2011-07-22 19:56:45 +00:00
|
|
|
|
2011-08-18 19:07:04 +00:00
|
|
|
CreditCard.get({id:123}, callback, errorCB);
|
2011-10-19 17:47:17 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
expect(errorCB).toHaveBeenCalledOnce();
|
2011-08-18 19:07:04 +00:00
|
|
|
expect(callback).not.toHaveBeenCalled();
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2011-08-18 19:07:04 +00:00
|
|
|
|
2011-10-19 17:47:17 +00:00
|
|
|
it('should call the error callback if provided on non 2xx response', inject(function($httpBackend) {
|
|
|
|
|
$httpBackend.expect('GET', '/CreditCard').respond(ERROR_CODE, ERROR_RESPONSE);
|
|
|
|
|
|
2011-08-18 19:07:04 +00:00
|
|
|
CreditCard.get(callback, errorCB);
|
2011-10-19 17:47:17 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
expect(errorCB).toHaveBeenCalledOnce();
|
2011-08-18 19:07:04 +00:00
|
|
|
expect(callback).not.toHaveBeenCalled();
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2011-07-22 19:56:45 +00:00
|
|
|
});
|
2010-03-15 21:36:50 +00:00
|
|
|
});
|