-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1dbcd7f
commit 9679892
Showing
4 changed files
with
146 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const Entries = require("models/entries"); | ||
const Entry = require("models/entry"); | ||
const Blog = require("models/blog"); | ||
const async = require("async"); | ||
|
||
function publishScheduledEntries(callback = function () {}) { | ||
Blog.getAllIDs(function (err, blogIDs) { | ||
if (err) return callback(err); | ||
async.each( | ||
blogIDs, | ||
function (blogID, nextBlog) { | ||
Entries.get(blogID, { lists: ["scheduled"] }, function (err, list) { | ||
if (err) return callback(err); | ||
async.each( | ||
list.scheduled, | ||
function (futureEntry, nextEntry) { | ||
// Saving an update, even an empty one, will ensure the entry model | ||
// schedules a task to rebuild the entry again in future when it's | ||
// time to publish the entry. | ||
Entry.set(blogID, futureEntry.path, {}, nextEntry); | ||
}, | ||
nextBlog | ||
); | ||
}); | ||
}, | ||
callback | ||
); | ||
}); | ||
} | ||
module.exports = publishScheduledEntries; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Enable this test once we can run it in parallel | ||
// it's too slow otherwise | ||
xdescribe("scheduled posts", function () { | ||
const Template = require("models/template"); | ||
const Blog = require("models/blog"); | ||
const sync = require("sync"); | ||
const blogServer = require("blog"); | ||
const fs = require("fs-extra"); | ||
const request = require("request"); | ||
const Express = require("express"); | ||
const config = require("../../config"); | ||
const guid = require("helper").guid; | ||
const moment = require("moment"); | ||
const MINUTE = 60 * 1000; | ||
|
||
global.test.blog(); | ||
|
||
it( | ||
"are published", | ||
function (done) { | ||
const path = "/entry.txt"; | ||
const id = guid(); | ||
sync(this.blog.id, (err, folder, finish) => { | ||
if (err) return callback(err); | ||
const contents = `Date: ${moment() | ||
.utc() | ||
.add(1, "minutes") | ||
.format("YYYY-MM-DD HH:mm")}\n\n${id}`; | ||
setTimeout(() => { | ||
request(this.origin, { strictSSL: false }, (err, res, body) => { | ||
expect(body).toContain(id); | ||
done(); | ||
}); | ||
}, MINUTE); | ||
fs.outputFileSync(this.blogDirectory + path, contents, "utf-8"); | ||
folder.update(path, (err) => { | ||
if (err) return callback(err); | ||
finish(null, () => { | ||
request(this.origin, { strictSSL: false }, (err, res, body) => { | ||
expect(body).not.toContain(id); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}, | ||
MINUTE * 2 | ||
); | ||
|
||
beforeEach(function (done) { | ||
const templateName = "example"; | ||
|
||
const view = { | ||
name: "entries.html", | ||
content: `<html><head></head><body>{{#entries}}{{{html}}}{{/entries}}</body></html>`, | ||
}; | ||
|
||
Template.create(this.blog.id, templateName, {}, (err) => { | ||
if (err) return done(err); | ||
Template.getTemplateList(this.blog.id, (err, templates) => { | ||
let templateId = templates.filter( | ||
({ name }) => name === templateName | ||
)[0].id; | ||
Template.setView(templateId, view, (err) => { | ||
if (err) return done(err); | ||
Blog.set( | ||
this.blog.id, | ||
{ forceSSL: false, template: templateId }, | ||
done | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
// Create a webserver for testing remote files | ||
beforeEach(function (done) { | ||
this.server = Express() | ||
.use((req, res, next) => { | ||
const _get = req.get; | ||
req.get = (arg) => { | ||
if (arg === "host") { | ||
return `${this.blog.handle}.${config.host}`; | ||
} else return _get(arg); | ||
}; | ||
next(); | ||
}) | ||
.use(blogServer) | ||
.listen(8919, done); | ||
this.origin = "http://localhost:" + 8919; | ||
}); | ||
|
||
afterEach(function (done) { | ||
this.server.close(); | ||
done(); | ||
}); | ||
}); |