test(backend): refactor tests (#13499)
* test(backend): refactor tests * fix: failed test
This commit is contained in:
@@ -6,47 +6,34 @@
|
||||
process.env.NODE_ENV = 'test';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { JTDDataType } from 'ajv/dist/jtd';
|
||||
import { DEFAULT_POLICIES } from '@/core/RoleService.js';
|
||||
import type { Packed } from '@/misc/json-schema.js';
|
||||
import { paramDef as CreateParamDef } from '@/server/api/endpoints/clips/create.js';
|
||||
import { paramDef as UpdateParamDef } from '@/server/api/endpoints/clips/update.js';
|
||||
import { paramDef as DeleteParamDef } from '@/server/api/endpoints/clips/delete.js';
|
||||
import { paramDef as ShowParamDef } from '@/server/api/endpoints/clips/show.js';
|
||||
import { paramDef as FavoriteParamDef } from '@/server/api/endpoints/clips/favorite.js';
|
||||
import { paramDef as UnfavoriteParamDef } from '@/server/api/endpoints/clips/unfavorite.js';
|
||||
import { paramDef as AddNoteParamDef } from '@/server/api/endpoints/clips/add-note.js';
|
||||
import { paramDef as RemoveNoteParamDef } from '@/server/api/endpoints/clips/remove-note.js';
|
||||
import { paramDef as NotesParamDef } from '@/server/api/endpoints/clips/notes.js';
|
||||
import { api, ApiRequest, failedApiCall, hiddenNote, post, signup, successfulApiCall } from '../utils.js';
|
||||
import type * as Misskey from 'misskey-js';
|
||||
|
||||
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
||||
|
||||
describe('クリップ', () => {
|
||||
type User = Packed<'User'>;
|
||||
type Note = Packed<'Note'>;
|
||||
type Clip = Packed<'Clip'>;
|
||||
|
||||
let alice: User;
|
||||
let bob: User;
|
||||
let aliceNote: Note;
|
||||
let aliceHomeNote: Note;
|
||||
let aliceFollowersNote: Note;
|
||||
let aliceSpecifiedNote: Note;
|
||||
let bobNote: Note;
|
||||
let bobHomeNote: Note;
|
||||
let bobFollowersNote: Note;
|
||||
let bobSpecifiedNote: Note;
|
||||
let alice: Misskey.entities.SignupResponse;
|
||||
let bob: Misskey.entities.SignupResponse;
|
||||
let aliceNote: Misskey.entities.Note;
|
||||
let aliceHomeNote: Misskey.entities.Note;
|
||||
let aliceFollowersNote: Misskey.entities.Note;
|
||||
let aliceSpecifiedNote: Misskey.entities.Note;
|
||||
let bobNote: Misskey.entities.Note;
|
||||
let bobHomeNote: Misskey.entities.Note;
|
||||
let bobFollowersNote: Misskey.entities.Note;
|
||||
let bobSpecifiedNote: Misskey.entities.Note;
|
||||
|
||||
const compareBy = <T extends { id: string }, >(selector: (s: T) => string = (s: T): string => s.id) => (a: T, b: T): number => {
|
||||
return selector(a).localeCompare(selector(b));
|
||||
};
|
||||
|
||||
type CreateParam = JTDDataType<typeof CreateParamDef>;
|
||||
const defaultCreate = (): Partial<CreateParam> => ({
|
||||
const defaultCreate = (): Pick<Misskey.entities.ClipsCreateRequest, 'name'> => ({
|
||||
name: 'test',
|
||||
});
|
||||
const create = async (parameters: Partial<CreateParam> = {}, request: Partial<ApiRequest> = {}): Promise<Clip> => {
|
||||
const clip = await successfulApiCall<Clip>({
|
||||
endpoint: '/clips/create',
|
||||
const create = async (parameters: Partial<Misskey.entities.ClipsCreateRequest> = {}, request: Partial<ApiRequest<'clips/create'>> = {}): Promise<Misskey.entities.Clip> => {
|
||||
const clip = await successfulApiCall({
|
||||
endpoint: 'clips/create',
|
||||
parameters: {
|
||||
...defaultCreate(),
|
||||
...parameters,
|
||||
@@ -64,17 +51,16 @@ describe('クリップ', () => {
|
||||
return clip;
|
||||
};
|
||||
|
||||
const createMany = async (parameters: Partial<CreateParam>, count = 10, user = alice): Promise<Clip[]> => {
|
||||
const createMany = async (parameters: Partial<Misskey.entities.ClipsCreateRequest>, count = 10, user = alice): Promise<Misskey.entities.Clip[]> => {
|
||||
return await Promise.all([...Array(count)].map((_, i) => create({
|
||||
name: `test${i}`,
|
||||
...parameters,
|
||||
}, { user })));
|
||||
};
|
||||
|
||||
type UpdateParam = JTDDataType<typeof UpdateParamDef>;
|
||||
const update = async (parameters: Partial<UpdateParam>, request: Partial<ApiRequest> = {}): Promise<Clip> => {
|
||||
const clip = await successfulApiCall<Clip>({
|
||||
endpoint: '/clips/update',
|
||||
const update = async (parameters: Optional<Misskey.entities.ClipsUpdateRequest, 'name'>, request: Partial<ApiRequest<'clips/update'>> = {}): Promise<Misskey.entities.Clip> => {
|
||||
const clip = await successfulApiCall({
|
||||
endpoint: 'clips/update',
|
||||
parameters: {
|
||||
name: 'updated',
|
||||
...parameters,
|
||||
@@ -92,41 +78,39 @@ describe('クリップ', () => {
|
||||
return clip;
|
||||
};
|
||||
|
||||
type DeleteParam = JTDDataType<typeof DeleteParamDef>;
|
||||
const deleteClip = async (parameters: DeleteParam, request: Partial<ApiRequest> = {}): Promise<void> => {
|
||||
return await successfulApiCall<void>({
|
||||
endpoint: '/clips/delete',
|
||||
const deleteClip = async (parameters: Misskey.entities.ClipsDeleteRequest, request: Partial<ApiRequest<'clips/delete'>> = {}): Promise<void> => {
|
||||
return await successfulApiCall({
|
||||
endpoint: 'clips/delete',
|
||||
parameters,
|
||||
user: alice,
|
||||
...request,
|
||||
}, {
|
||||
status: 204,
|
||||
});
|
||||
}) as any as void;
|
||||
};
|
||||
|
||||
type ShowParam = JTDDataType<typeof ShowParamDef>;
|
||||
const show = async (parameters: ShowParam, request: Partial<ApiRequest> = {}): Promise<Clip> => {
|
||||
return await successfulApiCall<Clip>({
|
||||
endpoint: '/clips/show',
|
||||
const show = async (parameters: Misskey.entities.ClipsShowRequest, request: Partial<ApiRequest<'clips/show'>> = {}): Promise<Misskey.entities.Clip> => {
|
||||
return await successfulApiCall({
|
||||
endpoint: 'clips/show',
|
||||
parameters,
|
||||
user: alice,
|
||||
...request,
|
||||
});
|
||||
};
|
||||
|
||||
const list = async (request: Partial<ApiRequest>): Promise<Clip[]> => {
|
||||
return successfulApiCall<Clip[]>({
|
||||
endpoint: '/clips/list',
|
||||
const list = async (request: Partial<ApiRequest<'clips/list'>>): Promise<Misskey.entities.Clip[]> => {
|
||||
return successfulApiCall({
|
||||
endpoint: 'clips/list',
|
||||
parameters: {},
|
||||
user: alice,
|
||||
...request,
|
||||
});
|
||||
};
|
||||
|
||||
const usersClips = async (request: Partial<ApiRequest>): Promise<Clip[]> => {
|
||||
return await successfulApiCall<Clip[]>({
|
||||
endpoint: '/users/clips',
|
||||
parameters: {},
|
||||
const usersClips = async (parameters: Misskey.entities.UsersClipsRequest, request: Partial<ApiRequest<'users/clips'>> = {}): Promise<Misskey.entities.Clip[]> => {
|
||||
return await successfulApiCall({
|
||||
endpoint: 'users/clips',
|
||||
parameters,
|
||||
user: alice,
|
||||
...request,
|
||||
});
|
||||
@@ -136,23 +120,22 @@ describe('クリップ', () => {
|
||||
alice = await signup({ username: 'alice' });
|
||||
bob = await signup({ username: 'bob' });
|
||||
|
||||
// FIXME: misskey-jsのNoteはoutdatedなので直接変換できない
|
||||
aliceNote = await post(alice, { text: 'test' }) as any;
|
||||
aliceHomeNote = await post(alice, { text: 'home only', visibility: 'home' }) as any;
|
||||
aliceFollowersNote = await post(alice, { text: 'followers only', visibility: 'followers' }) as any;
|
||||
aliceSpecifiedNote = await post(alice, { text: 'specified only', visibility: 'specified' }) as any;
|
||||
bobNote = await post(bob, { text: 'test' }) as any;
|
||||
bobHomeNote = await post(bob, { text: 'home only', visibility: 'home' }) as any;
|
||||
bobFollowersNote = await post(bob, { text: 'followers only', visibility: 'followers' }) as any;
|
||||
bobSpecifiedNote = await post(bob, { text: 'specified only', visibility: 'specified' }) as any;
|
||||
aliceNote = await post(alice, { text: 'test' });
|
||||
aliceHomeNote = await post(alice, { text: 'home only', visibility: 'home' });
|
||||
aliceFollowersNote = await post(alice, { text: 'followers only', visibility: 'followers' });
|
||||
aliceSpecifiedNote = await post(alice, { text: 'specified only', visibility: 'specified' });
|
||||
bobNote = await post(bob, { text: 'test' });
|
||||
bobHomeNote = await post(bob, { text: 'home only', visibility: 'home' });
|
||||
bobFollowersNote = await post(bob, { text: 'followers only', visibility: 'followers' });
|
||||
bobSpecifiedNote = await post(bob, { text: 'specified only', visibility: 'specified' });
|
||||
}, 1000 * 60 * 2);
|
||||
|
||||
afterEach(async () => {
|
||||
// テスト間で影響し合わないように毎回全部消す。
|
||||
for (const user of [alice, bob]) {
|
||||
const list = await api('/clips/list', { limit: 11 }, user);
|
||||
const list = await api('clips/list', { limit: 11 }, user);
|
||||
for (const clip of list.body) {
|
||||
await api('/clips/delete', { clipId: clip.id }, user);
|
||||
await api('clips/delete', { clipId: clip.id }, user);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -177,7 +160,7 @@ describe('クリップ', () => {
|
||||
}
|
||||
|
||||
await failedApiCall({
|
||||
endpoint: '/clips/create',
|
||||
endpoint: 'clips/create',
|
||||
parameters: defaultCreate(),
|
||||
user: alice,
|
||||
}, {
|
||||
@@ -204,7 +187,8 @@ describe('クリップ', () => {
|
||||
{ label: 'descriptionが最大長+1', parameters: { description: 'a'.repeat(2049) } },
|
||||
];
|
||||
test.each(createClipDenyPattern)('の作成は$labelならできない', async ({ parameters }) => failedApiCall({
|
||||
endpoint: '/clips/create',
|
||||
endpoint: 'clips/create',
|
||||
// @ts-expect-error invalid params
|
||||
parameters: {
|
||||
...defaultCreate(),
|
||||
...parameters,
|
||||
@@ -246,15 +230,15 @@ describe('クリップ', () => {
|
||||
code: 'NO_SUCH_CLIP',
|
||||
id: 'b4d92d70-b216-46fa-9a3f-a8c811699257',
|
||||
} },
|
||||
{ label: '他人のクリップ', user: (): User => bob, assertion: {
|
||||
{ label: '他人のクリップ', user: () => bob, assertion: {
|
||||
code: 'NO_SUCH_CLIP',
|
||||
id: 'b4d92d70-b216-46fa-9a3f-a8c811699257',
|
||||
} },
|
||||
...createClipDenyPattern as any,
|
||||
])('の更新は$labelならできない', async ({ parameters, user, assertion }) => failedApiCall({
|
||||
endpoint: '/clips/update',
|
||||
endpoint: 'clips/update',
|
||||
parameters: {
|
||||
clipId: (await create({}, { user: (user ?? ((): User => alice))() })).id,
|
||||
clipId: (await create({}, { user: (user ?? (() => alice))() })).id,
|
||||
name: 'updated',
|
||||
...parameters,
|
||||
},
|
||||
@@ -279,14 +263,15 @@ describe('クリップ', () => {
|
||||
code: 'NO_SUCH_CLIP',
|
||||
id: '70ca08ba-6865-4630-b6fb-8494759aa754',
|
||||
} },
|
||||
{ label: '他人のクリップ', user: (): User => bob, assertion: {
|
||||
{ label: '他人のクリップ', user: () => bob, assertion: {
|
||||
code: 'NO_SUCH_CLIP',
|
||||
id: '70ca08ba-6865-4630-b6fb-8494759aa754',
|
||||
} },
|
||||
])('の削除は$labelならできない', async ({ parameters, user, assertion }) => failedApiCall({
|
||||
endpoint: '/clips/delete',
|
||||
endpoint: 'clips/delete',
|
||||
parameters: {
|
||||
clipId: (await create({}, { user: (user ?? ((): User => alice))() })).id,
|
||||
// @ts-expect-error clipId must not be null
|
||||
clipId: (await create({}, { user: (user ?? (() => alice))() })).id,
|
||||
...parameters,
|
||||
},
|
||||
user: alice,
|
||||
@@ -306,7 +291,7 @@ describe('クリップ', () => {
|
||||
test('のID指定取得は他人のPrivateなクリップは取得できない', async () => {
|
||||
const clip = await create({ isPublic: false }, { user: bob } );
|
||||
failedApiCall({
|
||||
endpoint: '/clips/show',
|
||||
endpoint: 'clips/show',
|
||||
parameters: { clipId: clip.id },
|
||||
user: alice,
|
||||
}, {
|
||||
@@ -323,7 +308,8 @@ describe('クリップ', () => {
|
||||
id: 'c3c5fe33-d62c-44d2-9ea5-d997703f5c20',
|
||||
} },
|
||||
])('のID指定取得は$labelならできない', async ({ parameters, assetion }) => failedApiCall({
|
||||
endpoint: '/clips/show',
|
||||
endpoint: 'clips/show',
|
||||
// @ts-expect-error clipId must not be undefined
|
||||
parameters: {
|
||||
...parameters,
|
||||
},
|
||||
@@ -356,27 +342,23 @@ describe('クリップ', () => {
|
||||
|
||||
test('の一覧が取得できる(空)', async () => {
|
||||
const res = await usersClips({
|
||||
parameters: {
|
||||
userId: alice.id,
|
||||
},
|
||||
userId: alice.id,
|
||||
});
|
||||
assert.deepStrictEqual(res, []);
|
||||
});
|
||||
|
||||
test.each([
|
||||
{ label: '' },
|
||||
{ label: '他人アカウントから', user: (): User => bob },
|
||||
{ label: '他人アカウントから', user: () => bob },
|
||||
])('の一覧が$label取得できる', async () => {
|
||||
const clips = await createMany({ isPublic: true });
|
||||
const res = await usersClips({
|
||||
parameters: {
|
||||
userId: alice.id,
|
||||
},
|
||||
userId: alice.id,
|
||||
});
|
||||
|
||||
// 返ってくる配列には順序保障がないのでidでソートして厳密比較
|
||||
assert.deepStrictEqual(
|
||||
res.sort(compareBy<Clip>(s => s.id)),
|
||||
res.sort(compareBy<Misskey.entities.Clip>(s => s.id)),
|
||||
clips.sort(compareBy(s => s.id)));
|
||||
|
||||
// 認証状態で見たときだけisFavoritedが入っている
|
||||
@@ -386,17 +368,16 @@ describe('クリップ', () => {
|
||||
});
|
||||
|
||||
test.each([
|
||||
{ label: '未認証', user: (): undefined => undefined },
|
||||
{ label: '未認証', user: () => undefined },
|
||||
{ label: '存在しないユーザーのもの', parameters: { userId: 'xxxxxxx' } },
|
||||
])('の一覧は$labelでも取得できる', async ({ parameters, user }) => {
|
||||
const clips = await createMany({ isPublic: true });
|
||||
const res = await usersClips({
|
||||
parameters: {
|
||||
userId: alice.id,
|
||||
limit: clips.length,
|
||||
...parameters,
|
||||
},
|
||||
user: (user ?? ((): User => alice))(),
|
||||
userId: alice.id,
|
||||
limit: clips.length,
|
||||
...parameters,
|
||||
}, {
|
||||
user: (user ?? (() => alice))(),
|
||||
});
|
||||
|
||||
// 未認証で見たときはisFavoritedは入らない
|
||||
@@ -409,10 +390,8 @@ describe('クリップ', () => {
|
||||
await create({ isPublic: false });
|
||||
const aliceClip = await create({ isPublic: true });
|
||||
const res = await usersClips({
|
||||
parameters: {
|
||||
userId: alice.id,
|
||||
limit: 2,
|
||||
},
|
||||
userId: alice.id,
|
||||
limit: 2,
|
||||
});
|
||||
assert.deepStrictEqual(res, [aliceClip]);
|
||||
});
|
||||
@@ -421,17 +400,15 @@ describe('クリップ', () => {
|
||||
const clips = await createMany({ isPublic: true }, 7);
|
||||
clips.sort(compareBy(s => s.id));
|
||||
const res = await usersClips({
|
||||
parameters: {
|
||||
userId: alice.id,
|
||||
sinceId: clips[1].id,
|
||||
untilId: clips[5].id,
|
||||
limit: 4,
|
||||
},
|
||||
userId: alice.id,
|
||||
sinceId: clips[1].id,
|
||||
untilId: clips[5].id,
|
||||
limit: 4,
|
||||
});
|
||||
|
||||
// Promise.allで返ってくる配列には順序保障がないのでidでソートして厳密比較
|
||||
assert.deepStrictEqual(
|
||||
res.sort(compareBy<Clip>(s => s.id)),
|
||||
res.sort(compareBy<Misskey.entities.Clip>(s => s.id)),
|
||||
[clips[2], clips[3], clips[4]], // sinceIdとuntilId自体は結果に含まれない
|
||||
clips[1].id + ' ... ' + clips[3].id + ' with ' + clips.map(s => s.id) + ' vs. ' + res.map(s => s.id));
|
||||
});
|
||||
@@ -441,8 +418,9 @@ describe('クリップ', () => {
|
||||
{ label: 'limitゼロ', parameters: { limit: 0 } },
|
||||
{ label: 'limit最大+1', parameters: { limit: 101 } },
|
||||
])('の一覧は$labelだと取得できない', async ({ parameters }) => failedApiCall({
|
||||
endpoint: '/users/clips',
|
||||
endpoint: 'users/clips',
|
||||
parameters: {
|
||||
// @ts-expect-error userId must not be undefined
|
||||
userId: alice.id,
|
||||
...parameters,
|
||||
},
|
||||
@@ -454,15 +432,15 @@ describe('クリップ', () => {
|
||||
}));
|
||||
|
||||
test.each([
|
||||
{ label: '作成', endpoint: '/clips/create' },
|
||||
{ label: '更新', endpoint: '/clips/update' },
|
||||
{ label: '削除', endpoint: '/clips/delete' },
|
||||
{ label: '取得', endpoint: '/clips/list' },
|
||||
{ label: 'お気に入り設定', endpoint: '/clips/favorite' },
|
||||
{ label: 'お気に入り解除', endpoint: '/clips/unfavorite' },
|
||||
{ label: 'お気に入り取得', endpoint: '/clips/my-favorites' },
|
||||
{ label: 'ノート追加', endpoint: '/clips/add-note' },
|
||||
{ label: 'ノート削除', endpoint: '/clips/remove-note' },
|
||||
{ label: '作成', endpoint: 'clips/create' as const },
|
||||
{ label: '更新', endpoint: 'clips/update' as const },
|
||||
{ label: '削除', endpoint: 'clips/delete' as const },
|
||||
{ label: '取得', endpoint: 'clips/list' as const },
|
||||
{ label: 'お気に入り設定', endpoint: 'clips/favorite' as const },
|
||||
{ label: 'お気に入り解除', endpoint: 'clips/unfavorite' as const },
|
||||
{ label: 'お気に入り取得', endpoint: 'clips/my-favorites' as const },
|
||||
{ label: 'ノート追加', endpoint: 'clips/add-note' as const },
|
||||
{ label: 'ノート削除', endpoint: 'clips/remove-note' as const },
|
||||
])('の$labelは未認証ではできない', async ({ endpoint }) => await failedApiCall({
|
||||
endpoint: endpoint,
|
||||
parameters: {},
|
||||
@@ -474,35 +452,33 @@ describe('クリップ', () => {
|
||||
}));
|
||||
|
||||
describe('のお気に入り', () => {
|
||||
let aliceClip: Clip;
|
||||
let aliceClip: Misskey.entities.Clip;
|
||||
|
||||
type FavoriteParam = JTDDataType<typeof FavoriteParamDef>;
|
||||
const favorite = async (parameters: FavoriteParam, request: Partial<ApiRequest> = {}): Promise<void> => {
|
||||
return successfulApiCall<void>({
|
||||
endpoint: '/clips/favorite',
|
||||
const favorite = async (parameters: Misskey.entities.ClipsFavoriteRequest, request: Partial<ApiRequest<'clips/favorite'>> = {}): Promise<void> => {
|
||||
return successfulApiCall({
|
||||
endpoint: 'clips/favorite',
|
||||
parameters,
|
||||
user: alice,
|
||||
...request,
|
||||
}, {
|
||||
status: 204,
|
||||
});
|
||||
}) as any as void;
|
||||
};
|
||||
|
||||
type UnfavoriteParam = JTDDataType<typeof UnfavoriteParamDef>;
|
||||
const unfavorite = async (parameters: UnfavoriteParam, request: Partial<ApiRequest> = {}): Promise<void> => {
|
||||
return successfulApiCall<void>({
|
||||
endpoint: '/clips/unfavorite',
|
||||
const unfavorite = async (parameters: Misskey.entities.ClipsUnfavoriteRequest, request: Partial<ApiRequest<'clips/unfavorite'>> = {}): Promise<void> => {
|
||||
return successfulApiCall({
|
||||
endpoint: 'clips/unfavorite',
|
||||
parameters,
|
||||
user: alice,
|
||||
...request,
|
||||
}, {
|
||||
status: 204,
|
||||
});
|
||||
}) as any as void;
|
||||
};
|
||||
|
||||
const myFavorites = async (request: Partial<ApiRequest> = {}): Promise<Clip[]> => {
|
||||
return successfulApiCall<Clip[]>({
|
||||
endpoint: '/clips/my-favorites',
|
||||
const myFavorites = async (request: Partial<ApiRequest<'clips/my-favorites'>> = {}): Promise<Misskey.entities.Clip[]> => {
|
||||
return successfulApiCall({
|
||||
endpoint: 'clips/my-favorites',
|
||||
parameters: {},
|
||||
user: alice,
|
||||
...request,
|
||||
@@ -568,7 +544,7 @@ describe('クリップ', () => {
|
||||
test('は同じクリップに対して二回設定できない。', async () => {
|
||||
await favorite({ clipId: aliceClip.id });
|
||||
await failedApiCall({
|
||||
endpoint: '/clips/favorite',
|
||||
endpoint: 'clips/favorite',
|
||||
parameters: {
|
||||
clipId: aliceClip.id,
|
||||
},
|
||||
@@ -586,14 +562,15 @@ describe('クリップ', () => {
|
||||
code: 'NO_SUCH_CLIP',
|
||||
id: '4c2aaeae-80d8-4250-9606-26cb1fdb77a5',
|
||||
} },
|
||||
{ label: '他人のクリップ', user: (): User => bob, assertion: {
|
||||
{ label: '他人のクリップ', user: () => bob, assertion: {
|
||||
code: 'NO_SUCH_CLIP',
|
||||
id: '4c2aaeae-80d8-4250-9606-26cb1fdb77a5',
|
||||
} },
|
||||
])('の設定は$labelならできない', async ({ parameters, user, assertion }) => failedApiCall({
|
||||
endpoint: '/clips/favorite',
|
||||
endpoint: 'clips/favorite',
|
||||
parameters: {
|
||||
clipId: (await create({}, { user: (user ?? ((): User => alice))() })).id,
|
||||
// @ts-expect-error clipId must not be null
|
||||
clipId: (await create({}, { user: (user ?? (() => alice))() })).id,
|
||||
...parameters,
|
||||
},
|
||||
user: alice,
|
||||
@@ -619,7 +596,7 @@ describe('クリップ', () => {
|
||||
code: 'NO_SUCH_CLIP',
|
||||
id: '2603966e-b865-426c-94a7-af4a01241dc1',
|
||||
} },
|
||||
{ label: '他人のクリップ', user: (): User => bob, assertion: {
|
||||
{ label: '他人のクリップ', user: () => bob, assertion: {
|
||||
code: 'NOT_FAVORITED',
|
||||
id: '90c3a9e8-b321-4dae-bf57-2bf79bbcc187',
|
||||
} },
|
||||
@@ -628,9 +605,10 @@ describe('クリップ', () => {
|
||||
id: '90c3a9e8-b321-4dae-bf57-2bf79bbcc187',
|
||||
} },
|
||||
])('の設定解除は$labelならできない', async ({ parameters, user, assertion }) => failedApiCall({
|
||||
endpoint: '/clips/unfavorite',
|
||||
endpoint: 'clips/unfavorite',
|
||||
parameters: {
|
||||
clipId: (await create({}, { user: (user ?? ((): User => alice))() })).id,
|
||||
// @ts-expect-error clipId must not be null
|
||||
clipId: (await create({}, { user: (user ?? (() => alice))() })).id,
|
||||
...parameters,
|
||||
},
|
||||
user: alice,
|
||||
@@ -655,41 +633,38 @@ describe('クリップ', () => {
|
||||
});
|
||||
|
||||
describe('に紐づくノート', () => {
|
||||
let aliceClip: Clip;
|
||||
let aliceClip: Misskey.entities.Clip;
|
||||
|
||||
const sampleNotes = (): Note[] => [
|
||||
const sampleNotes = (): Misskey.entities.Note[] => [
|
||||
aliceNote, aliceHomeNote, aliceFollowersNote, aliceSpecifiedNote,
|
||||
bobNote, bobHomeNote, bobFollowersNote, bobSpecifiedNote,
|
||||
];
|
||||
|
||||
type AddNoteParam = JTDDataType<typeof AddNoteParamDef>;
|
||||
const addNote = async (parameters: AddNoteParam, request: Partial<ApiRequest> = {}): Promise<void> => {
|
||||
return successfulApiCall<void>({
|
||||
endpoint: '/clips/add-note',
|
||||
const addNote = async (parameters: Misskey.entities.ClipsAddNoteRequest, request: Partial<ApiRequest<'clips/add-note'>> = {}): Promise<void> => {
|
||||
return successfulApiCall({
|
||||
endpoint: 'clips/add-note',
|
||||
parameters,
|
||||
user: alice,
|
||||
...request,
|
||||
}, {
|
||||
status: 204,
|
||||
});
|
||||
}) as any as void;
|
||||
};
|
||||
|
||||
type RemoveNoteParam = JTDDataType<typeof RemoveNoteParamDef>;
|
||||
const removeNote = async (parameters: RemoveNoteParam, request: Partial<ApiRequest> = {}): Promise<void> => {
|
||||
return successfulApiCall<void>({
|
||||
endpoint: '/clips/remove-note',
|
||||
const removeNote = async (parameters: Misskey.entities.ClipsRemoveNoteRequest, request: Partial<ApiRequest<'clips/remove-note'>> = {}): Promise<void> => {
|
||||
return successfulApiCall({
|
||||
endpoint: 'clips/remove-note',
|
||||
parameters,
|
||||
user: alice,
|
||||
...request,
|
||||
}, {
|
||||
status: 204,
|
||||
});
|
||||
}) as any as void;
|
||||
};
|
||||
|
||||
type NotesParam = JTDDataType<typeof NotesParamDef>;
|
||||
const notes = async (parameters: Partial<NotesParam>, request: Partial<ApiRequest> = {}): Promise<Note[]> => {
|
||||
return successfulApiCall<Note[]>({
|
||||
endpoint: '/clips/notes',
|
||||
const notes = async (parameters: Misskey.entities.ClipsNotesRequest, request: Partial<ApiRequest<'clips/notes'>> = {}): Promise<Misskey.entities.Note[]> => {
|
||||
return successfulApiCall({
|
||||
endpoint: 'clips/notes',
|
||||
parameters,
|
||||
user: alice,
|
||||
...request,
|
||||
@@ -715,7 +690,7 @@ describe('クリップ', () => {
|
||||
test('として同じノートを二回紐づけることはできない', async () => {
|
||||
await addNote({ clipId: aliceClip.id, noteId: aliceNote.id });
|
||||
await failedApiCall({
|
||||
endpoint: '/clips/add-note',
|
||||
endpoint: 'clips/add-note',
|
||||
parameters: {
|
||||
clipId: aliceClip.id,
|
||||
noteId: aliceNote.id,
|
||||
@@ -733,11 +708,11 @@ describe('クリップ', () => {
|
||||
const noteLimit = DEFAULT_POLICIES.noteEachClipsLimit + 1;
|
||||
const noteList = await Promise.all([...Array(noteLimit)].map((_, i) => post(alice, {
|
||||
text: `test ${i}`,
|
||||
}) as unknown)) as Note[];
|
||||
}) as unknown)) as Misskey.entities.Note[];
|
||||
await Promise.all(noteList.map(s => addNote({ clipId: aliceClip.id, noteId: s.id })));
|
||||
|
||||
await failedApiCall({
|
||||
endpoint: '/clips/add-note',
|
||||
endpoint: 'clips/add-note',
|
||||
parameters: {
|
||||
clipId: aliceClip.id,
|
||||
noteId: aliceNote.id,
|
||||
@@ -751,7 +726,7 @@ describe('クリップ', () => {
|
||||
});
|
||||
|
||||
test('は他人のクリップへ追加できない。', async () => await failedApiCall({
|
||||
endpoint: '/clips/add-note',
|
||||
endpoint: 'clips/add-note',
|
||||
parameters: {
|
||||
clipId: aliceClip.id,
|
||||
noteId: aliceNote.id,
|
||||
@@ -774,18 +749,20 @@ describe('クリップ', () => {
|
||||
code: 'NO_SUCH_NOTE',
|
||||
id: 'fc8c0b49-c7a3-4664-a0a6-b418d386bb8b',
|
||||
} },
|
||||
{ label: '他人のクリップ', user: (): object => bob, assetion: {
|
||||
{ label: '他人のクリップ', user: () => bob, assetion: {
|
||||
code: 'NO_SUCH_CLIP',
|
||||
id: 'd6e76cc0-a1b5-4c7c-a287-73fa9c716dcf',
|
||||
} },
|
||||
])('の追加は$labelだとできない', async ({ parameters, user, assetion }) => failedApiCall({
|
||||
endpoint: '/clips/add-note',
|
||||
endpoint: 'clips/add-note',
|
||||
parameters: {
|
||||
// @ts-expect-error clipId must not be undefined
|
||||
clipId: aliceClip.id,
|
||||
// @ts-expect-error noteId must not be undefined
|
||||
noteId: aliceNote.id,
|
||||
...parameters,
|
||||
},
|
||||
user: (user ?? ((): User => alice))(),
|
||||
user: (user ?? (() => alice))(),
|
||||
}, {
|
||||
status: 400,
|
||||
code: 'INVALID_PARAM',
|
||||
@@ -810,18 +787,20 @@ describe('クリップ', () => {
|
||||
code: 'NO_SUCH_NOTE',
|
||||
id: 'aff017de-190e-434b-893e-33a9ff5049d8', // add-noteと異なる
|
||||
} },
|
||||
{ label: '他人のクリップ', user: (): object => bob, assetion: {
|
||||
{ label: '他人のクリップ', user: () => bob, assetion: {
|
||||
code: 'NO_SUCH_CLIP',
|
||||
id: 'b80525c6-97f7-49d7-a42d-ebccd49cfd52', // add-noteと異なる
|
||||
} },
|
||||
])('の削除は$labelだとできない', async ({ parameters, user, assetion }) => failedApiCall({
|
||||
endpoint: '/clips/remove-note',
|
||||
endpoint: 'clips/remove-note',
|
||||
parameters: {
|
||||
// @ts-expect-error clipId must not be undefined
|
||||
clipId: aliceClip.id,
|
||||
// @ts-expect-error noteId must not be undefined
|
||||
noteId: aliceNote.id,
|
||||
...parameters,
|
||||
},
|
||||
user: (user ?? ((): User => alice))(),
|
||||
user: (user ?? (() => alice))(),
|
||||
}, {
|
||||
status: 400,
|
||||
code: 'INVALID_PARAM',
|
||||
@@ -925,21 +904,22 @@ describe('クリップ', () => {
|
||||
code: 'NO_SUCH_CLIP',
|
||||
id: '1d7645e6-2b6d-4635-b0fe-fe22b0e72e00',
|
||||
} },
|
||||
{ label: '他人のPrivateなクリップから', user: (): object => bob, assertion: {
|
||||
{ label: '他人のPrivateなクリップから', user: () => bob, assertion: {
|
||||
code: 'NO_SUCH_CLIP',
|
||||
id: '1d7645e6-2b6d-4635-b0fe-fe22b0e72e00',
|
||||
} },
|
||||
{ label: '未認証でPrivateなクリップから', user: (): undefined => undefined, assertion: {
|
||||
{ label: '未認証でPrivateなクリップから', user: () => undefined, assertion: {
|
||||
code: 'NO_SUCH_CLIP',
|
||||
id: '1d7645e6-2b6d-4635-b0fe-fe22b0e72e00',
|
||||
} },
|
||||
])('は$labelだと取得できない', async ({ parameters, user, assertion }) => failedApiCall({
|
||||
endpoint: '/clips/notes',
|
||||
endpoint: 'clips/notes',
|
||||
parameters: {
|
||||
// @ts-expect-error clipId must not be undefined
|
||||
clipId: aliceClip.id,
|
||||
...parameters,
|
||||
},
|
||||
user: (user ?? ((): User => alice))(),
|
||||
user: (user ?? (() => alice))(),
|
||||
}, {
|
||||
status: 400,
|
||||
code: 'INVALID_PARAM',
|
||||
|
Reference in New Issue
Block a user