|
|
@@ -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) {
|
|
|
- context('with a ' + grant + ' page', function() {
|
|
|
- it('should return false', function(done) {
|
|
|
- Page.findOne({path: '/grant/' + grant}, function(err, page) {
|
|
|
+ ['restricted', 'specified', 'owner'].forEach(grant => {
|
|
|
+ context('with a ' + grant + ' 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();
|
|
|
@@ -96,22 +96,22 @@ describe('Page', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('.getDeletedPageName', function() {
|
|
|
- it('should return trash page name', function() {
|
|
|
+ describe('.getDeletedPageName', () => {
|
|
|
+ it('should return trash page name', () => {
|
|
|
expect(Page.getDeletedPageName('/hoge')).to.be.equal('/trash/hoge');
|
|
|
expect(Page.getDeletedPageName('hoge')).to.be.equal('/trash/hoge');
|
|
|
});
|
|
|
});
|
|
|
- describe('.getRevertDeletedPageName', function() {
|
|
|
- it('should return reverted trash page name', function() {
|
|
|
+ describe('.getRevertDeletedPageName', () => {
|
|
|
+ it('should return reverted trash page name', () => {
|
|
|
expect(Page.getRevertDeletedPageName('/hoge')).to.be.equal('/hoge');
|
|
|
expect(Page.getRevertDeletedPageName('/trash/hoge')).to.be.equal('/hoge');
|
|
|
expect(Page.getRevertDeletedPageName('/trash/hoge/trash')).to.be.equal('/hoge/trash');
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('.isDeletableName', function() {
|
|
|
- it('should decide deletable or not', function() {
|
|
|
+ describe('.isDeletableName', () => {
|
|
|
+ it('should decide deletable or not', () => {
|
|
|
expect(Page.isDeletableName('/hoge')).to.be.true;
|
|
|
expect(Page.isDeletableName('/user/xxx')).to.be.false;
|
|
|
expect(Page.isDeletableName('/user/xxx123')).to.be.false;
|
|
|
@@ -120,8 +120,8 @@ describe('Page', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('.isCreatableName', function() {
|
|
|
- it('should decide creatable or not', function() {
|
|
|
+ describe('.isCreatableName', () => {
|
|
|
+ it('should decide creatable or not', () => {
|
|
|
expect(Page.isCreatableName('/hoge')).to.be.true;
|
|
|
|
|
|
// edge cases
|
|
|
@@ -168,13 +168,13 @@ 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) {
|
|
|
+ describe('.isCreator', () => {
|
|
|
+ context('with creator', () => {
|
|
|
+ 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();
|
|
|
})
|
|
|
@@ -182,12 +182,12 @@ describe('Page', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- context('with non-creator', function() {
|
|
|
- it('should return false', function(done) {
|
|
|
- User.findOne({email: 'anonymous1@example.com'}, function(err, user) {
|
|
|
+ context('with non-creator', () => {
|
|
|
+ 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();
|
|
|
})
|
|
|
@@ -196,13 +196,13 @@ 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) {
|
|
|
+ describe('.isGrantedFor', () => {
|
|
|
+ context('with a granted 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);
|
|
|
@@ -212,12 +212,12 @@ describe('Page', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- context('with a public page', function() {
|
|
|
- it('should return true', function(done) {
|
|
|
- User.findOne({email: 'anonymous1@example.com'}, function(err, user) {
|
|
|
+ context('with a public page', () => {
|
|
|
+ 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);
|
|
|
@@ -227,12 +227,12 @@ 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) {
|
|
|
+ context('with a restricted page and an user who has no grant', () => {
|
|
|
+ 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 () {
|
|
|
- context('Normalize', function() {
|
|
|
- it('should start with slash', function(done) {
|
|
|
+ describe('Normalize path', () => {
|
|
|
+ context('Normalize', () => {
|
|
|
+ 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 => {
|
|
|
@@ -295,8 +295,8 @@ describe('Page', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- context('findPageByIdAndGrantedUser', function() {
|
|
|
- it('should find page', function(done) {
|
|
|
+ context('findPageByIdAndGrantedUser', () => {
|
|
|
+ it('should find page', done => {
|
|
|
const pageToFind = createdPages[0];
|
|
|
const grantedUser = createdUsers[0];
|
|
|
Page.findPageByIdAndGrantedUser(pageToFind._id, grantedUser)
|
|
|
@@ -311,6 +311,7 @@ describe('Page', function () {
|
|
|
const grantedUser = createdUsers[1];
|
|
|
Page.findPageByIdAndGrantedUser(pageToFind._id, grantedUser)
|
|
|
.then(pageData => {
|
|
|
+ done(new Error());
|
|
|
}).catch(err => {
|
|
|
expect(err).to.instanceof(Error);
|
|
|
done();
|