Added e2e tests for updating Mentions

closes https://github.com/TryGhost/Team/issues/2552

We send a Webmention for the same URL twice, but change the contents
of the source document, and we check that the source metadata is
updated appropriately.

We should consider extending all of these tests to include featured
images and logos etc...
This commit is contained in:
Fabien "egg" O'Carroll 2023-02-13 14:47:02 +07:00 committed by Fabien 'egg' O'Carroll
parent 77032262c4
commit bf6bcdbff3

View File

@ -75,6 +75,75 @@ describe('Webmentions (receiving)', function () {
})); }));
}); });
it('will update a mentions source metadata', async function () {
const targetUrl = new URL(urlUtils.getSiteUrl());
const sourceUrl = new URL('http://testpage.com/update-mention-test-1/');
testCreatingTheMention: {
const processWebmentionJob = jobsService.awaitCompletion('processWebmention');
const html = `
<html><head><title>Test Page</title><meta name="description" content="Test description"><meta name="author" content="John Doe"></head><body></body></html>
`;
nock(targetUrl.origin)
.head(targetUrl.pathname)
.reply(200);
nock(sourceUrl.origin)
.get(sourceUrl.pathname)
.reply(200, html, {'Content-Type': 'text/html'});
await agent.post('/receive')
.body({
source: sourceUrl.href,
target: targetUrl.href
})
.expectStatus(202);
await processWebmentionJob;
const mention = await models.Mention.findOne({source: 'http://testpage.com/update-mention-test-1/'});
assert(mention);
assert.equal(mention.get('source_title'), 'Test Page');
assert.equal(mention.get('source_excerpt'), 'Test description');
assert.equal(mention.get('source_author'), 'John Doe');
break testCreatingTheMention;
}
testUpdatingTheMention: {
const processWebmentionJob = jobsService.awaitCompletion('processWebmention');
const html = `
<html><head><title>New Title</title><meta name="description" content="New Description"><meta name="author" content="big man with a beard"></head><body></body></html>
`;
nock(targetUrl.origin)
.head(targetUrl.pathname)
.reply(200);
nock(sourceUrl.origin)
.get(sourceUrl.pathname)
.reply(200, html, {'Content-Type': 'text/html'});
await agent.post('/receive')
.body({
source: sourceUrl.href,
target: targetUrl.href
})
.expectStatus(202);
await processWebmentionJob;
const mention = await models.Mention.findOne({source: 'http://testpage.com/update-mention-test-1/'});
assert(mention);
assert.equal(mention.get('source_title'), 'New Title');
assert.equal(mention.get('source_excerpt'), 'New Description');
assert.equal(mention.get('source_author'), 'big man with a beard');
break testUpdatingTheMention;
}
});
it('can receive a webmention to homepage', async function () { it('can receive a webmention to homepage', async function () {
const processWebmentionJob = jobsService.awaitCompletion('processWebmention'); const processWebmentionJob = jobsService.awaitCompletion('processWebmention');
const targetUrl = new URL(urlUtils.getSiteUrl()); const targetUrl = new URL(urlUtils.getSiteUrl());