angular-hyper-resource icon indicating copy to clipboard operation
angular-hyper-resource copied to clipboard

Collection of embedded resources are not supported

Open intellix opened this issue 9 years ago • 1 comments

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();

    });

  });

intellix avatar Aug 27 '15 19:08 intellix

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.

johndgiese avatar Sep 02 '15 16:09 johndgiese