Skip to content

Commit

Permalink
fix: backend type check
Browse files Browse the repository at this point in the history
  • Loading branch information
slofp committed Jul 31, 2024
1 parent f651ae0 commit d484777
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 25 deletions.
23 changes: 21 additions & 2 deletions packages/backend/src/models/json-schema/emoji-log.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
const emojiChangeInfoData = [
{
type: 'array',
optional: false, nullable: false,
items: {
type: 'string',
optional: false, nullable: false,
},
},
{
type: 'string',
optional: false, nullable: false,
},
{
type: 'boolean',
optional: false, nullable: false,
},
] as const;

export const packedEmojiChangeInfoSchema = {
type: 'object',
properties: {
before: {
type: 'any',
oneOf: emojiChangeInfoData,
optional: false, nullable: false,
},
after: {
type: 'any',
oneOf: emojiChangeInfoData,
optional: false, nullable: false,
},
},
Expand Down
11 changes: 3 additions & 8 deletions packages/backend/test/e2e/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,6 @@ describe('Note', () => {
displayOrder: 0,
target: 'manual',
condFormula: {},
isAdministrator: false,
isModerator: false,
permissionGroup: 'Normal',
isPublic: false,
isExplorable: false,
Expand Down Expand Up @@ -775,8 +773,7 @@ describe('Note', () => {
displayOrder: 0,
target: 'manual',
condFormula: {},
isAdministrator: false,
isModerator: false,
permissionGroup: 'Normal',
isPublic: false,
isExplorable: false,
asBadge: false,
Expand Down Expand Up @@ -829,8 +826,7 @@ describe('Note', () => {
displayOrder: 0,
target: 'manual',
condFormula: {},
isAdministrator: false,
isModerator: false,
permissionGroup: 'Normal',
isPublic: false,
isExplorable: false,
asBadge: false,
Expand Down Expand Up @@ -885,8 +881,7 @@ describe('Note', () => {
displayOrder: 0,
target: 'manual',
condFormula: {},
isAdministrator: false,
isModerator: false,
permissionGroup: 'Normal',
isPublic: false,
isExplorable: false,
asBadge: false,
Expand Down
5 changes: 2 additions & 3 deletions packages/backend/test/e2e/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,10 +610,8 @@ describe('ユーザー', () => {
});
test.each([
{ label: 'Administratorになっている', user: () => userAdmin, me: () => userAdmin, selector: (user: misskey.entities.MeDetailed) => user.isAdmin },
// @ts-expect-error UserDetailedNotMe doesn't include isAdmin
{ label: '自分以外から見たときはAdministratorか判定できない', user: () => userAdmin, selector: (user: misskey.entities.UserDetailedNotMe) => user.isAdmin, expected: () => undefined },
{ label: 'Moderatorになっている', user: () => userModerator, me: () => userModerator, selector: (user: misskey.entities.MeDetailed) => user.isModerator },
// @ts-expect-error UserDetailedNotMe doesn't include isModerator
{ label: '自分以外から見たときはModeratorか判定できない', user: () => userModerator, selector: (user: misskey.entities.UserDetailedNotMe) => user.isModerator, expected: () => undefined },
{ label: 'サイレンスになっている', user: () => userSilenced, selector: (user: misskey.entities.UserDetailed) => user.isSilenced },
// FIXME: 落ちる
Expand Down Expand Up @@ -645,7 +643,8 @@ describe('ユーザー', () => {
color: rolePublic.color,
iconUrl: rolePublic.iconUrl,
description: rolePublic.description,
permissionGroup: rolePublic.permissionGroup,
isModerator: rolePublic.isModerator,
isAdministrator: rolePublic.isAdministrator,
displayOrder: rolePublic.displayOrder,
}]);
});
Expand Down
1 change: 1 addition & 0 deletions packages/backend/test/unit/NoteCreateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('NoteCreateService', () => {
replyUserHost: null,
renoteUserId: null,
renoteUserHost: null,
updatedAt: null,
};

const poll: IPoll = {
Expand Down
14 changes: 7 additions & 7 deletions packages/backend/test/unit/activitypub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ describe('ActivityPub', () => {
});
});

describe('JSON-LD', () =>{
describe('JSON-LD', () => {
test('Compaction', async () => {
const jsonLd = jsonLdService.use();

Expand Down Expand Up @@ -494,7 +494,7 @@ describe('ActivityPub', () => {
await createRandomRemoteUser(resolver, personService),
imageObject,
);
assert.ok(!driveFile.isLink);
assert.ok(!driveFile?.isLink);

const sensitiveImageObject: IApDocument = {
type: 'Document',
Expand All @@ -507,7 +507,7 @@ describe('ActivityPub', () => {
await createRandomRemoteUser(resolver, personService),
sensitiveImageObject,
);
assert.ok(!sensitiveDriveFile.isLink);
assert.ok(!sensitiveDriveFile?.isLink);
});

test('cacheRemoteFiles=false disables caching', async () => {
Expand All @@ -523,7 +523,7 @@ describe('ActivityPub', () => {
await createRandomRemoteUser(resolver, personService),
imageObject,
);
assert.ok(driveFile.isLink);
assert.ok(driveFile?.isLink);

const sensitiveImageObject: IApDocument = {
type: 'Document',
Expand All @@ -536,7 +536,7 @@ describe('ActivityPub', () => {
await createRandomRemoteUser(resolver, personService),
sensitiveImageObject,
);
assert.ok(sensitiveDriveFile.isLink);
assert.ok(sensitiveDriveFile?.isLink);
});

test('cacheRemoteSensitiveFiles=false only affects sensitive files', async () => {
Expand All @@ -552,7 +552,7 @@ describe('ActivityPub', () => {
await createRandomRemoteUser(resolver, personService),
imageObject,
);
assert.ok(!driveFile.isLink);
assert.ok(!driveFile?.isLink);

const sensitiveImageObject: IApDocument = {
type: 'Document',
Expand All @@ -565,7 +565,7 @@ describe('ActivityPub', () => {
await createRandomRemoteUser(resolver, personService),
sensitiveImageObject,
);
assert.ok(sensitiveDriveFile.isLink);
assert.ok(sensitiveDriveFile?.isLink);
});
});
});
1 change: 1 addition & 0 deletions packages/backend/test/unit/misc/is-renote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const base: MiNote = {
replyUserHost: null,
renoteUserId: null,
renoteUserHost: null,
updatedAt: null,
};

describe('misc:is-renote', () => {
Expand Down
5 changes: 2 additions & 3 deletions packages/backend/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export const play = async (user: UserToken, play: Partial<misskey.entities.Flash
summary: '',
title: 'test',
...play,
achievements: []
}, user);
return res.body;
};
Expand Down Expand Up @@ -247,7 +248,7 @@ export const channel = async (user: UserToken, channel: Partial<misskey.entities
return res.body;
};

export const role = async (user: UserToken, role: Partial<misskey.entities.Role> = {}, policies: any = {}): Promise<misskey.entities.Role> => {
export const role = async (user: UserToken, role: Partial<misskey.entities.AdminRolesCreateRequest> = {}, policies: any = {}): Promise<misskey.entities.Role> => {
const res = await api('admin/roles/create', {
asBadge: false,
canEditMembersByModerator: false,
Expand All @@ -259,8 +260,6 @@ export const role = async (user: UserToken, role: Partial<misskey.entities.Role>
description: '',
displayOrder: 0,
iconUrl: null,
isAdministrator: false,
isModerator: false,
permissionGroup: 'Normal',
isPublic: false,
name: 'New Role',
Expand Down
60 changes: 60 additions & 0 deletions packages/misskey-js/etc/misskey-js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ type AdminEmojiDeleteBulkRequest = operations['admin___emoji___delete-bulk']['re
// @public (undocumented)
type AdminEmojiDeleteRequest = operations['admin___emoji___delete']['requestBody']['content']['application/json'];

// @public (undocumented)
type AdminEmojiGetEmojiLogRequest = operations['admin___emoji___get-emoji-log']['requestBody']['content']['application/json'];

// @public (undocumented)
type AdminEmojiGetEmojiLogResponse = operations['admin___emoji___get-emoji-log']['responses']['200']['content']['application/json'];

// @public (undocumented)
type AdminEmojiImportZipRequest = operations['admin___emoji___import-zip']['requestBody']['content']['application/json'];

Expand Down Expand Up @@ -1033,6 +1039,18 @@ type EmojiAdded = {
emoji: EmojiDetailed;
};

// @public (undocumented)
type EmojiChangeInfo = components['schemas']['EmojiChangeInfo'];

// @public (undocumented)
type EmojiChangeLog = components['schemas']['EmojiChangeLog'];

// @public (undocumented)
type EmojiChangeLogs = components['schemas']['EmojiChangeLogs'];

// @public (undocumented)
type EmojiChangesProperty = components['schemas']['EmojiChangesProperty'];

// @public (undocumented)
type EmojiDeleted = {
emojis: EmojiDetailed[];
Expand Down Expand Up @@ -1199,6 +1217,8 @@ declare namespace entities {
AdminEmojiSetCategoryBulkRequest,
AdminEmojiSetLicenseBulkRequest,
AdminEmojiUpdateRequest,
AdminEmojiGetEmojiLogRequest,
AdminEmojiGetEmojiLogResponse,
AdminFederationDeleteAllFilesRequest,
AdminFederationRefreshRemoteInstanceMetadataRequest,
AdminFederationRemoveAllFollowingRequest,
Expand Down Expand Up @@ -1487,6 +1507,7 @@ declare namespace entities {
IRegistryKeysRequest,
IRegistryKeysResponse,
IRegistryRemoveRequest,
IRegistryRemoveAllKeysInScopeRequest,
IRegistryScopesWithDomainResponse,
IRegistrySetRequest,
IRevokeTokenRequest,
Expand Down Expand Up @@ -1540,6 +1561,7 @@ declare namespace entities {
NotesCreateRequest,
NotesCreateResponse,
NotesDeleteRequest,
NotesUpdateRequest,
NotesFavoritesCreateRequest,
NotesFavoritesDeleteRequest,
NotesFeaturedRequest,
Expand All @@ -1550,6 +1572,8 @@ declare namespace entities {
NotesHybridTimelineResponse,
NotesLocalTimelineRequest,
NotesLocalTimelineResponse,
NotesRelationalTimelineRequest,
NotesRelationalTimelineResponse,
NotesMentionsRequest,
NotesMentionsResponse,
NotesPollsRecommendationRequest,
Expand Down Expand Up @@ -1607,13 +1631,18 @@ declare namespace entities {
PingResponse,
PinnedUsersResponse,
PromoReadRequest,
RolesListRequest,
RolesListResponse,
RolesShowRequest,
RolesShowResponse,
RolesUsersRequest,
RolesUsersResponse,
RolesNotesRequest,
RolesNotesResponse,
RolesAddRequest,
RolesAssignRequest,
RolesUnassignRequest,
RolesUpdateRequest,
RequestResetPasswordRequest,
ResetPasswordRequest,
ServerInfoResponse,
Expand Down Expand Up @@ -1737,6 +1766,10 @@ declare namespace entities {
EmojiSimple,
EmojiDetailed,
Flash,
EmojiChangeInfo,
EmojiChangesProperty,
EmojiChangeLog,
EmojiChangeLogs,
Signin,
RoleCondFormulaLogics,
RoleCondFormulaValueNot,
Expand Down Expand Up @@ -2192,6 +2225,9 @@ type IRegistryKeysWithTypeRequest = operations['i___registry___keys-with-type'][
// @public (undocumented)
type IRegistryKeysWithTypeResponse = operations['i___registry___keys-with-type']['responses']['200']['content']['application/json'];

// @public (undocumented)
type IRegistryRemoveAllKeysInScopeRequest = operations['i___registry___remove-all-keys-in-scope']['requestBody']['content']['application/json'];

// @public (undocumented)
type IRegistryRemoveRequest = operations['i___registry___remove']['requestBody']['content']['application/json'];

Expand Down Expand Up @@ -2524,6 +2560,12 @@ type NotesReactionsRequest = operations['notes___reactions']['requestBody']['con
// @public (undocumented)
type NotesReactionsResponse = operations['notes___reactions']['responses']['200']['content']['application/json'];

// @public (undocumented)
type NotesRelationalTimelineRequest = operations['notes___relational-timeline']['requestBody']['content']['application/json'];

// @public (undocumented)
type NotesRelationalTimelineResponse = operations['notes___relational-timeline']['responses']['200']['content']['application/json'];

// @public (undocumented)
type NotesRenotesRequest = operations['notes___renotes']['requestBody']['content']['application/json'];

Expand Down Expand Up @@ -2587,6 +2629,9 @@ type NotesTranslateResponse = operations['notes___translate']['responses']['200'
// @public (undocumented)
type NotesUnrenoteRequest = operations['notes___unrenote']['requestBody']['content']['application/json'];

// @public (undocumented)
type NotesUpdateRequest = operations['notes___update']['requestBody']['content']['application/json'];

// @public (undocumented)
type NotesUserListTimelineRequest = operations['notes___user-list-timeline']['requestBody']['content']['application/json'];

Expand Down Expand Up @@ -2783,6 +2828,15 @@ type RoleLite = components['schemas']['RoleLite'];
// @public (undocumented)
type RolePolicies = components['schemas']['RolePolicies'];

// @public (undocumented)
type RolesAddRequest = operations['roles___add']['requestBody']['content']['application/json'];

// @public (undocumented)
type RolesAssignRequest = operations['roles___assign']['requestBody']['content']['application/json'];

// @public (undocumented)
type RolesListRequest = operations['roles___list']['requestBody']['content']['application/json'];

// @public (undocumented)
type RolesListResponse = operations['roles___list']['responses']['200']['content']['application/json'];

Expand All @@ -2798,6 +2852,12 @@ type RolesShowRequest = operations['roles___show']['requestBody']['content']['ap
// @public (undocumented)
type RolesShowResponse = operations['roles___show']['responses']['200']['content']['application/json'];

// @public (undocumented)
type RolesUnassignRequest = operations['roles___unassign']['requestBody']['content']['application/json'];

// @public (undocumented)
type RolesUpdateRequest = operations['roles___update']['requestBody']['content']['application/json'];

// @public (undocumented)
type RolesUsersRequest = operations['roles___users']['requestBody']['content']['application/json'];

Expand Down
4 changes: 2 additions & 2 deletions packages/misskey-js/src/autogen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4662,8 +4662,8 @@ export type components = {
isLiked?: boolean;
};
EmojiChangeInfo: {
before: Record<string, never>;
after: Record<string, never>;
before: string[] | string | boolean;
after: string[] | string | boolean;
};
EmojiChangesProperty: {
type: string;
Expand Down

0 comments on commit d484777

Please sign in to comment.