2023-02-03 19:45:50 +03:00
|
|
|
const {agentProvider, fixtureManager, mockManager} = require('../../utils/e2e-framework');
|
|
|
|
const nock = require('nock');
|
2023-06-21 11:56:59 +03:00
|
|
|
const assert = require('assert/strict');
|
2023-02-03 19:45:50 +03:00
|
|
|
const markdownToMobiledoc = require('../../utils/fixtures/data-generator').markdownToMobiledoc;
|
2023-02-17 15:05:36 +03:00
|
|
|
const jobsService = require('../../../core/server/services/mentions-jobs');
|
2023-02-03 19:45:50 +03:00
|
|
|
|
|
|
|
let agent;
|
|
|
|
let mentionUrl = new URL('https://www.otherghostsite.com/');
|
2023-09-21 17:17:05 +03:00
|
|
|
let mentionUrl2 = new URL('https://www.otherghostsite2.com/');
|
2023-02-03 19:45:50 +03:00
|
|
|
let mentionHtml = `Check out this really cool <a href="${mentionUrl.href}">other site</a>.`;
|
2023-09-21 17:17:05 +03:00
|
|
|
let mentionHtml2 = `Check out this really cool <a href="${mentionUrl2.href}">other site</a>.`;
|
2023-02-03 19:45:50 +03:00
|
|
|
let endpointUrl = new URL('https://www.endpoint.com/');
|
2023-09-21 17:17:05 +03:00
|
|
|
let endpointUrl2 = new URL('https://www.endpoint2.com/');
|
2023-02-03 19:45:50 +03:00
|
|
|
let targetHtml = `<head><link rel="webmention" href="${endpointUrl.href}"</head><body>Some content</body>`;
|
2023-09-21 17:17:05 +03:00
|
|
|
let targetHtml2 = `<head><link rel="webmention" href="${endpointUrl2.href}"</head><body>Some content</body>`;
|
2023-02-03 19:45:50 +03:00
|
|
|
let mentionMock;
|
|
|
|
let endpointMock;
|
2023-02-22 20:15:53 +03:00
|
|
|
const DomainEvents = require('@tryghost/domain-events');
|
2023-02-03 19:45:50 +03:00
|
|
|
|
|
|
|
const mentionsPost = {
|
|
|
|
title: 'testing sending webmentions',
|
|
|
|
mobiledoc: markdownToMobiledoc(mentionHtml)
|
|
|
|
};
|
|
|
|
|
2023-09-21 17:17:05 +03:00
|
|
|
const editedMentionsPost = {
|
|
|
|
title: 'testing sending webmentions',
|
|
|
|
mobiledoc: markdownToMobiledoc(mentionHtml2)
|
|
|
|
};
|
|
|
|
|
|
|
|
function addMentionMocks() {
|
|
|
|
// mock response from website mentioned by post to provide endpoint
|
|
|
|
mentionMock = nock(mentionUrl.href)
|
|
|
|
.persist()
|
|
|
|
.get('/')
|
|
|
|
.reply(200, targetHtml, {'content-type': 'text/html'});
|
|
|
|
|
|
|
|
// mock response from mention endpoint, usually 201, sometimes 202
|
|
|
|
endpointMock = nock(endpointUrl.href)
|
|
|
|
.persist()
|
|
|
|
.post('/')
|
|
|
|
.reply(201);
|
|
|
|
}
|
|
|
|
|
2023-02-03 19:45:50 +03:00
|
|
|
describe('Mentions Service', function () {
|
|
|
|
before(async function () {
|
|
|
|
agent = await agentProvider.getAdminAPIAgent();
|
|
|
|
await fixtureManager.init('users');
|
|
|
|
await agent.loginAsAdmin();
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(async function () {
|
|
|
|
// externalRequest does dns lookup; stub to make sure we don't fail with fake domain names
|
2023-03-07 15:20:28 +03:00
|
|
|
mockManager.disableNetwork();
|
2023-02-03 19:45:50 +03:00
|
|
|
|
|
|
|
// mock response from website mentioned by post to provide endpoint
|
2023-09-21 17:17:05 +03:00
|
|
|
addMentionMocks();
|
2023-02-22 20:15:53 +03:00
|
|
|
|
|
|
|
await jobsService.allSettled();
|
|
|
|
await DomainEvents.allSettled();
|
2023-02-03 19:45:50 +03:00
|
|
|
});
|
|
|
|
|
2023-02-09 01:29:12 +03:00
|
|
|
afterEach(async function () {
|
2023-02-03 19:45:50 +03:00
|
|
|
mockManager.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Sending Service', function () {
|
|
|
|
describe(`does not send when we expect it to not send`, function () {
|
|
|
|
it('New draft post created', async function () {
|
2023-03-11 00:25:10 +03:00
|
|
|
const draftPost = {status: 'draft', ...mentionsPost};
|
2023-02-03 19:45:50 +03:00
|
|
|
await agent
|
|
|
|
.post('posts/')
|
2023-03-11 00:25:10 +03:00
|
|
|
.body({posts: [draftPost]})
|
2023-02-03 19:45:50 +03:00
|
|
|
.expectStatus(201);
|
|
|
|
|
2023-02-22 20:15:53 +03:00
|
|
|
await jobsService.allSettled();
|
|
|
|
await DomainEvents.allSettled();
|
|
|
|
|
2023-02-03 19:45:50 +03:00
|
|
|
assert.equal(mentionMock.isDone(), false);
|
|
|
|
assert.equal(endpointMock.isDone(), false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Email only post published', async function () {
|
2023-02-22 20:15:53 +03:00
|
|
|
const publishedPost = {status: 'published', email_only: true, ...mentionsPost};
|
2023-02-03 19:45:50 +03:00
|
|
|
await agent
|
|
|
|
.post('posts/')
|
|
|
|
.body({posts: [publishedPost]})
|
|
|
|
.expectStatus(201);
|
|
|
|
|
2023-02-22 20:15:53 +03:00
|
|
|
await jobsService.allSettled();
|
|
|
|
await DomainEvents.allSettled();
|
|
|
|
|
2023-02-03 19:45:50 +03:00
|
|
|
assert.equal(mentionMock.isDone(), false);
|
|
|
|
assert.equal(endpointMock.isDone(), false);
|
|
|
|
});
|
2023-02-16 20:07:04 +03:00
|
|
|
|
|
|
|
it('Post without content', async function () {
|
2023-02-22 20:15:53 +03:00
|
|
|
const publishedPost = {status: 'published', mobiledoc: markdownToMobiledoc(''), title: 'empty post'};
|
2023-02-16 20:07:04 +03:00
|
|
|
await agent
|
|
|
|
.post('posts/')
|
|
|
|
.body({posts: [publishedPost]})
|
|
|
|
.expectStatus(201);
|
|
|
|
|
2023-02-22 20:15:53 +03:00
|
|
|
await jobsService.allSettled();
|
|
|
|
await DomainEvents.allSettled();
|
|
|
|
|
2023-02-16 20:07:04 +03:00
|
|
|
assert.equal(mentionMock.isDone(), false);
|
|
|
|
assert.equal(endpointMock.isDone(), false);
|
|
|
|
});
|
2023-03-11 00:25:10 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
2023-02-03 19:45:50 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe(`does send when we expect it to send`, function () {
|
|
|
|
it('Newly published post (post.published)', async function () {
|
|
|
|
let publishedPost = {status: 'published', ...mentionsPost};
|
|
|
|
await agent
|
|
|
|
.post('posts/')
|
|
|
|
.body({posts: [publishedPost]})
|
|
|
|
.expectStatus(201);
|
|
|
|
|
2023-02-22 20:15:53 +03:00
|
|
|
await jobsService.allSettled();
|
|
|
|
await DomainEvents.allSettled();
|
2023-02-03 19:45:50 +03:00
|
|
|
|
|
|
|
assert.equal(mentionMock.isDone(), true);
|
|
|
|
assert.equal(endpointMock.isDone(), true);
|
|
|
|
});
|
|
|
|
|
2023-09-21 17:17:05 +03:00
|
|
|
it('Does not send for edited post without url changes (post.published.edited)', async function () {
|
|
|
|
const publishedPost = {status: 'published', ...mentionsPost};
|
|
|
|
const res = await agent
|
|
|
|
.post('posts/')
|
|
|
|
.body({posts: [publishedPost]})
|
|
|
|
.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();
|
|
|
|
addMentionMocks();
|
|
|
|
assert.equal(mentionMock.isDone(), false, 'should be reset');
|
|
|
|
assert.equal(endpointMock.isDone(), false, 'should be reset');
|
|
|
|
|
|
|
|
const postId = res.body.posts[0].id;
|
|
|
|
const editedPost = {
|
|
|
|
mobiledoc: markdownToMobiledoc(mentionHtml + 'More content'),
|
|
|
|
updated_at: res.body.posts[0].updated_at
|
|
|
|
};
|
|
|
|
|
|
|
|
await agent.put(`posts/${postId}/`)
|
|
|
|
.body({posts: [editedPost]})
|
|
|
|
.expectStatus(200);
|
|
|
|
|
|
|
|
await jobsService.allSettled();
|
|
|
|
await DomainEvents.allSettled();
|
|
|
|
|
|
|
|
assert.equal(mentionMock.isDone(), false);
|
|
|
|
assert.equal(endpointMock.isDone(), false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Does send for edited post with url changes (post.published.edited)', async function () {
|
2023-02-22 20:15:53 +03:00
|
|
|
const publishedPost = {status: 'published', ...mentionsPost};
|
|
|
|
const res = await agent
|
2023-02-03 19:45:50 +03:00
|
|
|
.post('posts/')
|
|
|
|
.body({posts: [publishedPost]})
|
|
|
|
.expectStatus(201);
|
|
|
|
|
2023-02-22 20:15:53 +03:00
|
|
|
await jobsService.allSettled();
|
|
|
|
await DomainEvents.allSettled();
|
2023-02-03 19:45:50 +03:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2023-02-22 20:15:53 +03:00
|
|
|
nock.cleanAll();
|
2023-09-21 17:17:05 +03:00
|
|
|
addMentionMocks();
|
|
|
|
assert.equal(mentionMock.isDone(), false, 'should be reset');
|
|
|
|
assert.equal(endpointMock.isDone(), false, 'should be reset');
|
2023-02-22 20:15:53 +03:00
|
|
|
|
2023-02-03 19:45:50 +03:00
|
|
|
// reset mocks for mention
|
2023-09-21 17:17:05 +03:00
|
|
|
const mentionMockTwo = nock(mentionUrl2.href)
|
2023-02-22 20:15:53 +03:00
|
|
|
.persist()
|
2023-02-03 19:45:50 +03:00
|
|
|
.get('/')
|
2023-09-21 17:17:05 +03:00
|
|
|
.reply(200, targetHtml2, {'content-type': 'text/html'});
|
2023-02-22 20:15:53 +03:00
|
|
|
|
2023-09-21 17:17:05 +03:00
|
|
|
const endpointMockTwo = nock(endpointUrl2.href)
|
2023-02-22 20:15:53 +03:00
|
|
|
.persist()
|
2023-02-03 19:45:50 +03:00
|
|
|
.post('/')
|
|
|
|
.reply(201);
|
|
|
|
|
2023-02-22 20:15:53 +03:00
|
|
|
const postId = res.body.posts[0].id;
|
|
|
|
const editedPost = {
|
2023-09-21 17:17:05 +03:00
|
|
|
...editedMentionsPost,
|
2023-02-03 19:45:50 +03:00
|
|
|
updated_at: res.body.posts[0].updated_at
|
|
|
|
};
|
|
|
|
|
|
|
|
await agent.put(`posts/${postId}/`)
|
|
|
|
.body({posts: [editedPost]})
|
|
|
|
.expectStatus(200);
|
|
|
|
|
2023-02-22 20:15:53 +03:00
|
|
|
await jobsService.allSettled();
|
|
|
|
await DomainEvents.allSettled();
|
2023-02-03 19:45:50 +03:00
|
|
|
|
|
|
|
assert.equal(mentionMockTwo.isDone(), true);
|
|
|
|
assert.equal(endpointMockTwo.isDone(), true);
|
2023-09-21 17:17:05 +03:00
|
|
|
|
|
|
|
// Also send again to the deleted url
|
|
|
|
assert.equal(mentionMock.isDone(), true);
|
|
|
|
assert.equal(endpointMock.isDone(), true);
|
2023-02-03 19:45:50 +03:00
|
|
|
});
|
2023-02-22 20:15:53 +03:00
|
|
|
|
2023-02-03 19:45:50 +03:00
|
|
|
it('Unpublished post (post.unpublished)', async function () {
|
2023-02-22 20:15:53 +03:00
|
|
|
const publishedPost = {status: 'published', ...mentionsPost};
|
|
|
|
const res = await agent
|
2023-02-03 19:45:50 +03:00
|
|
|
.post('posts/')
|
|
|
|
.body({posts: [publishedPost]})
|
|
|
|
.expectStatus(201);
|
|
|
|
|
2023-02-22 20:15:53 +03:00
|
|
|
await jobsService.allSettled();
|
|
|
|
await DomainEvents.allSettled();
|
2023-02-03 19:45:50 +03:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2023-02-22 20:15:53 +03:00
|
|
|
nock.cleanAll();
|
|
|
|
|
2023-02-03 19:45:50 +03:00
|
|
|
// reset mocks for mention
|
2023-02-22 20:15:53 +03:00
|
|
|
const mentionMockTwo = nock(mentionUrl.href)
|
|
|
|
.persist()
|
2023-02-03 19:45:50 +03:00
|
|
|
.get('/')
|
|
|
|
.reply(200, targetHtml, {'content-type': 'text/html'});
|
2023-02-22 20:15:53 +03:00
|
|
|
const endpointMockTwo = nock(endpointUrl.href)
|
|
|
|
.persist()
|
2023-02-03 19:45:50 +03:00
|
|
|
.post('/')
|
|
|
|
.reply(201);
|
|
|
|
|
2023-02-22 20:15:53 +03:00
|
|
|
const postId = res.body.posts[0].id;
|
2023-02-03 19:45:50 +03:00
|
|
|
// moving back to draft is how we unpublish
|
2023-02-22 20:15:53 +03:00
|
|
|
const unpublishedPost = {
|
|
|
|
status: 'draft',
|
2023-02-03 19:45:50 +03:00
|
|
|
updated_at: res.body.posts[0].updated_at
|
|
|
|
};
|
|
|
|
await agent.put(`posts/${postId}/`)
|
|
|
|
.body({posts: [unpublishedPost]})
|
|
|
|
.expectStatus(200);
|
|
|
|
|
2023-02-22 20:15:53 +03:00
|
|
|
await jobsService.allSettled();
|
|
|
|
await DomainEvents.allSettled();
|
2023-02-03 19:45:50 +03:00
|
|
|
|
|
|
|
assert.equal(mentionMockTwo.isDone(), true);
|
|
|
|
assert.equal(endpointMockTwo.isDone(), true);
|
|
|
|
});
|
|
|
|
|
2023-03-11 00:25:10 +03:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2023-09-21 17:17:05 +03:00
|
|
|
it('Edited published page without url changes (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();
|
|
|
|
addMentionMocks();
|
|
|
|
assert.equal(mentionMock.isDone(), false, 'should be reset');
|
|
|
|
assert.equal(endpointMock.isDone(), false, 'should be reset');
|
|
|
|
|
|
|
|
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(mentionMock.isDone(), false);
|
|
|
|
assert.equal(mentionMock.isDone(), false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Edited published page with url changes (page.published.edited)', async function () {
|
2023-03-11 00:25:10 +03:00
|
|
|
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();
|
2023-09-21 17:17:05 +03:00
|
|
|
addMentionMocks();
|
|
|
|
assert.equal(mentionMock.isDone(), false, 'should be reset');
|
|
|
|
assert.equal(endpointMock.isDone(), false, 'should be reset');
|
2023-03-11 00:25:10 +03:00
|
|
|
|
|
|
|
// reset mocks for mention
|
2023-09-21 17:17:05 +03:00
|
|
|
const mentionMockTwo = nock(mentionUrl2.href)
|
2023-03-11 00:25:10 +03:00
|
|
|
.persist()
|
|
|
|
.get('/')
|
2023-09-21 17:17:05 +03:00
|
|
|
.reply(200, targetHtml2, {'content-type': 'text/html'});
|
2023-03-11 00:25:10 +03:00
|
|
|
|
2023-09-21 17:17:05 +03:00
|
|
|
const endpointMockTwo = nock(endpointUrl2.href)
|
2023-03-11 00:25:10 +03:00
|
|
|
.persist()
|
|
|
|
.post('/')
|
|
|
|
.reply(201);
|
|
|
|
|
|
|
|
const pageId = res.body.pages[0].id;
|
|
|
|
const editedPage = {
|
2023-09-21 17:17:05 +03:00
|
|
|
...editedMentionsPost,
|
2023-03-11 00:25:10 +03:00
|
|
|
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);
|
2023-09-21 17:17:05 +03:00
|
|
|
|
|
|
|
// Also send again to the deleted url
|
|
|
|
assert.equal(mentionMock.isDone(), true);
|
|
|
|
assert.equal(endpointMock.isDone(), true);
|
2023-03-11 00:25:10 +03:00
|
|
|
});
|
|
|
|
|
2024-04-16 10:37:06 +03:00
|
|
|
it('Unpublished page (page.unpublished)', async function () {
|
2023-03-11 00:25:10 +03:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2023-02-03 19:45:50 +03:00
|
|
|
it('Sends for links that got removed from a post', async function () {
|
2023-02-22 20:15:53 +03:00
|
|
|
const publishedPost = {status: 'published', ...mentionsPost};
|
|
|
|
const res = await agent
|
2023-02-03 19:45:50 +03:00
|
|
|
.post('posts/')
|
|
|
|
.body({posts: [publishedPost]})
|
|
|
|
.expectStatus(201);
|
|
|
|
|
2023-02-22 20:15:53 +03:00
|
|
|
await jobsService.allSettled();
|
|
|
|
await DomainEvents.allSettled();
|
2023-02-03 19:45:50 +03:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2023-02-22 20:15:53 +03:00
|
|
|
nock.cleanAll();
|
|
|
|
|
2023-02-03 19:45:50 +03:00
|
|
|
// reset mocks for mention
|
2023-02-22 20:15:53 +03:00
|
|
|
const mentionMockTwo = nock(mentionUrl.href)
|
|
|
|
.persist()
|
2023-02-03 19:45:50 +03:00
|
|
|
.get('/')
|
|
|
|
.reply(200, targetHtml, {'content-type': 'text/html'});
|
2023-02-22 20:15:53 +03:00
|
|
|
|
|
|
|
const endpointMockTwo = nock(endpointUrl.href)
|
|
|
|
.persist()
|
2023-02-03 19:45:50 +03:00
|
|
|
.post('/')
|
|
|
|
.reply(201);
|
|
|
|
|
2023-02-22 20:15:53 +03:00
|
|
|
const postId = res.body.posts[0].id;
|
|
|
|
const editedPost = {
|
2023-02-03 19:45:50 +03:00
|
|
|
mobiledoc: markdownToMobiledoc(`mentions were removed from this post`),
|
|
|
|
updated_at: res.body.posts[0].updated_at
|
|
|
|
};
|
|
|
|
await agent.put(`posts/${postId}/`)
|
|
|
|
.body({posts: [editedPost]})
|
|
|
|
.expectStatus(200);
|
|
|
|
|
2023-02-22 20:15:53 +03:00
|
|
|
await jobsService.allSettled();
|
|
|
|
await DomainEvents.allSettled();
|
2023-02-03 19:45:50 +03:00
|
|
|
|
|
|
|
assert.equal(mentionMockTwo.isDone(), true);
|
|
|
|
assert.equal(endpointMockTwo.isDone(), true);
|
|
|
|
});
|
|
|
|
|
2023-03-11 00:25:10 +03:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2023-02-03 19:45:50 +03:00
|
|
|
// there's no special handling for this atm, but could be down the road
|
|
|
|
it('New paid post', async function () {
|
2023-02-22 20:15:53 +03:00
|
|
|
const publishedPost = {status: 'published', visibility: 'paid', ...mentionsPost};
|
2023-02-03 19:45:50 +03:00
|
|
|
await agent
|
|
|
|
.post('posts/')
|
|
|
|
.body({posts: [publishedPost]})
|
|
|
|
.expectStatus(201);
|
|
|
|
|
2023-02-22 20:15:53 +03:00
|
|
|
await jobsService.allSettled();
|
|
|
|
await DomainEvents.allSettled();
|
2023-02-03 19:45:50 +03:00
|
|
|
|
|
|
|
assert.equal(mentionMock.isDone(), true);
|
|
|
|
assert.equal(endpointMock.isDone(), true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2023-02-22 20:15:53 +03:00
|
|
|
});
|