diff --git a/dist/jsonapi-datastore.js b/dist/jsonapi-datastore.js index 2ef8d3c..a4c98a7 100644 --- a/dist/jsonapi-datastore.js +++ b/dist/jsonapi-datastore.js @@ -201,6 +201,10 @@ var JsonApiDataStore = (function () { model[key] = rec.attributes[key]; } + if (rec.links) { + model._links = rec.links; + } + if (rec.relationships) { for (key in rec.relationships) { var rel = rec.relationships[key]; @@ -215,7 +219,9 @@ var JsonApiDataStore = (function () { } } if (rel.links) { - console.log("Warning: Links not implemented yet."); + model._links = model._links || {}; + model._links._relationships = model._links._relationships || {}; + model._links._relationships[key] = rel.links; } } } diff --git a/dist/jsonapi-datastore.min.js b/dist/jsonapi-datastore.min.js index c5ee19f..412dcfb 100644 --- a/dist/jsonapi-datastore.min.js +++ b/dist/jsonapi-datastore.min.js @@ -1 +1 @@ -"use strict";function _classCallCheck(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function t(t,i){for(var e=0;e { expect(articles[1].related_article.id).to.eq(1337); }); }); + + context('when given a payload with a link', () => { + var store = new JsonApiDataStore(), + payload = { + data: { + type: 'article', + id: 1337, + links: { + self: 'https://example.com/articles/1337' + } + } + }; + + it('should set the links', () => { + var article = store.sync(payload); + expect(article._links.self).to.eq('https://example.com/articles/1337'); + }); + }); + + context('when given a payload with relationships containing links', () => { + var store = new JsonApiDataStore(), + payload = { + data: { + type: 'article', + id: 1337, + relationships: { + author: { + data: { + type: 'user', + id: 1 + }, + links: { + self: 'http://example.com/articles/1337/relationships/user', + related: 'http://example.com/articles/1337/user' + }, + } + } + } + }; + + it('should set the relationship links', () => { + var article = store.sync(payload); + expect(article._links._relationships.author.self).to.eq('http://example.com/articles/1337/relationships/user'); + expect(article._links._relationships.author.related).to.eq('http://example.com/articles/1337/user'); + }); + }); + + context('when given a payload with links and relationships containing links', () => { + var store = new JsonApiDataStore(), + payload = { + data: { + type: 'article', + id: 1337, + links: { + self: 'https://example.com/articles/1337' + }, + relationships: { + author: { + data: { + type: 'user', + id: 1 + }, + links: { + self: 'http://example.com/articles/1337/relationships/user', + related: 'http://example.com/articles/1337/user' + }, + } + } + } + }; + + it('should set the links', () => { + var article = store.sync(payload); + expect(article._links.self).to.eq('https://example.com/articles/1337'); + }); + + it('should set the relationship links', () => { + var article = store.sync(payload); + expect(article._links._relationships.author.self).to.eq('http://example.com/articles/1337/relationships/user'); + expect(article._links._relationships.author.related).to.eq('http://example.com/articles/1337/user'); + }); + }); }); describe('.syncWithMeta()', () => {