pleroma/app/soapbox/utils/__tests__/badges.test.ts

41 lines
997 B
TypeScript
Raw Normal View History

2023-06-20 12:24:39 -07:00
import { buildAccount } from 'soapbox/jest/factory';
2022-09-11 19:04:21 -07:00
import {
tagToBadge,
badgeToTag,
filterBadges,
getTagDiff,
getBadges,
} from '../badges';
test('tagToBadge', () => {
expect(tagToBadge('yolo')).toEqual('badge:yolo');
});
test('badgeToTag', () => {
expect(badgeToTag('badge:yolo')).toEqual('yolo');
expect(badgeToTag('badge:badge:')).toEqual('badge:');
});
test('filterBadges', () => {
const tags = ['one', 'badge:two', 'badge:three', 'four'];
const badges = ['badge:two', 'badge:three'];
expect(filterBadges(tags)).toEqual(badges);
});
test('getTagDiff', () => {
const oldTags = ['one', 'two', 'three'];
const newTags = ['three', 'four', 'five'];
const expected = {
added: ['four', 'five'],
removed: ['one', 'two'],
};
expect(getTagDiff(oldTags, newTags)).toEqual(expected);
});
test('getBadges', () => {
2023-06-20 12:24:39 -07:00
const account = buildAccount({ id: '1', pleroma: { tags: ['a', 'b', 'badge:c'] } });
2022-09-11 19:04:21 -07:00
expect(getBadges(account)).toEqual(['badge:c']);
});