Ghost/ghost/admin/tests/unit/models/user-test.js

142 lines
4.7 KiB
JavaScript
Raw Normal View History

2015-02-18 23:29:30 +03:00
import Ember from 'ember';
2015-02-18 23:02:48 +03:00
import {
describeModel,
it
} from 'ember-mocha';
const {run} = Ember;
describeModel(
'user',
'Unit: Model: user',
2015-02-18 23:02:48 +03:00
{
2015-11-30 21:23:47 +03:00
needs: ['model:role', 'serializer:application', 'serializer:user']
2015-02-18 23:02:48 +03:00
},
function () {
it('has a validation type of "user"', function () {
let model = this.subject();
2015-02-18 23:02:48 +03:00
expect(model.get('validationType')).to.equal('user');
});
it('active property is correct', function () {
let model = this.subject({
2015-02-18 23:02:48 +03:00
status: 'active'
});
expect(model.get('active')).to.be.ok;
['warn-1', 'warn-2', 'warn-3', 'warn-4', 'locked'].forEach(function (status) {
run(() => { model.set('status', status); });
expect(model.get('status')).to.be.ok;
2015-02-18 23:02:48 +03:00
});
run(() => { model.set('status', 'inactive'); });
expect(model.get('active')).to.not.be.ok;
2015-02-18 23:02:48 +03:00
run(() => { model.set('status', 'invited'); });
expect(model.get('active')).to.not.be.ok;
2015-02-18 23:02:48 +03:00
});
it('invited property is correct', function () {
let model = this.subject({
2015-02-18 23:02:48 +03:00
status: 'invited'
});
expect(model.get('invited')).to.be.ok;
run(() => { model.set('status', 'invited-pending'); });
expect(model.get('invited')).to.be.ok;
2015-02-18 23:02:48 +03:00
run(() => { model.set('status', 'active'); });
expect(model.get('invited')).to.not.be.ok;
2015-02-18 23:02:48 +03:00
run(() => { model.set('status', 'inactive'); });
expect(model.get('invited')).to.not.be.ok;
2015-02-18 23:02:48 +03:00
});
it('pending property is correct', function () {
let model = this.subject({
2015-02-18 23:02:48 +03:00
status: 'invited-pending'
});
expect(model.get('pending')).to.be.ok;
run(() => { model.set('status', 'invited'); });
expect(model.get('pending')).to.not.be.ok;
2015-02-18 23:02:48 +03:00
run(() => { model.set('status', 'inactive'); });
expect(model.get('pending')).to.not.be.ok;
2015-02-18 23:02:48 +03:00
});
it('role property is correct', function () {
let model = this.subject();
2015-02-18 23:02:48 +03:00
run(() => {
let role = this.store().push({data: {id: 1, type: 'role', attributes: {name: 'Author'}}});
2015-02-18 23:02:48 +03:00
model.get('roles').pushObject(role);
});
expect(model.get('role.name')).to.equal('Author');
2015-02-18 23:02:48 +03:00
run(() => {
let role = this.store().push({data: {id: 1, type: 'role', attributes: {name: 'Editor'}}});
2015-02-18 23:02:48 +03:00
model.set('role', role);
});
expect(model.get('role.name')).to.equal('Editor');
2015-02-18 23:02:48 +03:00
});
it('isAuthor property is correct', function () {
let model = this.subject();
2015-02-18 23:02:48 +03:00
run(() => {
let role = this.store().push({data: {id: 1, type: 'role', attributes: {name: 'Author'}}});
2015-02-18 23:02:48 +03:00
model.set('role', role);
});
expect(model.get('isAuthor')).to.be.ok;
expect(model.get('isEditor')).to.not.be.ok;
expect(model.get('isAdmin')).to.not.be.ok;
expect(model.get('isOwner')).to.not.be.ok;
2015-02-18 23:02:48 +03:00
});
it('isEditor property is correct', function () {
let model = this.subject();
2015-02-18 23:02:48 +03:00
run(() => {
let role = this.store().push({data: {id: 1, type: 'role', attributes: {name: 'Editor'}}});
2015-02-18 23:02:48 +03:00
model.set('role', role);
});
expect(model.get('isEditor')).to.be.ok;
expect(model.get('isAuthor')).to.not.be.ok;
expect(model.get('isAdmin')).to.not.be.ok;
expect(model.get('isOwner')).to.not.be.ok;
2015-02-18 23:02:48 +03:00
});
it('isAdmin property is correct', function () {
let model = this.subject();
2015-02-18 23:02:48 +03:00
run(() => {
let role = this.store().push({data: {id: 1, type: 'role', attributes: {name: 'Administrator'}}});
2015-02-18 23:02:48 +03:00
model.set('role', role);
});
expect(model.get('isAdmin')).to.be.ok;
expect(model.get('isAuthor')).to.not.be.ok;
expect(model.get('isEditor')).to.not.be.ok;
expect(model.get('isOwner')).to.not.be.ok;
2015-02-18 23:02:48 +03:00
});
it('isOwner property is correct', function () {
let model = this.subject();
2015-02-18 23:02:48 +03:00
run(() => {
let role = this.store().push({data: {id: 1, type: 'role', attributes: {name: 'Owner'}}});
2015-02-18 23:02:48 +03:00
model.set('role', role);
});
expect(model.get('isOwner')).to.be.ok;
expect(model.get('isAuthor')).to.not.be.ok;
expect(model.get('isAdmin')).to.not.be.ok;
expect(model.get('isEditor')).to.not.be.ok;
2015-02-18 23:02:48 +03:00
});
}
);