mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
added e2e tests to cover page events
no refs -added e2e tests for sending mentions on various page events
This commit is contained in:
parent
80cec29144
commit
8d76832b07
1 changed files with 160 additions and 2 deletions
|
@ -52,10 +52,10 @@ describe('Mentions Service', function () {
|
|||
describe('Sending Service', function () {
|
||||
describe(`does not send when we expect it to not send`, function () {
|
||||
it('New draft post created', async function () {
|
||||
const publishedPost = {status: 'draft', ...mentionsPost};
|
||||
const draftPost = {status: 'draft', ...mentionsPost};
|
||||
await agent
|
||||
.post('posts/')
|
||||
.body({posts: [publishedPost]})
|
||||
.body({posts: [draftPost]})
|
||||
.expectStatus(201);
|
||||
|
||||
await jobsService.allSettled();
|
||||
|
@ -92,6 +92,20 @@ describe('Mentions Service', function () {
|
|||
assert.equal(mentionMock.isDone(), false);
|
||||
assert.equal(endpointMock.isDone(), false);
|
||||
});
|
||||
|
||||
it('New draft page created', async function () {
|
||||
const draftPage = {status: 'draft', ...mentionsPost};
|
||||
await agent
|
||||
.post('pages/')
|
||||
.body({pages: [draftPage]})
|
||||
.expectStatus(201);
|
||||
|
||||
await jobsService.allSettled();
|
||||
await DomainEvents.allSettled();
|
||||
|
||||
assert.equal(mentionMock.isDone(), false);
|
||||
assert.equal(endpointMock.isDone(), false);
|
||||
});
|
||||
});
|
||||
|
||||
describe(`does send when we expect it to send`, function () {
|
||||
|
@ -196,6 +210,107 @@ describe('Mentions Service', function () {
|
|||
assert.equal(endpointMockTwo.isDone(), true);
|
||||
});
|
||||
|
||||
it('Newly published page (page.published)', async function () {
|
||||
let publishedPage = {status: 'published', ...mentionsPost};
|
||||
await agent
|
||||
.post('pages/')
|
||||
.body({pages: [publishedPage]})
|
||||
.expectStatus(201);
|
||||
|
||||
await jobsService.allSettled();
|
||||
await DomainEvents.allSettled();
|
||||
|
||||
assert.equal(mentionMock.isDone(), true);
|
||||
assert.equal(endpointMock.isDone(), true);
|
||||
});
|
||||
|
||||
it('Edited published page (page.published.edited)', async function () {
|
||||
const publishedPage = {status: 'published', ...mentionsPost};
|
||||
const res = await agent
|
||||
.post('pages/')
|
||||
.body({pages: [publishedPage]})
|
||||
.expectStatus(201);
|
||||
|
||||
await jobsService.allSettled();
|
||||
await DomainEvents.allSettled();
|
||||
|
||||
// while not the point of the test, we should have real links/mentions to start with
|
||||
assert.equal(mentionMock.isDone(), true);
|
||||
assert.equal(endpointMock.isDone(), true);
|
||||
|
||||
nock.cleanAll();
|
||||
|
||||
// reset mocks for mention
|
||||
const mentionMockTwo = nock(mentionUrl.href)
|
||||
.persist()
|
||||
.get('/')
|
||||
.reply(200, targetHtml, {'content-type': 'text/html'});
|
||||
|
||||
const endpointMockTwo = nock(endpointUrl.href)
|
||||
.persist()
|
||||
.post('/')
|
||||
.reply(201);
|
||||
|
||||
const pageId = res.body.pages[0].id;
|
||||
const editedPage = {
|
||||
mobiledoc: markdownToMobiledoc(mentionHtml + 'More content'),
|
||||
updated_at: res.body.pages[0].updated_at
|
||||
};
|
||||
|
||||
await agent.put(`pages/${pageId}/`)
|
||||
.body({pages: [editedPage]})
|
||||
.expectStatus(200);
|
||||
|
||||
await jobsService.allSettled();
|
||||
await DomainEvents.allSettled();
|
||||
|
||||
assert.equal(mentionMockTwo.isDone(), true);
|
||||
assert.equal(endpointMockTwo.isDone(), true);
|
||||
});
|
||||
|
||||
it('Unpublished post (post.unpublished)', async function () {
|
||||
const publishedPage = {status: 'published', ...mentionsPost};
|
||||
const res = await agent
|
||||
.post('pages/')
|
||||
.body({pages: [publishedPage]})
|
||||
.expectStatus(201);
|
||||
|
||||
await jobsService.allSettled();
|
||||
await DomainEvents.allSettled();
|
||||
|
||||
// while not the point of the test, we should have real links/mentions to start with
|
||||
assert.equal(mentionMock.isDone(), true);
|
||||
assert.equal(endpointMock.isDone(), true);
|
||||
|
||||
nock.cleanAll();
|
||||
|
||||
// reset mocks for mention
|
||||
const mentionMockTwo = nock(mentionUrl.href)
|
||||
.persist()
|
||||
.get('/')
|
||||
.reply(200, targetHtml, {'content-type': 'text/html'});
|
||||
const endpointMockTwo = nock(endpointUrl.href)
|
||||
.persist()
|
||||
.post('/')
|
||||
.reply(201);
|
||||
|
||||
const pageId = res.body.pages[0].id;
|
||||
// moving back to draft is how we unpublish
|
||||
const unpublishedPage = {
|
||||
status: 'draft',
|
||||
updated_at: res.body.pages[0].updated_at
|
||||
};
|
||||
await agent.put(`pages/${pageId}/`)
|
||||
.body({pages: [unpublishedPage]})
|
||||
.expectStatus(200);
|
||||
|
||||
await jobsService.allSettled();
|
||||
await DomainEvents.allSettled();
|
||||
|
||||
assert.equal(mentionMockTwo.isDone(), true);
|
||||
assert.equal(endpointMockTwo.isDone(), true);
|
||||
});
|
||||
|
||||
it('Sends for links that got removed from a post', async function () {
|
||||
const publishedPost = {status: 'published', ...mentionsPost};
|
||||
const res = await agent
|
||||
|
@ -239,6 +354,49 @@ describe('Mentions Service', function () {
|
|||
assert.equal(endpointMockTwo.isDone(), true);
|
||||
});
|
||||
|
||||
it('Sends for links that got removed from a page', async function () {
|
||||
const publishedPage = {status: 'published', ...mentionsPost};
|
||||
const res = await agent
|
||||
.post('pages/')
|
||||
.body({pages: [publishedPage]})
|
||||
.expectStatus(201);
|
||||
|
||||
await jobsService.allSettled();
|
||||
await DomainEvents.allSettled();
|
||||
|
||||
// while not the point of the test, we should have real links/mentions to start with
|
||||
assert.equal(mentionMock.isDone(), true);
|
||||
assert.equal(endpointMock.isDone(), true);
|
||||
|
||||
nock.cleanAll();
|
||||
|
||||
// reset mocks for mention
|
||||
const mentionMockTwo = nock(mentionUrl.href)
|
||||
.persist()
|
||||
.get('/')
|
||||
.reply(200, targetHtml, {'content-type': 'text/html'});
|
||||
|
||||
const endpointMockTwo = nock(endpointUrl.href)
|
||||
.persist()
|
||||
.post('/')
|
||||
.reply(201);
|
||||
|
||||
const pageId = res.body.pages[0].id;
|
||||
const editedPage = {
|
||||
mobiledoc: markdownToMobiledoc(`mentions were removed from this post`),
|
||||
updated_at: res.body.pages[0].updated_at
|
||||
};
|
||||
await agent.put(`pages/${pageId}/`)
|
||||
.body({pages: [editedPage]})
|
||||
.expectStatus(200);
|
||||
|
||||
await jobsService.allSettled();
|
||||
await DomainEvents.allSettled();
|
||||
|
||||
assert.equal(mentionMockTwo.isDone(), true);
|
||||
assert.equal(endpointMockTwo.isDone(), true);
|
||||
});
|
||||
|
||||
// there's no special handling for this atm, but could be down the road
|
||||
it('New paid post', async function () {
|
||||
const publishedPost = {status: 'published', visibility: 'paid', ...mentionsPost};
|
||||
|
|
Loading…
Add table
Reference in a new issue