|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +describe('Style: AMS', function() { |
| 4 | + |
| 5 | + var bike; |
| 6 | + |
| 7 | + beforeEach(module('restmod')); |
| 8 | + |
| 9 | + beforeEach(module(function($provide, restmodProvider) { |
| 10 | + restmodProvider.rebase('AMSApi'); |
| 11 | + $provide.factory('Bike', function(restmod) { |
| 12 | + return restmod.model('/api/bikes', { |
| 13 | + user: { belongsTo: restmod.model('/api/users') } |
| 14 | + }); |
| 15 | + }); |
| 16 | + })); |
| 17 | + |
| 18 | + beforeEach(inject(function(Bike) { |
| 19 | + bike = Bike.$new(); |
| 20 | + })); |
| 21 | + |
| 22 | + it('should properly rename names on decode/encode', function() { |
| 23 | + bike.$decode({ 'rear_wheel': 'crossmax' }); |
| 24 | + |
| 25 | + expect(bike.rearWheel).toBeDefined(); |
| 26 | + expect(bike['rear_wheel']).not.toBeDefined(); |
| 27 | + expect(bike.$encode()['rear_wheel']).toBeDefined(); |
| 28 | + expect(bike.$encode().rearWheel).not.toBeDefined(); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should use "id" as primary key', function() { |
| 32 | + bike.$decode({ id: 1 }); |
| 33 | + expect(bike.$pk).toEqual(1); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should extract metadata from "meta" property', function() { |
| 37 | + bike.$unwrap({ bike: { id: 1 }, meta: { date: '2014-05-01' } }); |
| 38 | + expect(bike.$metadata).toBeDefined(); |
| 39 | + expect(bike.$metadata.date).toBeDefined(); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should extract links from "links" property', function() { |
| 43 | + bike.$unwrap({ bike: { id: 1, 'user_id': 1 }, links: { users: [ { id: 1, name: 'Pancho' } ] } }); |
| 44 | + expect(bike.user).toBeDefined(); |
| 45 | + expect(bike.user.name).toEqual('Pancho'); |
| 46 | + }); |
| 47 | +}); |
0 commit comments