Skip to content

Commit

Permalink
fix? backend testing
Browse files Browse the repository at this point in the history
  • Loading branch information
taiyme committed Dec 28, 2024
1 parent 4bb8c16 commit 551b676
Show file tree
Hide file tree
Showing 45 changed files with 361 additions and 361 deletions.
3 changes: 2 additions & 1 deletion packages/backend/test-server/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { portToPid } from 'pid-port';
import fkill from 'fkill';
import Fastify from 'fastify';
import { NestFactory } from '@nestjs/core';
import { INestApplicationContext } from '@nestjs/common';
import { MainModule } from '@/MainModule.js';
import { ServerService } from '@/server/ServerService.js';
import { loadConfig } from '@/config.js';
import { NestLogger } from '@/NestLogger.js';
import { INestApplicationContext } from '@nestjs/common';

const config = loadConfig();
const originEnv = JSON.stringify(process.env);
Expand Down Expand Up @@ -100,4 +100,5 @@ async function startControllerEndpoints(port = config.port + 1000) {
await fastify.listen({ port: port, host: 'localhost' });
}

// eslint-disable-next-line import/no-default-export
export default launch;
26 changes: 13 additions & 13 deletions packages/backend/test/e2e/2fa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

process.env.NODE_ENV = 'test';

import * as assert from 'assert';
import * as assert from 'node:assert';
import * as crypto from 'node:crypto';
import cbor from 'cbor';
import * as OTPAuth from 'otpauth';
import { loadConfig } from '@/config.js';
import { api, signup } from '../utils.js';
import type {
AuthenticationResponseJSON,
Expand All @@ -19,10 +18,11 @@ import type {
PublicKeyCredentialRequestOptionsJSON,
RegistrationResponseJSON,
} from '@simplewebauthn/types';
import type * as misskey from 'misskey-js';
import type * as Misskey from 'misskey-js';
import { loadConfig } from '@/config.js';

describe('2要素認証', () => {
let alice: misskey.entities.SignupResponse;
let alice: Misskey.entities.SignupResponse;

const config = loadConfig();
const password = 'test';
Expand Down Expand Up @@ -96,10 +96,10 @@ describe('2要素認証', () => {
password,
token: param.token,
name: param.keyName,
credential: <RegistrationResponseJSON>{
credential: {
id: param.credentialId.toString('base64url'),
rawId: param.credentialId.toString('base64url'),
response: <AuthenticatorAttestationResponseJSON>{
response: {
clientDataJSON: Buffer.from(JSON.stringify({
type: 'webauthn.create',
challenge: param.creationOptions.challenge,
Expand All @@ -111,10 +111,10 @@ describe('2要素認証', () => {
attStmt: {},
authData,
}).toString('base64url'),
},
} satisfies AuthenticatorAttestationResponseJSON,
clientExtensionResults: {},
type: 'public-key',
},
} satisfies RegistrationResponseJSON,
};
};

Expand All @@ -136,7 +136,7 @@ describe('2要素認証', () => {
keyName: string,
credentialId: Buffer,
requestOptions: PublicKeyCredentialRequestOptionsJSON,
}): misskey.entities.SigninFlowRequest => {
}): Misskey.entities.SigninFlowRequest => {
// AuthenticatorAssertionResponse.authenticatorData
// https://developer.mozilla.org/en-US/docs/Web/API/AuthenticatorAssertionResponse/authenticatorData
const authenticatorData = Buffer.concat([
Expand All @@ -160,17 +160,17 @@ describe('2要素認証', () => {
return {
username,
password,
credential: <AuthenticationResponseJSON>{
credential: {
id: param.credentialId.toString('base64url'),
rawId: param.credentialId.toString('base64url'),
response: <AuthenticatorAssertionResponseJSON>{
response: {
clientDataJSON: clientDataJSONBuffer.toString('base64url'),
authenticatorData: authenticatorData.toString('base64url'),
signature: signature.toString('base64url'),
},
} satisfies AuthenticatorAssertionResponseJSON,
clientExtensionResults: {},
type: 'public-key',
},
} satisfies AuthenticationResponseJSON,
'g-recaptcha-response': null,
'hcaptcha-response': null,
};
Expand Down
30 changes: 15 additions & 15 deletions packages/backend/test/e2e/antennas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

process.env.NODE_ENV = 'test';

import * as assert from 'assert';
import { DEFAULT_POLICIES } from '@/core/RoleService.js';
import * as assert from 'node:assert';
import {
api,
failedApiCall,
Expand All @@ -18,7 +17,8 @@ import {
uploadFile,
userList,
} from '../utils.js';
import type * as misskey from 'misskey-js';
import type * as Misskey from 'misskey-js';
import { DEFAULT_POLICIES } from '@/core/RoleService.js';

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));
Expand All @@ -28,9 +28,9 @@ describe('アンテナ', () => {
// エンティティとしてのアンテナを主眼においたテストを記述する
// (Antennaを返すエンドポイント、Antennaエンティティを書き換えるエンドポイント、Antennaからノートを取得するエンドポイントをテストする)

type Antenna = misskey.entities.Antenna;
type User = misskey.entities.SignupResponse;
type Note = misskey.entities.Note;
type Antenna = Misskey.entities.Antenna;
type User = Misskey.entities.SignupResponse;
type Note = Misskey.entities.Note;

// アンテナを作成できる最小のパラメタ
const defaultParam = {
Expand All @@ -52,9 +52,9 @@ describe('アンテナ', () => {
let carol: User;

let alicePost: Note;
let aliceList: misskey.entities.UserList;
let bobFile: misskey.entities.DriveFile;
let bobList: misskey.entities.UserList;
let aliceList: Misskey.entities.UserList;
let bobFile: Misskey.entities.DriveFile;
let bobList: Misskey.entities.UserList;

let userNotExplorable: User;
let userLocking: User;
Expand Down Expand Up @@ -232,12 +232,12 @@ describe('アンテナ', () => {
await failedApiCall({
endpoint: 'antennas/create',
parameters: { ...defaultParam, keywords: [[]], excludeKeywords: [[]] },
user: alice
user: alice,
}, {
status: 400,
code: 'EMPTY_KEYWORD',
id: '53ee222e-1ddd-4f9a-92e5-9fb82ddb463a'
})
id: '53ee222e-1ddd-4f9a-92e5-9fb82ddb463a',
});
});
//#endregion
//#region 更新(antennas/update)
Expand Down Expand Up @@ -271,12 +271,12 @@ describe('アンテナ', () => {
await failedApiCall({
endpoint: 'antennas/update',
parameters: { ...defaultParam, antennaId: antenna.id, keywords: [[]], excludeKeywords: [[]] },
user: alice
user: alice,
}, {
status: 400,
code: 'EMPTY_KEYWORD',
id: '721aaff6-4e1b-4d88-8de6-877fae9f68c4'
})
id: '721aaff6-4e1b-4d88-8de6-877fae9f68c4',
});
});

//#endregion
Expand Down
44 changes: 22 additions & 22 deletions packages/backend/test/e2e/api-visibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,56 @@

process.env.NODE_ENV = 'test';

import * as assert from 'assert';
import { UserToken, api, post, signup } from '../utils.js';
import type * as misskey from 'misskey-js';
import * as assert from 'node:assert';
import { type UserToken, api, post, signup } from '../utils.js';
import type * as Misskey from 'misskey-js';

describe('API visibility', () => {
describe('Note visibility', () => {
//#region vars
/** ヒロイン */
let alice: misskey.entities.SignupResponse;
let alice: Misskey.entities.SignupResponse;
/** フォロワー */
let follower: misskey.entities.SignupResponse;
let follower: Misskey.entities.SignupResponse;
/** 非フォロワー */
let other: misskey.entities.SignupResponse;
let other: Misskey.entities.SignupResponse;
/** 非フォロワーでもリプライやメンションをされた人 */
let target: misskey.entities.SignupResponse;
let target: Misskey.entities.SignupResponse;
/** specified mentionでmentionを飛ばされる人 */
let target2: misskey.entities.SignupResponse;
let target2: Misskey.entities.SignupResponse;

/** public-post */
let pub: misskey.entities.Note;
let pub: Misskey.entities.Note;
/** home-post */
let home: misskey.entities.Note;
let home: Misskey.entities.Note;
/** followers-post */
let fol: misskey.entities.Note;
let fol: Misskey.entities.Note;
/** specified-post */
let spe: misskey.entities.Note;
let spe: Misskey.entities.Note;

/** public-reply to target's post */
let pubR: misskey.entities.Note;
let pubR: Misskey.entities.Note;
/** home-reply to target's post */
let homeR: misskey.entities.Note;
let homeR: Misskey.entities.Note;
/** followers-reply to target's post */
let folR: misskey.entities.Note;
let folR: Misskey.entities.Note;
/** specified-reply to target's post */
let speR: misskey.entities.Note;
let speR: Misskey.entities.Note;

/** public-mention to target */
let pubM: misskey.entities.Note;
let pubM: Misskey.entities.Note;
/** home-mention to target */
let homeM: misskey.entities.Note;
let homeM: Misskey.entities.Note;
/** followers-mention to target */
let folM: misskey.entities.Note;
let folM: Misskey.entities.Note;
/** specified-mention to target */
let speM: misskey.entities.Note;
let speM: Misskey.entities.Note;

/** reply target post */
let tgt: misskey.entities.Note;
let tgt: Misskey.entities.Note;
//#endregion

const show = async (noteId: misskey.entities.Note['id'], by?: UserToken) => {
const show = async (noteId: Misskey.entities.Note['id'], by?: UserToken) => {
return await api('notes/show', {
noteId,
}, by);
Expand Down
10 changes: 5 additions & 5 deletions packages/backend/test/e2e/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

process.env.NODE_ENV = 'test';

import * as assert from 'assert';
import { IncomingMessage } from 'http';
import * as assert from 'node:assert';
import {
api,
connectStream,
Expand All @@ -18,11 +17,12 @@ import {
uploadFile,
waitFire,
} from '../utils.js';
import type * as misskey from 'misskey-js';
import type { IncomingMessage } from 'node:http';
import type * as Misskey from 'misskey-js';

describe('API', () => {
let alice: misskey.entities.SignupResponse;
let bob: misskey.entities.SignupResponse;
let alice: Misskey.entities.SignupResponse;
let bob: Misskey.entities.SignupResponse;

beforeAll(async () => {
alice = await signup({ username: 'alice' });
Expand Down
12 changes: 6 additions & 6 deletions packages/backend/test/e2e/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

process.env.NODE_ENV = 'test';

import * as assert from 'assert';
import * as assert from 'node:assert';
import { api, castAsError, post, signup } from '../utils.js';
import type * as misskey from 'misskey-js';
import type * as Misskey from 'misskey-js';

describe('Block', () => {
// alice blocks bob
let alice: misskey.entities.SignupResponse;
let bob: misskey.entities.SignupResponse;
let carol: misskey.entities.SignupResponse;
let alice: Misskey.entities.SignupResponse;
let bob: Misskey.entities.SignupResponse;
let carol: Misskey.entities.SignupResponse;

beforeAll(async () => {
alice = await signup({ username: 'alice' });
Expand Down Expand Up @@ -75,7 +75,7 @@ describe('Block', () => {
const carolNote = await post(carol, { text: 'hi' });

const res = await api('notes/local-timeline', {}, bob);
const body = res.body as misskey.entities.Note[];
const body = res.body as Misskey.entities.Note[];

assert.strictEqual(res.status, 200);
assert.strictEqual(Array.isArray(res.body), true);
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/test/e2e/clips.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

process.env.NODE_ENV = 'test';

import * as assert from 'assert';
import { DEFAULT_POLICIES } from '@/core/RoleService.js';
import { api, ApiRequest, failedApiCall, hiddenNote, post, signup, successfulApiCall } from '../utils.js';
import * as assert from 'node:assert';
import { type ApiRequest, api, failedApiCall, hiddenNote, post, signup, successfulApiCall } from '../utils.js';
import type * as Misskey from 'misskey-js';
import { DEFAULT_POLICIES } from '@/core/RoleService.js';

type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;

Expand Down
10 changes: 5 additions & 5 deletions packages/backend/test/e2e/drive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

process.env.NODE_ENV = 'test';

import * as assert from 'assert';
import * as assert from 'node:assert';
import { api, makeStreamCatcher, post, signup, uploadFile } from '../utils.js';
import type * as misskey from 'misskey-js';
import type * as Misskey from 'misskey-js';

describe('Drive', () => {
let alice: misskey.entities.SignupResponse;
let bob: misskey.entities.SignupResponse;
let alice: Misskey.entities.SignupResponse;
let bob: Misskey.entities.SignupResponse;

beforeAll(async () => {
alice = await signup({ username: 'alice' });
Expand All @@ -23,7 +23,7 @@ describe('Drive', () => {

const marker = Math.random().toString();

const url = 'https://raw.githubusercontent.com/misskey-dev/misskey/develop/packages/backend/test/resources/192.jpg';
const url = 'https://raw.githubusercontent.com/taiyme/misskey/taiyme/packages/backend/test/resources/192.jpg';

const catcher = makeStreamCatcher(
alice,
Expand Down
Loading

0 comments on commit 551b676

Please sign in to comment.