2017-05-29 21:50:03 +03:00
|
|
|
import Pretender from 'pretender';
|
2016-11-24 01:50:57 +03:00
|
|
|
import {describe, it} from 'mocha';
|
2017-05-29 21:50:03 +03:00
|
|
|
import {expect} from 'chai';
|
2016-11-24 01:50:57 +03:00
|
|
|
import {setupTest} from 'ember-mocha';
|
2015-11-24 17:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
describe('Integration: Adapter: user', function () {
|
|
|
|
setupTest('adapter:user', {
|
2015-11-24 17:02:48 +03:00
|
|
|
integration: true
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-11-24 17:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
let server, store;
|
2015-11-24 17:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
beforeEach(function () {
|
|
|
|
store = this.container.lookup('service:store');
|
|
|
|
server = new Pretender();
|
|
|
|
});
|
2015-11-24 17:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
afterEach(function () {
|
|
|
|
server.shutdown();
|
|
|
|
});
|
2015-11-24 17:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('loads users from regular endpoint when all are fetched', function (done) {
|
2018-10-05 21:46:33 +03:00
|
|
|
server.get('/ghost/api/v2/admin/users/', function () {
|
2016-11-24 01:50:57 +03:00
|
|
|
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'
|
|
|
|
}
|
|
|
|
]})];
|
2015-11-24 17:02:48 +03:00
|
|
|
});
|
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
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) {
|
2018-10-05 21:46:33 +03:00
|
|
|
server.get('/ghost/api/v2/admin/users/slug/user-1/', function () {
|
2016-11-24 01:50:57 +03:00
|
|
|
return [200, {'Content-Type': 'application/json'}, JSON.stringify({users: [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
slug: 'user-1',
|
|
|
|
name: 'User 1'
|
|
|
|
}
|
|
|
|
]})];
|
|
|
|
});
|
2015-11-24 17:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
store.queryRecord('user', {slug: 'user-1'}).then((user) => {
|
|
|
|
expect(user).to.be.ok;
|
|
|
|
expect(user.get('name')).to.equal('User 1');
|
|
|
|
done();
|
2015-11-24 17:02:48 +03:00
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-11-24 17:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('handles "include" parameter when querying single user via slug', function (done) {
|
2018-10-05 21:46:33 +03:00
|
|
|
server.get('/ghost/api/v2/admin/users/slug/user-1/', (request) => {
|
2016-11-24 01:50:57 +03:00
|
|
|
let params = request.queryParams;
|
|
|
|
expect(params.include, 'include query').to.equal('roles,count.posts');
|
2015-11-24 17:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
return [200, {'Content-Type': 'application/json'}, JSON.stringify({users: [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
slug: 'user-1',
|
|
|
|
name: 'User 1',
|
|
|
|
count: {
|
|
|
|
posts: 5
|
2015-11-24 17:02:48 +03:00
|
|
|
}
|
2016-11-24 01:50:57 +03:00
|
|
|
}
|
|
|
|
]})];
|
|
|
|
});
|
2015-11-24 17:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
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();
|
2015-11-24 17:02:48 +03:00
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
});
|