Skip to content

Commit

Permalink
Do not send RabbitMQ event when updating scheduled article
Browse files Browse the repository at this point in the history
  • Loading branch information
nickskalkin committed Jan 24, 2023
1 parent 83ea71b commit 37b9bcb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/api/apps/articles/model/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,17 @@ export const save = (input, accessToken, options, callback) => {
}

// Handle publishing, unpublishing, published, draft
const publishing =
(modifiedArticle.published && !article.published) ||
(modifiedArticle.scheduled_publish_at && !article.published)
const publishing = modifiedArticle.published && !article.published
const scheduledPublishing =
modifiedArticle.scheduled_publish_at && !article.published
const unPublishing = article.published && !modifiedArticle.published
const hasSlugs =
modifiedArticle.slugs && modifiedArticle.slugs.length > 0

if (publishing) {
return onPublish(modifiedArticle, postPublishCallback(callback))
} else if (scheduledPublishing) {
return onPublish(modifiedArticle, sanitizeAndSave(callback))
} else if (unPublishing) {
return onUnpublish(modifiedArticle, sanitizeAndSave(callback))
} else if (!publishing && !hasSlugs) {
Expand Down Expand Up @@ -227,7 +229,7 @@ export const unqueue = callback => {
weekly_email: false,
daily_email: false,
})
return onPublish(article, postPublishCallback(cb))
return onPublish(article, sanitizeAndSave(cb))
},
(err, results) => {
if (err) {
Expand Down
1 change: 0 additions & 1 deletion src/api/apps/articles/test/model/index/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ describe("Article", () => {
results[0].weekly_email.should.be.false()
results[0].daily_email.should.be.false()

publishStub.callCount.should.eql(1)
done()
})
)))
Expand Down
25 changes: 25 additions & 0 deletions src/api/apps/articles/test/model/index/persistence.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,31 @@ describe("Article Persistence", () => {
)
})

it("doesn't send RabbitMQ event when scheduling publishing", done => {
Article.save(
{
title: "Top Ten Shows",
thumbnail_title: "Ten Shows",
author_id: "5086df098523e60002000018",
scheduled_publish_at: moment("2040-01-01").toDate(),
id: "5086df098523e60002002222",
primary_featured_artist_ids: ["52868347b202a37bb000072a"],
channel_id: "5086df098523e60002000018",
},
"foo",
{},
(err, _) => {
if (err) {
done(err)
}

publishStub.callCount.should.eql(0)

done()
}
)
})

it("doesn't send RabbitMQ event when publishing not editorial article", done => {
Channel.save({ name: "Channel", type: "team" }, (err, channel) => {
if (err) {
Expand Down

0 comments on commit 37b9bcb

Please sign in to comment.