angular-hyper-resource
angular-hyper-resource copied to clipboard
Collection of embedded resources are not supported
In your list of examples, you specify that it's possible to do something like: books.query()
but am not seeing the support if you return an actual collection of embedded entities:
The following test fails with Error: [$resource:badcfg] Error in resource configuration. Expected response to contain an array but got an object
:
describe('collections:', function() {
var Book;
beforeEach(function() {
Book = hResource('book', '/books/:id', {id: '@id'});
});
it('returns an array of entities embedded within a collection', function() {
var response = {
_embedded: {
books: [
{
id: 1,
title: 'The BFG'
},
{
id: 2,
title: 'Matilda'
},
{
id: 3,
title: 'James and the Giant Peach'
},
]
},
_links: {
self: {
href: '/books'
}
},
count: 3,
total: 10
};
$httpBackend.expectGET('/books').respond(200, response);
var books = Book.query();
$httpBackend.flush();
expect(books).toBeArray();
});
});
I apologize, but I have been really busy for the last couple weeks. Will try to look at this next week.
On Aug 27, 2015, at 2:27 PM, Dominic Watson [email protected] wrote:
In your list of examples, you specify that it's possible to do something like: books.query() but am not seeing the support if you return an actual collection of embedded entities:
The following test fails with Error: [$resource:badcfg] Error in resource configuration. Expected response to contain an array but got an object:
describe('collections:', function() {
var Book; beforeEach(function() { Book = hResource('book', '/books/:id', {id: '@id'}); }); it('returns an array of entities embedded within a collection', function() { var response = { _embedded: { books: [ { id: 1, title: 'The BFG' }, { id: 2, title: 'Matilda' }, { id: 3, title: 'James and the Giant Peach' }, ] }, _links: { self: { href: '/books' } }, count: 3, total: 10 }; $httpBackend.expectGET('/books').respond(200, response); var books = Book.query(); $httpBackend.flush(); expect(books).toBeArray(); });
}); — Reply to this email directly or view it on GitHub.