Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-giguere committed Jun 5, 2024
1 parent 5fd327c commit ce10319
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mastofeed",
"version": "1.5.10",
"version": "1.5.11",
"description": "A Node.js / TypeScript library to post RSS feed items to Mastodon. Outputs rich, highly-customizable posts.",
"author": "Pascal Giguère",
"homepage": "https://github.com/pascal-giguere/mastofeed#readme",
Expand Down
3 changes: 1 addition & 2 deletions src/utils/posts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Item } from 'rss-parser';
import { PropertyDef, PropertyDefOptions } from './properties';
import { addMFIDToUrl, encodeMFID } from './mfid';
import { addMFIDToUrl } from './mfid';

const MAX_TOOT_CHARACTER_COUNT = 500;

Expand Down Expand Up @@ -70,7 +70,6 @@ export function buildTootText(post: Post): string {
if (post.author) text += post.author;
if (post.author && post.category) text += ' — ';
if (post.category) text += post.category;
if (post.linkUrl) text += `\n${post.linkUrl}?mfid=${encodeMFID(post.id)}`;
if (post.linkUrl) text += `\n${addMFIDToUrl(post.linkUrl, post.id)}`;
return text;
}
18 changes: 15 additions & 3 deletions test/unit/mfid.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { decodeMFID, encodeMFID, extractUrlFromTootContent, extractMFIDFromUrl } from '../../src/utils/mfid';
import {
decodeMFID,
encodeMFID,
extractUrlFromTootContent,
extractMFIDFromUrl,
addMFIDToUrl,
} from '../../src/utils/mfid';

describe('Mastofeed identifier (MFID)', () => {
it('encodes an MFID', () => {
Expand All @@ -19,9 +25,15 @@ describe('Mastofeed identifier (MFID)', () => {
);
});

it('extracts an MFID from an URL', () => {
it('adds an MFID to a URL', () => {
expect(addMFIDToUrl('https://www.example.com/test?utm=foo', '375c0c80e35f3c5494478cab7343fa13')).toEqual(
'https://www.example.com/test?utm=foo&mfid=Mzc1YzBjODBlMzVmM2M1NDk0NDc4Y2FiNzM0M2ZhMTM%3D',
);
});

it('extracts an MFID from a URL', () => {
expect(
extractMFIDFromUrl('https://www.example.com/test?mfid=Mzc1YzBjODBlMzVmM2M1NDk0NDc4Y2FiNzM0M2ZhMTM=&oid=abc'),
extractMFIDFromUrl('https://www.example.com/test?utm=foo&mfid=Mzc1YzBjODBlMzVmM2M1NDk0NDc4Y2FiNzM0M2ZhMTM%3D'),
).toEqual('375c0c80e35f3c5494478cab7343fa13');
});
});

0 comments on commit ce10319

Please sign in to comment.