mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-11-24 10:47:19 +01:00
Add test
This commit is contained in:
parent
cf2b1c1e00
commit
8c64f999dc
1 changed files with 38 additions and 30 deletions
|
@ -11,8 +11,25 @@ import { GlobalModule } from '@/GlobalModule.js';
|
||||||
import { CoreModule } from '@/core/CoreModule.js';
|
import { CoreModule } from '@/core/CoreModule.js';
|
||||||
import { FederatedInstanceService } from '@/core/FederatedInstanceService.js';
|
import { FederatedInstanceService } from '@/core/FederatedInstanceService.js';
|
||||||
import { LoggerService } from '@/core/LoggerService.js';
|
import { LoggerService } from '@/core/LoggerService.js';
|
||||||
|
import type { IActor } from '@/core/activitypub/type.js';
|
||||||
import { MockResolver } from '../misc/mock-resolver.js';
|
import { MockResolver } from '../misc/mock-resolver.js';
|
||||||
|
|
||||||
|
const host = 'https://host1.test';
|
||||||
|
|
||||||
|
function createRandomActor(): IActor & { id: string } {
|
||||||
|
const preferredUsername = `${rndstr('A-Z', 4)}${rndstr('a-z', 4)}`;
|
||||||
|
const actorId = `${host}/users/${preferredUsername.toLowerCase()}`;
|
||||||
|
|
||||||
|
return {
|
||||||
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||||
|
id: actorId,
|
||||||
|
type: 'Person',
|
||||||
|
preferredUsername,
|
||||||
|
inbox: `${actorId}/inbox`,
|
||||||
|
outbox: `${actorId}/outbox`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
describe('ActivityPub', () => {
|
describe('ActivityPub', () => {
|
||||||
let noteService: ApNoteService;
|
let noteService: ApNoteService;
|
||||||
let personService: ApPersonService;
|
let personService: ApPersonService;
|
||||||
|
@ -36,18 +53,7 @@ describe('ActivityPub', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Parse minimum object', () => {
|
describe('Parse minimum object', () => {
|
||||||
const host = 'https://host1.test';
|
const actor = createRandomActor();
|
||||||
const preferredUsername = `${rndstr('A-Z', 4)}${rndstr('a-z', 4)}`;
|
|
||||||
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 = {
|
const post = {
|
||||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||||
|
@ -80,29 +86,31 @@ describe('ActivityPub', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Truncate long name', () => {
|
describe('Name field', () => {
|
||||||
const host = 'https://host1.test';
|
test('Truncate long name', async () => {
|
||||||
const preferredUsername = `${rndstr('A-Z', 4)}${rndstr('a-z', 4)}`;
|
const actor = {
|
||||||
const actorId = `${host}/users/${preferredUsername.toLowerCase()}`;
|
...createRandomActor(),
|
||||||
|
name: rndstr('0-9a-z', 129),
|
||||||
|
};
|
||||||
|
|
||||||
const name = rndstr('0-9a-z', 129);
|
|
||||||
|
|
||||||
const actor = {
|
|
||||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
||||||
id: actorId,
|
|
||||||
type: 'Person',
|
|
||||||
preferredUsername,
|
|
||||||
name,
|
|
||||||
inbox: `${actorId}/inbox`,
|
|
||||||
outbox: `${actorId}/outbox`,
|
|
||||||
};
|
|
||||||
|
|
||||||
test('Actor', async () => {
|
|
||||||
resolver._register(actor.id, actor);
|
resolver._register(actor.id, actor);
|
||||||
|
|
||||||
const user = await personService.createPerson(actor.id, resolver);
|
const user = await personService.createPerson(actor.id, resolver);
|
||||||
|
|
||||||
assert.deepStrictEqual(user.name, actor.name.substr(0, 128));
|
assert.deepStrictEqual(user.name, actor.name.slice(0, 128));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Normalize empty name', async () => {
|
||||||
|
const actor = {
|
||||||
|
...createRandomActor(),
|
||||||
|
name: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
resolver._register(actor.id, actor);
|
||||||
|
|
||||||
|
const user = await personService.createPerson(actor.id, resolver);
|
||||||
|
|
||||||
|
assert.strictEqual(user.name, null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue