summaryrefslogtreecommitdiff
path: root/packages/backend/test/unit
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-02-12 15:11:19 -0500
committerHazelnoot <acomputerdog@gmail.com>2025-02-16 19:20:41 -0500
commitc54b6bf55d94ac74ee59631003d8b78a8993bbbb (patch)
tree50e48338f6968ca0b56fd08dbba2dd3e7cdc3fc0 /packages/backend/test/unit
parentfix type error in WebhookTestService.ts (diff)
downloadsharkey-c54b6bf55d94ac74ee59631003d8b78a8993bbbb.tar.gz
sharkey-c54b6bf55d94ac74ee59631003d8b78a8993bbbb.tar.bz2
sharkey-c54b6bf55d94ac74ee59631003d8b78a8993bbbb.zip
append mandatory CW in `Update(Note)` activities
Diffstat (limited to 'packages/backend/test/unit')
-rw-r--r--packages/backend/test/unit/activitypub.ts111
1 files changed, 82 insertions, 29 deletions
diff --git a/packages/backend/test/unit/activitypub.ts b/packages/backend/test/unit/activitypub.ts
index 105a3292bf..b4cffbc706 100644
--- a/packages/backend/test/unit/activitypub.ts
+++ b/packages/backend/test/unit/activitypub.ts
@@ -483,38 +483,38 @@ describe('ActivityPub', () => {
});
describe(ApRendererService, () => {
- describe('renderNote', () => {
- let note: MiNote;
- let author: MiUser;
+ let note: MiNote;
+ let author: MiUser;
- beforeEach(() => {
- author = new MiUser({
- id: idService.gen(),
- });
- note = new MiNote({
- id: idService.gen(),
- userId: author.id,
- visibility: 'public',
- localOnly: false,
- text: 'Note text',
- cw: null,
- renoteCount: 0,
- repliesCount: 0,
- clippedCount: 0,
- reactions: {},
- fileIds: [],
- attachedFileTypes: [],
- visibleUserIds: [],
- mentions: [],
- // This is fucked tbh - it's JSON stored in a TEXT column that gets parsed/serialized all over the place
- mentionedRemoteUsers: '[]',
- reactionAndUserPairCache: [],
- emojis: [],
- tags: [],
- hasPoll: false,
- });
+ beforeEach(() => {
+ author = new MiUser({
+ id: idService.gen(),
+ });
+ note = new MiNote({
+ id: idService.gen(),
+ userId: author.id,
+ visibility: 'public',
+ localOnly: false,
+ text: 'Note text',
+ cw: null,
+ renoteCount: 0,
+ repliesCount: 0,
+ clippedCount: 0,
+ reactions: {},
+ fileIds: [],
+ attachedFileTypes: [],
+ visibleUserIds: [],
+ mentions: [],
+ // This is fucked tbh - it's JSON stored in a TEXT column that gets parsed/serialized all over the place
+ mentionedRemoteUsers: '[]',
+ reactionAndUserPairCache: [],
+ emojis: [],
+ tags: [],
+ hasPoll: false,
});
+ });
+ describe('renderNote', () => {
describe('summary', () => {
// I actually don't know why it does this, but the logic was already there so I've preserved it.
it('should be special character when CW is empty string', async () => {
@@ -566,5 +566,58 @@ describe('ActivityPub', () => {
});
});
});
+
+ describe('renderUpnote', () => {
+ describe('summary', () => {
+ // I actually don't know why it does this, but the logic was already there so I've preserved it.
+ it('should be special character when CW is empty string', async () => {
+ note.cw = '';
+
+ const result = await rendererService.renderUpNote(note, author, false);
+
+ expect(result.summary).toBe(String.fromCharCode(0x200B));
+ });
+
+ it('should be undefined when CW is null', async () => {
+ const result = await rendererService.renderUpNote(note, author, false);
+
+ expect(result.summary).toBeUndefined();
+ });
+
+ it('should be CW when present without mandatoryCW', async () => {
+ note.cw = 'original';
+
+ const result = await rendererService.renderUpNote(note, author, false);
+
+ expect(result.summary).toBe('original');
+ });
+
+ it('should be mandatoryCW when present without CW', async () => {
+ author.mandatoryCW = 'mandatory';
+
+ const result = await rendererService.renderUpNote(note, author, false);
+
+ expect(result.summary).toBe('mandatory');
+ });
+
+ it('should be merged when CW and mandatoryCW are both present', async () => {
+ note.cw = 'original';
+ author.mandatoryCW = 'mandatory';
+
+ const result = await rendererService.renderUpNote(note, author, false);
+
+ expect(result.summary).toBe('original, mandatory');
+ });
+
+ it('should be CW when CW includes mandatoryCW', async () => {
+ note.cw = 'original and mandatory';
+ author.mandatoryCW = 'mandatory';
+
+ const result = await rendererService.renderUpNote(note, author, false);
+
+ expect(result.summary).toBe('original and mandatory');
+ });
+ });
+ });
});
});