mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
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
This commit is contained in:
parent
a156a1ed08
commit
2b1f784d91
5 changed files with 150 additions and 124 deletions
|
@ -29,6 +29,7 @@ export default DS.Model.extend(ValidationEngine, {
|
|||
embedded: 'always',
|
||||
async: false
|
||||
}),
|
||||
count: DS.attr('raw'),
|
||||
|
||||
ghostPaths: Ember.inject.service('ghost-paths'),
|
||||
|
||||
|
|
63
core/client/tests/integration/adapters/tag-test.js
Normal file
63
core/client/tests/integration/adapters/tag-test.js
Normal file
|
@ -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();
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
86
core/client/tests/integration/adapters/user-test.js
Normal file
86
core/client/tests/integration/adapters/user-test.js
Normal file
|
@ -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();
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue