From 2b1f784d91ed4bdb8d69a10c8b099e7f9bc33954 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Tue, 24 Nov 2015 14:02:48 +0000 Subject: [PATCH] Add count.posts support to user model on client no issue - moves adapter tests from unit to integration as we are not testing them in isolation - add test for querying user's by slug with `include=count.posts` - add `count` attribute to User model --- core/client/app/models/user.js | 1 + .../tests/integration/adapters/tag-test.js | 63 ++++++++++++++ .../tests/integration/adapters/user-test.js | 86 +++++++++++++++++++ core/client/tests/unit/adapters/tag-test.js | 62 ------------- core/client/tests/unit/adapters/user-test.js | 62 ------------- 5 files changed, 150 insertions(+), 124 deletions(-) create mode 100644 core/client/tests/integration/adapters/tag-test.js create mode 100644 core/client/tests/integration/adapters/user-test.js delete mode 100644 core/client/tests/unit/adapters/tag-test.js delete mode 100644 core/client/tests/unit/adapters/user-test.js diff --git a/core/client/app/models/user.js b/core/client/app/models/user.js index 22d53b1b1e..f81752418a 100644 --- a/core/client/app/models/user.js +++ b/core/client/app/models/user.js @@ -29,6 +29,7 @@ export default DS.Model.extend(ValidationEngine, { embedded: 'always', async: false }), + count: DS.attr('raw'), ghostPaths: Ember.inject.service('ghost-paths'), diff --git a/core/client/tests/integration/adapters/tag-test.js b/core/client/tests/integration/adapters/tag-test.js new file mode 100644 index 0000000000..839cd82e6e --- /dev/null +++ b/core/client/tests/integration/adapters/tag-test.js @@ -0,0 +1,63 @@ +/* jshint expr:true */ +import { expect } from 'chai'; +import { + describeModule, + it +} from 'ember-mocha'; +import Pretender from 'pretender'; + +describeModule( + 'adapter:tag', + 'Integration: Adapter: tag', + { + integration: true + }, + function () { + let server, store; + + beforeEach(function () { + store = this.container.lookup('service:store'); + server = new Pretender(); + }); + + afterEach(function () { + server.shutdown(); + }); + + it('loads tags from regular endpoint when all are fetched', function (done) { + server.get('/ghost/api/v0.1/tags/', function () { + return [200, {'Content-Type': 'application/json'}, JSON.stringify({tags: [{ + id: 1, + name: 'Tag 1', + slug: 'tag-1' + }, { + id: 2, + name: 'Tag 2', + slug: 'tag-2' + }]})]; + }); + + store.findAll('tag', {reload: true}).then((tags) => { + expect(tags).to.be.ok; + expect(tags.objectAtContent(0).get('name')).to.equal('Tag 1'); + done(); + }); + }); + + it('loads tag from slug endpoint when single tag is queried and slug is passed in', function (done) { + server.get('/ghost/api/v0.1/tags/slug/tag-1/', function () { + return [200, {'Content-Type': 'application/json'}, JSON.stringify({tags: [{ + id: 1, + slug: 'tag-1', + name: 'Tag 1' + }]})]; + }); + + store.queryRecord('tag', {slug: 'tag-1'}).then((tag) => { + expect(tag).to.be.ok; + expect(tag.get('name')).to.equal('Tag 1'); + done(); + }); + }); + } +); diff --git a/core/client/tests/integration/adapters/user-test.js b/core/client/tests/integration/adapters/user-test.js new file mode 100644 index 0000000000..b9c2c884ac --- /dev/null +++ b/core/client/tests/integration/adapters/user-test.js @@ -0,0 +1,86 @@ +/* jshint expr:true */ +import { expect } from 'chai'; +import { + describeModule, + it +} from 'ember-mocha'; +import Pretender from 'pretender'; + +describeModule( + 'adapter:user', + 'Integration: Adapter: user', + { + integration: true + }, + function () { + let server, store; + + beforeEach(function () { + store = this.container.lookup('service:store'); + server = new Pretender(); + }); + + afterEach(function () { + server.shutdown(); + }); + + it('loads users from regular endpoint when all are fetched', function (done) { + server.get('/ghost/api/v0.1/users/', function () { + return [200, {'Content-Type': 'application/json'}, JSON.stringify({users: [{ + id: 1, + name: 'User 1', + slug: 'user-1' + }, { + id: 2, + name: 'User 2', + slug: 'user-2' + }]})]; + }); + + store.findAll('user', {reload: true}).then((users) => { + expect(users).to.be.ok; + expect(users.objectAtContent(0).get('name')).to.equal('User 1'); + done(); + }); + }); + + it('loads user from slug endpoint when single user is queried and slug is passed in', function (done) { + server.get('/ghost/api/v0.1/users/slug/user-1/', function () { + return [200, {'Content-Type': 'application/json'}, JSON.stringify({users: [{ + id: 1, + slug: 'user-1', + name: 'User 1' + }]})]; + }); + + store.queryRecord('user', {slug: 'user-1'}).then((user) => { + expect(user).to.be.ok; + expect(user.get('name')).to.equal('User 1'); + done(); + }); + }); + + it('handles "include" parameter when querying single user via slug', function (done) { + server.get('/ghost/api/v0.1/users/slug/user-1/', (request) => { + let params = request.queryParams; + expect(params.include, 'include query').to.equal('roles,count.posts'); + + return [200, {'Content-Type': 'application/json'}, JSON.stringify({users: [{ + id: 1, + slug: 'user-1', + name: 'User 1', + count: { + posts: 5 + } + }]})]; + }); + + store.queryRecord('user', {slug: 'user-1', include: 'count.posts'}).then((user) => { + expect(user).to.be.ok; + expect(user.get('name')).to.equal('User 1'); + expect(user.get('count.posts')).to.equal(5); + done(); + }); + }); + } +); diff --git a/core/client/tests/unit/adapters/tag-test.js b/core/client/tests/unit/adapters/tag-test.js deleted file mode 100644 index ddb13c8ac0..0000000000 --- a/core/client/tests/unit/adapters/tag-test.js +++ /dev/null @@ -1,62 +0,0 @@ -/* jshint expr:true */ -import { expect } from 'chai'; -import { - describeModel, - it -} from 'ember-mocha'; -import Pretender from 'pretender'; - -describeModel('tag', 'Unit: Adapter: tag', { - needs: [ - 'service:ghost-paths', - 'service:session', - 'adapter:tag', - 'serializer:tag' - ] -}, function () { - let server; - - beforeEach(function () { - server = new Pretender(); - }); - - afterEach(function () { - server.shutdown(); - }); - - it('loads tags from regular endpoint when all are fetched', function (done) { - server.get('/ghost/api/v0.1/tags/', function () { - return [200, {'Content-Type': 'application/json'}, JSON.stringify({tags: [{ - id: 1, - name: 'Tag 1', - slug: 'tag-1' - }, { - id: 2, - name: 'Tag 2', - slug: 'tag-2' - }]})]; - }); - - this.store().findAll('tag', {reload: true}).then((tags) => { - expect(tags).to.be.ok; - expect(tags.objectAtContent(0).get('name')).to.equal('Tag 1'); - done(); - }); - }); - - it('loads tag from slug endpoint when single tag is queried and slug is passed in', function (done) { - server.get('/ghost/api/v0.1/tags/slug/tag-1/', function () { - return [200, {'Content-Type': 'application/json'}, JSON.stringify({tags: [{ - id: 1, - slug: 'tag-1', - name: 'Tag 1' - }]})]; - }); - - this.store().queryRecord('tag', {slug: 'tag-1'}).then((tag) => { - expect(tag).to.be.ok; - expect(tag.get('name')).to.equal('Tag 1'); - done(); - }); - }); -}); diff --git a/core/client/tests/unit/adapters/user-test.js b/core/client/tests/unit/adapters/user-test.js deleted file mode 100644 index 0463459fb3..0000000000 --- a/core/client/tests/unit/adapters/user-test.js +++ /dev/null @@ -1,62 +0,0 @@ -/* jshint expr:true */ -import { expect } from 'chai'; -import { - describeModel, - it -} from 'ember-mocha'; -import Pretender from 'pretender'; - -describeModel('user', 'Unit: Adapter: user', { - needs: [ - 'service:ghost-paths', - 'service:session', - 'adapter:user', - 'serializer:user' - ] -}, function () { - let server; - - beforeEach(function () { - server = new Pretender(); - }); - - afterEach(function () { - server.shutdown(); - }); - - it('loads users from regular endpoint when all are fetched', function (done) { - server.get('/ghost/api/v0.1/users/', function () { - return [200, {'Content-Type': 'application/json'}, JSON.stringify({users: [{ - id: 1, - name: 'User 1', - slug: 'user-1' - }, { - id: 2, - name: 'User 2', - slug: 'user-2' - }]})]; - }); - - this.store().findAll('user', {reload: true}).then((users) => { - expect(users).to.be.ok; - expect(users.objectAtContent(0).get('name')).to.equal('User 1'); - done(); - }); - }); - - it('loads user from slug endpoint when single user is queried and slug is passed in', function (done) { - server.get('/ghost/api/v0.1/users/slug/user-1/', function () { - return [200, {'Content-Type': 'application/json'}, JSON.stringify({users: [{ - id: 1, - slug: 'user-1', - name: 'User 1' - }]})]; - }); - - this.store().queryRecord('user', {slug: 'user-1'}).then((user) => { - expect(user).to.be.ok; - expect(user.get('name')).to.equal('User 1'); - done(); - }); - }); -});