linagora-rse
Version:
104 lines (84 loc) • 2.85 kB
JavaScript
;
const mockery = require('mockery');
const q = require('q');
const expect = require('chai').expect;
describe('The webserver user denormalizer', function() {
describe('The denormalize function', function() {
beforeEach(function() {
mockery.registerMock('../../core/user/denormalize', {
denormalize(user) {
return user;
}
});
mockery.registerMock('../../core/esn-config', {
getConfigsForUser: function() {
return q({modules: []});
}
});
});
it('should set the following flag if user is not the current one and is following', function(done) {
const user = {_id: this.helpers.objectIdMock('1'), login: {}};
mockery.registerMock('../../core/user/follow', {
isFollowedBy: function() {
return q(true);
},
getUserStats: function() {
return q({});
}
});
mockery.registerMock('../../core/platformadmin', {
isPlatformAdmin: function() {
return q(false);
}
});
const module = this.helpers.requireBackend('webserver/denormalize/user');
module.denormalize(user, {user: {_id: this.helpers.objectIdMock('2')}, includeIsFollowing: true}).then(function(result) {
expect(result.following).to.be.true;
done();
}).catch(done);
});
it('should set the follow statistics', function() {
const followStats = {
followers: 1,
followgins: 2
};
const user = {login: {}};
mockery.registerMock('../../core/user/follow', {
isFollowedBy: function() {
return q(true);
},
getUserStats: function() {
return q(followStats);
}
});
mockery.registerMock('../../core/platformadmin', {
isPlatformAdmin: function() {
return q(false);
}
});
const module = this.helpers.requireBackend('webserver/denormalize/user');
module.denormalize(user, {}).then(function(result) {
expect(result).to.shallowDeepEqual(followStats);
});
});
it('should set isPlatformAdmin to check if user is platform admin', function(done) {
const isPlatformAdmin = true;
const user = { login: {} };
mockery.registerMock('../../core/user/follow', {
getUserStats: function() {
return q({});
}
});
mockery.registerMock('../../core/platformadmin', {
isPlatformAdmin: function() {
return q(isPlatformAdmin);
}
});
const module = this.helpers.requireBackend('webserver/denormalize/user');
module.denormalize(user, {includeIsPlatformAdmin: true}).then(function(result) {
expect(result.isPlatformAdmin).to.equal(isPlatformAdmin);
done();
}).catch(done);
});
});
});