Merge remote-tracking branch 'origin/develop' into fetch-outbox
This commit is contained in:
@@ -5,7 +5,7 @@ export const getValidator = (paramDef: Schema) => {
|
||||
const ajv = new Ajv({
|
||||
useDefaults: true,
|
||||
});
|
||||
ajv.addFormat('misskey:id', /^[a-zA-Z0-9]+$/);
|
||||
ajv.addFormat('misskey:id', /^[a-zA-Z0-9]+$/);
|
||||
|
||||
return ajv.compile(paramDef);
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ describe('DriveService', () => {
|
||||
test('delete a file', async () => {
|
||||
s3Mock.on(DeleteObjectCommand)
|
||||
.resolves({} as DeleteObjectCommandOutput);
|
||||
|
||||
|
||||
await driveService.deleteObjectStorageFile('peace of the world');
|
||||
});
|
||||
|
||||
|
109
packages/backend/test/unit/FetchInstanceMetadataService.ts
Normal file
109
packages/backend/test/unit/FetchInstanceMetadataService.ts
Normal file
@@ -0,0 +1,109 @@
|
||||
process.env.NODE_ENV = 'test';
|
||||
|
||||
import { jest } from '@jest/globals';
|
||||
import { ModuleMocker } from 'jest-mock';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import { GlobalModule } from '@/GlobalModule.js';
|
||||
import { FetchInstanceMetadataService } from '@/core/FetchInstanceMetadataService.js';
|
||||
import { FederatedInstanceService } from '@/core/FederatedInstanceService.js';
|
||||
import { HttpRequestService } from '@/core/HttpRequestService.js';
|
||||
import { LoggerService } from '@/core/LoggerService.js';
|
||||
import { UtilityService } from '@/core/UtilityService.js';
|
||||
import { IdService } from '@/core/IdService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import type { TestingModule } from '@nestjs/testing';
|
||||
import type { MockFunctionMetadata } from 'jest-mock';
|
||||
import { Redis } from 'ioredis'
|
||||
|
||||
function mockRedis() {
|
||||
const hash = {};
|
||||
const set = jest.fn((key, value) => {
|
||||
const ret = hash[key];
|
||||
hash[key] = value;
|
||||
return ret;
|
||||
});
|
||||
return set;
|
||||
}
|
||||
|
||||
describe('FetchInstanceMetadataService', () => {
|
||||
let app: TestingModule;
|
||||
let fetchInstanceMetadataService: jest.Mocked<FetchInstanceMetadataService>;
|
||||
let federatedInstanceService: jest.Mocked<FederatedInstanceService>;
|
||||
let httpRequestService: jest.Mocked<HttpRequestService>;
|
||||
let redisClient: jest.Mocked<Redis.Redis>;
|
||||
|
||||
beforeAll(async () => {
|
||||
app = await Test
|
||||
.createTestingModule({
|
||||
imports: [
|
||||
GlobalModule,
|
||||
],
|
||||
providers: [
|
||||
FetchInstanceMetadataService,
|
||||
LoggerService,
|
||||
UtilityService,
|
||||
IdService,
|
||||
],
|
||||
})
|
||||
.useMocker((token) => {
|
||||
if (token === HttpRequestService) {
|
||||
return { getJson: jest.fn(), getHtml: jest.fn(), send: jest.fn(), };
|
||||
} else if (token === FederatedInstanceService) {
|
||||
return { fetch: jest.fn() };
|
||||
} else if (token === DI.redis) {
|
||||
return mockRedis;
|
||||
}})
|
||||
.compile();
|
||||
|
||||
app.enableShutdownHooks();
|
||||
|
||||
fetchInstanceMetadataService = app.get<FetchInstanceMetadataService>(FetchInstanceMetadataService);
|
||||
federatedInstanceService = app.get<FederatedInstanceService>(FederatedInstanceService) as jest.Mocked<FederatedInstanceService>;
|
||||
redisClient = app.get<Redis.Redis>(DI.redis) as jest.Mocked<Redis.Redis>;
|
||||
httpRequestService = app.get<HttpRequestService>(HttpRequestService) as jest.Mocked<HttpRequestService>;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await app.close();
|
||||
});
|
||||
|
||||
test('Lock and update', async () => {
|
||||
redisClient.set = mockRedis();
|
||||
const now = Date.now();
|
||||
federatedInstanceService.fetch.mockReturnValue({ infoUpdatedAt: { getTime: () => { return now - 10 * 1000 * 60 * 60 * 24; } } });
|
||||
httpRequestService.getJson.mockImplementation(() => { throw Error(); });
|
||||
const tryLockSpy = jest.spyOn(fetchInstanceMetadataService, 'tryLock');
|
||||
const unlockSpy = jest.spyOn(fetchInstanceMetadataService, 'unlock');
|
||||
await fetchInstanceMetadataService.fetchInstanceMetadata({ host: "example.com" });
|
||||
expect(tryLockSpy).toHaveBeenCalledTimes(1);
|
||||
expect(unlockSpy).toHaveBeenCalledTimes(1);
|
||||
expect(federatedInstanceService.fetch).toHaveBeenCalledTimes(1);
|
||||
expect(httpRequestService.getJson).toHaveBeenCalled();
|
||||
});
|
||||
test("Lock and don't update", async () => {
|
||||
redisClient.set = mockRedis();
|
||||
const now = Date.now();
|
||||
federatedInstanceService.fetch.mockReturnValue({ infoUpdatedAt: { getTime: () => now } });
|
||||
httpRequestService.getJson.mockImplementation(() => { throw Error(); });
|
||||
const tryLockSpy = jest.spyOn(fetchInstanceMetadataService, 'tryLock');
|
||||
const unlockSpy = jest.spyOn(fetchInstanceMetadataService, 'unlock');
|
||||
await fetchInstanceMetadataService.fetchInstanceMetadata({ host: "example.com" });
|
||||
expect(tryLockSpy).toHaveBeenCalledTimes(1);
|
||||
expect(unlockSpy).toHaveBeenCalledTimes(1);
|
||||
expect(federatedInstanceService.fetch).toHaveBeenCalledTimes(1);
|
||||
expect(httpRequestService.getJson).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
test('Do nothing when lock not acquired', async () => {
|
||||
redisClient.set = mockRedis();
|
||||
federatedInstanceService.fetch.mockReturnValue({ infoUpdatedAt: { getTime: () => now - 10 * 1000 * 60 * 60 * 24 } });
|
||||
httpRequestService.getJson.mockImplementation(() => { throw Error(); });
|
||||
const tryLockSpy = jest.spyOn(fetchInstanceMetadataService, 'tryLock');
|
||||
const unlockSpy = jest.spyOn(fetchInstanceMetadataService, 'unlock');
|
||||
await fetchInstanceMetadataService.tryLock("example.com");
|
||||
await fetchInstanceMetadataService.fetchInstanceMetadata({ host: "example.com" });
|
||||
expect(tryLockSpy).toHaveBeenCalledTimes(2);
|
||||
expect(unlockSpy).toHaveBeenCalledTimes(0);
|
||||
expect(federatedInstanceService.fetch).toHaveBeenCalledTimes(0);
|
||||
expect(httpRequestService.getJson).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
});
|
@@ -94,7 +94,7 @@ describe('FileInfoService', () => {
|
||||
orientation: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test('Generic APNG', async () => {
|
||||
const path = `${resources}/anime.png`;
|
||||
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
|
||||
@@ -114,7 +114,7 @@ describe('FileInfoService', () => {
|
||||
orientation: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test('Generic AGIF', async () => {
|
||||
const path = `${resources}/anime.gif`;
|
||||
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
|
||||
@@ -134,7 +134,7 @@ describe('FileInfoService', () => {
|
||||
orientation: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test('PNG with alpha', async () => {
|
||||
const path = `${resources}/with-alpha.png`;
|
||||
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
|
||||
@@ -154,7 +154,7 @@ describe('FileInfoService', () => {
|
||||
orientation: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test('Generic SVG', async () => {
|
||||
const path = `${resources}/image.svg`;
|
||||
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
|
||||
@@ -174,7 +174,7 @@ describe('FileInfoService', () => {
|
||||
orientation: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test('SVG with XML definition', async () => {
|
||||
// https://github.com/misskey-dev/misskey/issues/4413
|
||||
const path = `${resources}/with-xml-def.svg`;
|
||||
@@ -195,7 +195,7 @@ describe('FileInfoService', () => {
|
||||
orientation: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test('Dimension limit', async () => {
|
||||
const path = `${resources}/25000x25000.png`;
|
||||
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
|
||||
@@ -215,7 +215,7 @@ describe('FileInfoService', () => {
|
||||
orientation: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test('Rotate JPEG', async () => {
|
||||
const path = `${resources}/rotate.jpg`;
|
||||
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
|
||||
@@ -257,7 +257,7 @@ describe('FileInfoService', () => {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test('WAV', async () => {
|
||||
const path = `${resources}/kick_gaba7.wav`;
|
||||
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
|
||||
@@ -277,7 +277,7 @@ describe('FileInfoService', () => {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test('AAC', async () => {
|
||||
const path = `${resources}/kick_gaba7.aac`;
|
||||
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
|
||||
@@ -297,7 +297,7 @@ describe('FileInfoService', () => {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test('FLAC', async () => {
|
||||
const path = `${resources}/kick_gaba7.flac`;
|
||||
const info = await fileInfoService.getFileInfo(path, { skipSensitiveDetection: true }) as any;
|
||||
@@ -317,7 +317,7 @@ describe('FileInfoService', () => {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
* video/webmとして検出されてしまう
|
||||
test('WEBM AUDIO', async () => {
|
||||
|
@@ -61,7 +61,7 @@ describe('RelayService', () => {
|
||||
await app.close();
|
||||
});
|
||||
|
||||
test('addRelay', async () => {
|
||||
test('addRelay', async () => {
|
||||
const result = await relayService.addRelay('https://example.com');
|
||||
|
||||
expect(result.inbox).toBe('https://example.com');
|
||||
@@ -72,7 +72,7 @@ describe('RelayService', () => {
|
||||
//expect(queueService.deliver.mock.lastCall![0].username).toBe('relay.actor');
|
||||
});
|
||||
|
||||
test('listRelay', async () => {
|
||||
test('listRelay', async () => {
|
||||
const result = await relayService.listRelay();
|
||||
|
||||
expect(result.length).toBe(1);
|
||||
@@ -80,7 +80,7 @@ describe('RelayService', () => {
|
||||
expect(result[0].status).toBe('requesting');
|
||||
});
|
||||
|
||||
test('removeRelay: succ', async () => {
|
||||
test('removeRelay: succ', async () => {
|
||||
await relayService.removeRelay('https://example.com');
|
||||
|
||||
expect(queueService.deliver).toHaveBeenCalled();
|
||||
@@ -93,7 +93,7 @@ describe('RelayService', () => {
|
||||
expect(list.length).toBe(0);
|
||||
});
|
||||
|
||||
test('removeRelay: fail', async () => {
|
||||
test('removeRelay: fail', async () => {
|
||||
await expect(relayService.removeRelay('https://x.example.com'))
|
||||
.rejects.toThrow('relay not found');
|
||||
});
|
||||
|
@@ -475,16 +475,16 @@ describe('Chart', () => {
|
||||
await testIntersectionChart.addA('bob');
|
||||
await testIntersectionChart.addB('carol');
|
||||
await testIntersectionChart.save();
|
||||
|
||||
|
||||
const chartHours = await testIntersectionChart.getChart('hour', 3, null);
|
||||
const chartDays = await testIntersectionChart.getChart('day', 3, null);
|
||||
|
||||
|
||||
assert.deepStrictEqual(chartHours, {
|
||||
a: [2, 0, 0],
|
||||
b: [1, 0, 0],
|
||||
aAndB: [0, 0, 0],
|
||||
});
|
||||
|
||||
|
||||
assert.deepStrictEqual(chartDays, {
|
||||
a: [2, 0, 0],
|
||||
b: [1, 0, 0],
|
||||
@@ -498,16 +498,16 @@ describe('Chart', () => {
|
||||
await testIntersectionChart.addB('carol');
|
||||
await testIntersectionChart.addB('alice');
|
||||
await testIntersectionChart.save();
|
||||
|
||||
|
||||
const chartHours = await testIntersectionChart.getChart('hour', 3, null);
|
||||
const chartDays = await testIntersectionChart.getChart('day', 3, null);
|
||||
|
||||
|
||||
assert.deepStrictEqual(chartHours, {
|
||||
a: [2, 0, 0],
|
||||
b: [2, 0, 0],
|
||||
aAndB: [1, 0, 0],
|
||||
});
|
||||
|
||||
|
||||
assert.deepStrictEqual(chartDays, {
|
||||
a: [2, 0, 0],
|
||||
b: [2, 0, 0],
|
||||
|
Reference in New Issue
Block a user