2016-06-30 13:21:47 +03:00
|
|
|
import run from 'ember-runloop';
|
2016-11-24 01:50:57 +03:00
|
|
|
import {describe, it} from 'mocha';
|
|
|
|
import {setupModelTest} from 'ember-mocha';
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
describe('Unit: Model: user', function () {
|
|
|
|
setupModelTest('user', {
|
2017-03-29 01:22:02 +03:00
|
|
|
needs: [
|
|
|
|
'model:role',
|
|
|
|
'serializer:application',
|
|
|
|
'serializer:user',
|
|
|
|
'service:ajax',
|
|
|
|
'service:ghostPaths',
|
|
|
|
'service:notifications',
|
|
|
|
'service:session'
|
|
|
|
]
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('has a validation type of "user"', function () {
|
|
|
|
let model = this.subject();
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
expect(model.get('validationType')).to.equal('user');
|
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2017-03-08 21:21:35 +03:00
|
|
|
it('isActive/isSuspended properties are correct', function () {
|
2016-11-24 01:50:57 +03:00
|
|
|
let model = this.subject({
|
|
|
|
status: 'active'
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
|
2017-03-08 21:21:35 +03:00
|
|
|
expect(model.get('isActive')).to.be.ok;
|
|
|
|
expect(model.get('isSuspended')).to.not.be.ok;
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
['warn-1', 'warn-2', 'warn-3', 'warn-4', 'locked'].forEach(function (status) {
|
2015-10-14 12:37:57 +03:00
|
|
|
run(() => {
|
2016-11-24 01:50:57 +03:00
|
|
|
model.set('status', status);
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
2017-03-08 21:21:35 +03:00
|
|
|
expect(model.get('isActive')).to.be.ok;
|
|
|
|
expect(model.get('isSuspended')).to.not.be.ok;
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
run(() => {
|
|
|
|
model.set('status', 'inactive');
|
|
|
|
});
|
2017-03-08 21:21:35 +03:00
|
|
|
expect(model.get('isSuspended')).to.be.ok;
|
|
|
|
expect(model.get('isActive')).to.not.be.ok;
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('role property is correct', function () {
|
|
|
|
let model = this.subject();
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
run(() => {
|
|
|
|
let role = this.store().push({data: {id: 1, type: 'role', attributes: {name: 'Author'}}});
|
|
|
|
model.get('roles').pushObject(role);
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
expect(model.get('role.name')).to.equal('Author');
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
run(() => {
|
|
|
|
let role = this.store().push({data: {id: 1, type: 'role', attributes: {name: 'Editor'}}});
|
|
|
|
model.set('role', role);
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
expect(model.get('role.name')).to.equal('Editor');
|
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('isAuthor property is correct', function () {
|
|
|
|
let model = this.subject();
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
run(() => {
|
|
|
|
let role = this.store().push({data: {id: 1, type: 'role', attributes: {name: 'Author'}}});
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('isEditor property is correct', function () {
|
|
|
|
let model = this.subject();
|
|
|
|
|
|
|
|
run(() => {
|
|
|
|
let role = this.store().push({data: {id: 1, type: 'role', attributes: {name: 'Editor'}}});
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('isAdmin property is correct', function () {
|
|
|
|
let model = this.subject();
|
|
|
|
|
|
|
|
run(() => {
|
|
|
|
let role = this.store().push({data: {id: 1, type: 'role', attributes: {name: 'Administrator'}}});
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('isOwner property is correct', function () {
|
|
|
|
let model = this.subject();
|
|
|
|
|
|
|
|
run(() => {
|
|
|
|
let role = this.store().push({data: {id: 1, type: 'role', attributes: {name: 'Owner'}}});
|
|
|
|
model.set('role', role);
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
});
|