|
|
@@ -6,22 +6,22 @@ var chai = require('chai')
|
|
|
;
|
|
|
chai.use(sinonChai);
|
|
|
|
|
|
-describe('Page', function () {
|
|
|
+describe('Page', () => {
|
|
|
var Page = utils.models.Page,
|
|
|
User = utils.models.User,
|
|
|
conn = utils.mongoose.connection,
|
|
|
createdPages,
|
|
|
createdUsers;
|
|
|
|
|
|
- before(function (done) {
|
|
|
- Promise.resolve().then(function() {
|
|
|
+ before(done => {
|
|
|
+ Promise.resolve().then(() => {
|
|
|
var userFixture = [
|
|
|
{name: 'Anon 0', username: 'anonymous0', email: 'anonymous0@example.com'},
|
|
|
{name: 'Anon 1', username: 'anonymous1', email: 'anonymous1@example.com'}
|
|
|
];
|
|
|
|
|
|
return testDBUtil.generateFixture(conn, 'User', userFixture);
|
|
|
- }).then(function(testUsers) {
|
|
|
+ }).then(testUsers => {
|
|
|
createdUsers = testUsers;
|
|
|
var testUser0 = testUsers[0];
|
|
|
|
|
|
@@ -65,17 +65,17 @@ describe('Page', function () {
|
|
|
];
|
|
|
|
|
|
return testDBUtil.generateFixture(conn, 'Page', fixture)
|
|
|
- .then(function(pages) {
|
|
|
+ .then(pages => {
|
|
|
createdPages = pages;
|
|
|
done();
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('.isPublic', function () {
|
|
|
- context('with a public page', function() {
|
|
|
- it('should return true', function(done) {
|
|
|
- Page.findOne({path: '/grant/public'}, function(err, page) {
|
|
|
+ describe('.isPublic', () => {
|
|
|
+ context('with a public page', () => {
|
|
|
+ it('should return true', done => {
|
|
|
+ Page.findOne({path: '/grant/public'}, (err, page) => {
|
|
|
expect(err).to.be.null;
|
|
|
expect(page.isPublic()).to.be.equal(true);
|
|
|
done();
|
|
|
@@ -83,10 +83,10 @@ describe('Page', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- ['restricted', 'specified', 'owner'].forEach(function(grant) {
|
|
|
+ ['restricted', 'specified', 'owner'].forEach(grant => {
|
|
|
context('with a ' + grant + ' page', function() {
|
|
|
- it('should return false', function(done) {
|
|
|
- Page.findOne({path: '/grant/' + grant}, function(err, page) {
|
|
|
+ it('should return false', done => {
|
|
|
+ Page.findOne({path: '/grant/' + grant}, (err, page) => {
|
|
|
expect(err).to.be.null;
|
|
|
expect(page.isPublic()).to.be.equal(false);
|
|
|
done();
|
|
|
@@ -170,11 +170,11 @@ describe('Page', function () {
|
|
|
|
|
|
describe('.isCreator', function() {
|
|
|
context('with creator', function() {
|
|
|
- it('should return true', function(done) {
|
|
|
- User.findOne({email: 'anonymous0@example.com'}, function(err, user) {
|
|
|
+ it('should return true', done => {
|
|
|
+ User.findOne({email: 'anonymous0@example.com'}, (err, user) => {
|
|
|
if (err) { done(err); }
|
|
|
|
|
|
- Page.findOne({path: '/user/anonymous/memo'}, function(err, page) {
|
|
|
+ Page.findOne({path: '/user/anonymous/memo'}, (err, page) => {
|
|
|
expect(page.isCreator(user)).to.be.equal(true);
|
|
|
done();
|
|
|
})
|
|
|
@@ -183,11 +183,11 @@ describe('Page', function () {
|
|
|
});
|
|
|
|
|
|
context('with non-creator', function() {
|
|
|
- it('should return false', function(done) {
|
|
|
- User.findOne({email: 'anonymous1@example.com'}, function(err, user) {
|
|
|
+ it('should return false', done => {
|
|
|
+ User.findOne({email: 'anonymous1@example.com'}, (err, user) => {
|
|
|
if (err) { done(err); }
|
|
|
|
|
|
- Page.findOne({path: '/user/anonymous/memo'}, function(err, page) {
|
|
|
+ Page.findOne({path: '/user/anonymous/memo'}, (err, page) => {
|
|
|
expect(page.isCreator(user)).to.be.equal(false);
|
|
|
done();
|
|
|
})
|
|
|
@@ -198,11 +198,11 @@ describe('Page', function () {
|
|
|
|
|
|
describe('.isGrantedFor', function() {
|
|
|
context('with a granted user', function() {
|
|
|
- it('should return true', function(done) {
|
|
|
- User.findOne({email: 'anonymous0@example.com'}, function(err, user) {
|
|
|
+ it('should return true', done => {
|
|
|
+ User.findOne({email: 'anonymous0@example.com'}, (err, user) => {
|
|
|
if (err) { done(err); }
|
|
|
|
|
|
- Page.findOne({path: '/user/anonymous/memo'}, function(err, page) {
|
|
|
+ Page.findOne({path: '/user/anonymous/memo'}, (err, page) => {
|
|
|
if (err) { done(err); }
|
|
|
|
|
|
expect(page.isGrantedFor(user)).to.be.equal(true);
|
|
|
@@ -213,11 +213,11 @@ describe('Page', function () {
|
|
|
});
|
|
|
|
|
|
context('with a public page', function() {
|
|
|
- it('should return true', function(done) {
|
|
|
- User.findOne({email: 'anonymous1@example.com'}, function(err, user) {
|
|
|
+ it('should return true', done => {
|
|
|
+ User.findOne({email: 'anonymous1@example.com'}, (err, user) => {
|
|
|
if (err) { done(err); }
|
|
|
|
|
|
- Page.findOne({path: '/grant/public'}, function(err, page) {
|
|
|
+ Page.findOne({path: '/grant/public'}, (err, page) => {
|
|
|
if (err) { done(err); }
|
|
|
|
|
|
expect(page.isGrantedFor(user)).to.be.equal(true);
|
|
|
@@ -228,11 +228,11 @@ describe('Page', function () {
|
|
|
});
|
|
|
|
|
|
context('with a restricted page and an user who has no grant', function() {
|
|
|
- it('should return false', function(done) {
|
|
|
- User.findOne({email: 'anonymous1@example.com'}, function(err, user) {
|
|
|
+ it('should return false', done => {
|
|
|
+ User.findOne({email: 'anonymous1@example.com'}, (err, user) => {
|
|
|
if (err) { done(err); }
|
|
|
|
|
|
- Page.findOne({path: '/grant/restricted'}, function(err, page) {
|
|
|
+ Page.findOne({path: '/grant/restricted'}, (err, page) => {
|
|
|
if (err) { done(err); }
|
|
|
|
|
|
expect(page.isGrantedFor(user)).to.be.equal(false);
|
|
|
@@ -243,21 +243,21 @@ describe('Page', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('Extended field', function () {
|
|
|
- context('Slack Channel.', function() {
|
|
|
- it('should be empty', function(done) {
|
|
|
- Page.findOne({path: '/page/for/extended'}, function(err, page) {
|
|
|
+ describe('Extended field', () => {
|
|
|
+ context('Slack Channel.', () => {
|
|
|
+ it('should be empty', done => {
|
|
|
+ Page.findOne({path: '/page/for/extended'}, (err, page) => {
|
|
|
expect(page.extended.hoge).to.be.equal(1);
|
|
|
expect(page.getSlackChannel()).to.be.equal('');
|
|
|
done();
|
|
|
})
|
|
|
});
|
|
|
|
|
|
- it('set slack channel and should get it and should keep hoge ', function(done) {
|
|
|
- Page.findOne({path: '/page/for/extended'}, function(err, page) {
|
|
|
+ it('set slack channel and should get it and should keep hoge ', done => {
|
|
|
+ Page.findOne({path: '/page/for/extended'}, (err, page) => {
|
|
|
page.updateSlackChannel('slack-channel1')
|
|
|
- .then(function(data) {
|
|
|
- Page.findOne({path: '/page/for/extended'}, function(err, page) {
|
|
|
+ .then(data => {
|
|
|
+ Page.findOne({path: '/page/for/extended'}, (err, page) => {
|
|
|
expect(page.extended.hoge).to.be.equal(1);
|
|
|
expect(page.getSlackChannel()).to.be.equal('slack-channel1');
|
|
|
done();
|
|
|
@@ -269,23 +269,23 @@ describe('Page', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('Normalize path', function () {
|
|
|
+ describe('Normalize path', () => {
|
|
|
context('Normalize', function() {
|
|
|
- it('should start with slash', function(done) {
|
|
|
+ it('should start with slash', done => {
|
|
|
expect(Page.normalizePath('hoge/fuga')).to.equal('/hoge/fuga');
|
|
|
done();
|
|
|
});
|
|
|
|
|
|
- it('should trim spaces of slash', function(done) {
|
|
|
+ it('should trim spaces of slash', done => {
|
|
|
expect(Page.normalizePath('/ hoge / fuga')).to.equal('/hoge/fuga');
|
|
|
done();
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('.findPage', function () {
|
|
|
+ describe('.findPage', () => {
|
|
|
context('findPageById', () => {
|
|
|
- it('should find page', function(done) {
|
|
|
+ it('should find page', done => {
|
|
|
const pageToFind = createdPages[0];
|
|
|
Page.findPageById(pageToFind._id)
|
|
|
.then(pageData => {
|
|
|
@@ -296,7 +296,7 @@ describe('Page', function () {
|
|
|
});
|
|
|
|
|
|
context('findPageByIdAndGrantedUser', function() {
|
|
|
- it('should find page', function(done) {
|
|
|
+ it('should find page', done => {
|
|
|
const pageToFind = createdPages[0];
|
|
|
const grantedUser = createdUsers[0];
|
|
|
Page.findPageByIdAndGrantedUser(pageToFind._id, grantedUser)
|