2024-05-18 17:36:06 +02:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: dakkar and sharkey-project
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
import type { IObject } from '@/core/activitypub/type.js';
|
|
|
|
import { describe, expect, test } from '@jest/globals';
|
|
|
|
import { assertActivityMatchesUrls } from '@/core/activitypub/misc/check-against-url.js';
|
|
|
|
|
|
|
|
function assertOne(activity: IObject) {
|
|
|
|
// return a function so we can use `.toThrow`
|
|
|
|
return () => assertActivityMatchesUrls(activity, ['good']);
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('assertActivityMatchesUrls', () => {
|
|
|
|
test('id', () => {
|
2024-05-31 13:59:32 +02:00
|
|
|
expect(assertOne({ type: 'Test', id: 'bad' })).toThrow(/bad Activity/);
|
|
|
|
expect(assertOne({ type: 'Test', id: 'good' })).not.toThrow();
|
2024-05-18 17:36:06 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('simple url', () => {
|
2024-05-31 13:59:32 +02:00
|
|
|
expect(assertOne({ type: 'Test', url: 'bad' })).toThrow(/bad Activity/);
|
|
|
|
expect(assertOne({ type: 'Test', url: 'good' })).not.toThrow();
|
2024-05-18 17:36:06 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('array of urls', () => {
|
2024-05-31 13:59:32 +02:00
|
|
|
expect(assertOne({ type: 'Test', url: ['bad'] })).toThrow(/bad Activity/);
|
|
|
|
expect(assertOne({ type: 'Test', url: ['bad', 'other'] })).toThrow(/bad Activity/);
|
|
|
|
expect(assertOne({ type: 'Test', url: ['good'] })).not.toThrow();
|
|
|
|
expect(assertOne({ type: 'Test', url: ['bad', 'good'] })).not.toThrow();
|
2024-05-18 17:36:06 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('array of objects', () => {
|
2024-05-31 13:59:32 +02:00
|
|
|
expect(assertOne({ type: 'Test', url: [{ type: 'Test', href: 'bad' }] })).toThrow(/bad Activity/);
|
|
|
|
expect(assertOne({ type: 'Test', url: [{ type: 'Test', href: 'bad' }, { type: 'Test', href: 'other' }] })).toThrow(/bad Activity/);
|
|
|
|
expect(assertOne({ type: 'Test', url: [{ type: 'Test', href: 'good' }] })).not.toThrow();
|
|
|
|
expect(assertOne({ type: 'Test', url: [{ type: 'Test', href: 'bad' }, { type: 'Test', href: 'good' }] })).not.toThrow();
|
2024-05-18 17:36:06 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('mixed array', () => {
|
2024-05-31 13:59:32 +02:00
|
|
|
expect(assertOne({ type: 'Test', url: [{ type: 'Test', href: 'bad' }, 'other'] })).toThrow(/bad Activity/);
|
|
|
|
expect(assertOne({ type: 'Test', url: [{ type: 'Test', href: 'bad' }, 'good'] })).not.toThrow();
|
|
|
|
expect(assertOne({ type: 'Test', url: ['bad', { type: 'Test', href: 'good' }] })).not.toThrow();
|
2024-05-18 17:36:06 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('id and url', () => {
|
2024-05-31 13:59:32 +02:00
|
|
|
expect(assertOne({ type: 'Test', id: 'other', url: 'bad' })).toThrow(/bad Activity/);
|
|
|
|
expect(assertOne({ type: 'Test', id: 'bad', url: 'good' })).not.toThrow();
|
|
|
|
expect(assertOne({ type: 'Test', id: 'good', url: 'bad' })).not.toThrow();
|
2024-05-18 17:36:06 +02:00
|
|
|
});
|
|
|
|
});
|