it('can publish a post in the past with force flag', function (done) {
     api.schedules.publishPost({force: true}, {id: 4, context: {client: 'ghost-scheduler'}})
         .then(function (result) {
             result.posts[0].id.should.eql(4);
             result.posts[0].status.should.eql('published');
             done();
         })
         .catch(done);
 });
 it('can publish with tolerance (30seconds in the past)', function (done) {
     api.schedules.publishPost({id: 3, context: {client: 'ghost-scheduler'}})
         .then(function (result) {
             result.posts[0].id.should.eql(3);
             result.posts[0].status.should.eql('published');
             done();
         })
         .catch(done);
 });
 it('client with specific perms has access to publish post', function (done) {
     api.schedules.publishPost({id: 1, context: {client: 'ghost-scheduler'}})
         .then(function (result) {
             result.posts[0].id.should.eql(1);
             result.posts[0].status.should.eql('published');
             done();
         })
         .catch(done);
 });
 it('publish, but status is draft', function (done) {
     api.schedules.publishPost({id: 2, context: {client: 'ghost-scheduler'}})
         .then(function () {
             done(new Error('expected ValidationError'));
         })
         .catch(function (err) {
             should.exist(err);
             (err instanceof errors.NotFoundError).should.eql(true);
             done();
         });
 });
 it('invalid params', function (done) {
     api.schedules.publishPost({id: 'bla', context: {client: 'ghost-scheduler'}})
         .then(function () {
             done(new Error('expected ValidationError'));
         })
         .catch(function (err) {
             should.exist(err);
             (err instanceof errors.ValidationError).should.eql(true);
             done();
         });
 });
 .then(function (result) {
     api.schedules.publishPost({id: 1, context: {user: result[0]}})
         .then(function () {
             done(new Error('expected NoPermissionError'));
         })
         .catch(function (err) {
             should.exist(err);
             (err instanceof errors.NoPermissionError).should.eql(true);
             done();
         });
 })
 it('owner has no access (this is how it is right now!)', function (done) {
     api.schedules.publishPost({id: 2, context: {user: testUtils.users.ids.author}})
         .then(function () {
             done(new Error('expected NoPermissionError'));
         })
         .catch(function (err) {
             should.exist(err);
             (err instanceof errors.NoPermissionError).should.eql(true);
             done();
         });
 });
 it('ghost admin has no access', function (done) {
     api.schedules.publishPost({id: 1, context: {client: 'ghost-admin'}})
         .then(function () {
             done(new Error('expected NoPermissionError'));
         })
         .catch(function (err) {
             should.exist(err);
             (err instanceof errors.NoPermissionError).should.eql(true);
             done();
         });
 });
Example #9
0
 it('publish at a wrong time', function (done) {
     api.schedules.publishPost({id: scope.posts[3].id, context: {client: 'ghost-scheduler'}})
         .then(function () {
             done(new Error('expected ValidationError'));
         })
         .catch(function (err) {
             should.exist(err);
             (err instanceof errors.NotFoundError).should.eql(true);
             done();
         });
 });
Example #10
0
 it('post does not exist', function (done) {
     api.schedules.publishPost({id: ObjectId.generate(), context: {client: 'ghost-scheduler'}})
         .then(function () {
             done(new Error('expected ValidationError'));
         })
         .catch(function (err) {
             should.exist(err);
             (err instanceof errors.NotFoundError).should.eql(true);
             done();
         });
 });
Example #11
0
            it('collision protection', function (done) {
                var originalPostApi = api.posts.edit,
                    postId = scope.posts[0].id, // first post is status=scheduled!
                    requestCanComeIn = false,
                    interval;

                // this request get's blocked
                interval = setInterval(function () {
                    if (requestCanComeIn) {
                        clearInterval(interval);

                        // happens in a transaction, request has to wait until the scheduler api finished
                        return models.Post.edit({title: 'Berlin'}, {id: postId, context: {internal: true}})
                            .then(function (post) {
                                post.id.should.eql(postId);
                                post.get('status').should.eql('published');
                                post.get('title').should.eql('Berlin');
                                done();
                            })
                            .catch(done);
                    }
                }, 500);

                // target post to publish was read already, simulate a client request
                sandbox.stub(api.posts, 'edit', function () {
                    var self = this,
                        args = arguments;

                    requestCanComeIn = true;
                    return Promise.delay(2000)
                        .then(function () {
                            return originalPostApi.apply(self, args);
                        });
                });

                api.schedules.publishPost({id: postId, context: {client: 'ghost-scheduler'}})
                    .then(function (result) {
                        result.posts[0].id.should.eql(postId);
                        result.posts[0].status.should.eql('published');
                        result.posts[0].title.should.eql('title');
                    })
                    .catch(done);
            });