test: refactor tests to support additional Note tests

This commit is contained in:
Julian Lam
2024-05-07 11:56:58 -04:00
parent 2cd9088c8d
commit 0c0f01b560

View File

@@ -361,56 +361,61 @@ describe('ActivityPub integration', () => {
}); });
describe('Serving of local assets to remote clients', () => { describe('Serving of local assets to remote clients', () => {
let category;
let uid;
let postData;
let topicData;
before(async () => {
category = await categories.create({ name: utils.generateUUID().slice(0, 8) });
const slug = slugify(utils.generateUUID().slice(0, 8));
uid = await user.create({ username: slug });
({ postData, topicData } = await topics.post({
uid,
cid: category.cid,
title: 'Lorem "Lipsum" Ipsum',
content: 'Lorem ipsum dolor sit amet',
}));
});
describe('Note', () => { describe('Note', () => {
let body; let cid;
let response; let uid;
before(async () => { before(async () => {
({ body, response } = await request.get(`${nconf.get('url')}/post/${postData.pid}`, { ({ cid } = await categories.create({ name: utils.generateUUID().slice(0, 8) }));
headers: { const slug = slugify(utils.generateUUID().slice(0, 8));
Accept: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', uid = await user.create({ username: slug });
},
}));
}); });
it('should return a 404 on a non-existant post', async () => { describe('Existing and resolvable', () => {
const { response } = await request.get(`${nconf.get('url')}/post/${parseInt(postData.pid, 10) + 1}`, { let body;
headers: { let response;
Accept: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', let postData;
},
before(async () => {
({ postData } = await topics.post({
uid,
cid,
title: 'Lorem "Lipsum" Ipsum',
content: 'Lorem ipsum dolor sit amet',
}));
({ body, response } = await request.get(`${nconf.get('url')}/post/${postData.pid}`, {
headers: {
Accept: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
},
}));
}); });
assert.strictEqual(response.statusCode, 404); it('should return a 404 on a non-existant post', async () => {
const { response } = await request.get(`${nconf.get('url')}/post/${parseInt(postData.pid, 10) + 1}`, {
headers: {
Accept: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
},
});
assert.strictEqual(response.statusCode, 404);
});
it('should return a 200 response on an existing post', () => {
assert.strictEqual(response.statusCode, 200);
});
it('should return the expected Content-Type header', () => {
assert.strictEqual(response.headers['content-type'], 'application/activity+json; charset=utf-8');
});
it('Topic title (`name`) should not be escaped', () => {
assert.strictEqual(body.name, 'Lorem "Lipsum" Ipsum');
});
}); });
it('should return a 200 response on an existing post', () => { describe('Soft deleted', () => {
assert.strictEqual(response.statusCode, 200);
});
it('should return the expected Content-Type header', () => {
assert.strictEqual(response.headers['content-type'], 'application/activity+json; charset=utf-8');
});
it('Topic title (`name`) should not be escaped', () => {
assert.strictEqual(body.name, 'Lorem "Lipsum" Ipsum');
}); });
}); });
}); });