Johann150
38786b6999
Some checks failed
ci/woodpecker/push/build Pipeline failed
ci/woodpecker/push/lint-foundkey-js Pipeline failed
ci/woodpecker/push/test unknown status
ci/woodpecker/push/lint-backend Pipeline failed
ci/woodpecker/push/lint-client Pipeline failed
ci/woodpecker/push/lint-sw Pipeline failed
This allows to get rid of the special loader for ts files. There is no need for the test files to be written in TypeScript, plain JavaScript should be fine for this purpose.
113 lines
3 KiB
JavaScript
113 lines
3 KiB
JavaScript
process.env.NODE_ENV = 'test';
|
|
|
|
import * as assert from 'assert';
|
|
import { initDb } from '../built/db/postgre.js';
|
|
import { initTestDb } from './utils.mjs';
|
|
|
|
|
|
function rndstr(length) {
|
|
const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
const chars_len = 62;
|
|
|
|
let str = '';
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
let rand = Math.floor(Math.random() * chars_len);
|
|
if (rand === chars_len) {
|
|
rand = chars_len - 1;
|
|
}
|
|
str += chars.charAt(rand);
|
|
}
|
|
|
|
return str;
|
|
}
|
|
|
|
describe('ActivityPub', () => {
|
|
before(async () => {
|
|
//await initTestDb();
|
|
await initDb();
|
|
});
|
|
|
|
describe('Parse minimum object', () => {
|
|
const host = 'https://host1.test';
|
|
const preferredUsername = `${rndstr(8)}`;
|
|
const actorId = `${host}/users/${preferredUsername.toLowerCase()}`;
|
|
|
|
const actor = {
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
id: actorId,
|
|
type: 'Person',
|
|
preferredUsername,
|
|
inbox: `${actorId}/inbox`,
|
|
outbox: `${actorId}/outbox`,
|
|
};
|
|
|
|
const post = {
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
id: `${host}/users/${rndstr(8)}`,
|
|
type: 'Note',
|
|
attributedTo: actor.id,
|
|
to: 'https://www.w3.org/ns/activitystreams#Public',
|
|
content: 'あ',
|
|
};
|
|
|
|
it('Minimum Actor', async () => {
|
|
const { MockResolver } = await import('./misc/mock-resolver.mjs');
|
|
const { createPerson } = await import('../built/remote/activitypub/models/person.js');
|
|
|
|
const resolver = new MockResolver();
|
|
resolver._register(actor.id, actor);
|
|
|
|
const user = await createPerson(actor.id, resolver);
|
|
|
|
assert.deepStrictEqual(user.uri, actor.id);
|
|
assert.deepStrictEqual(user.username, actor.preferredUsername);
|
|
assert.deepStrictEqual(user.inbox, actor.inbox);
|
|
});
|
|
|
|
it('Minimum Note', async () => {
|
|
const { MockResolver } = await import('./misc/mock-resolver.mjs');
|
|
const { createNote } = await import('../built/remote/activitypub/models/note.js');
|
|
|
|
const resolver = new MockResolver();
|
|
resolver._register(actor.id, actor);
|
|
resolver._register(post.id, post);
|
|
|
|
const note = await createNote(post.id, resolver, true);
|
|
|
|
assert.deepStrictEqual(note?.uri, post.id);
|
|
assert.deepStrictEqual(note.visibility, 'public');
|
|
assert.deepStrictEqual(note.text, post.content);
|
|
});
|
|
});
|
|
|
|
describe('Truncate long name', () => {
|
|
const host = 'https://host1.test';
|
|
const preferredUsername = `${rndstr(8)}`;
|
|
const actorId = `${host}/users/${preferredUsername.toLowerCase()}`;
|
|
|
|
const name = rndstr(129);
|
|
|
|
const actor = {
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
id: actorId,
|
|
type: 'Person',
|
|
preferredUsername,
|
|
name,
|
|
inbox: `${actorId}/inbox`,
|
|
outbox: `${actorId}/outbox`,
|
|
};
|
|
|
|
it('Actor', async () => {
|
|
const { MockResolver } = await import('./misc/mock-resolver.mjs');
|
|
const { createPerson } = await import('../built/remote/activitypub/models/person.js');
|
|
|
|
const resolver = new MockResolver();
|
|
resolver._register(actor.id, actor);
|
|
|
|
const user = await createPerson(actor.id, resolver);
|
|
|
|
assert.deepStrictEqual(user.name, actor.name.substr(0, 128));
|
|
});
|
|
});
|
|
});
|