2023-07-27 08:31:52 +03:00
|
|
|
/*
|
2024-02-13 17:59:27 +02:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 08:31:52 +03:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-09-20 22:58:32 +03:00
|
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
|
|
|
|
import { jest } from '@jest/globals';
|
|
|
|
import { Test } from '@nestjs/testing';
|
|
|
|
import { GlobalModule } from '@/GlobalModule.js';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
|
|
|
import { MetaService } from '@/core/MetaService.js';
|
|
|
|
import { CoreModule } from '@/core/CoreModule.js';
|
|
|
|
import type { TestingModule } from '@nestjs/testing';
|
2024-01-08 10:43:52 +02:00
|
|
|
import type { DataSource } from 'typeorm';
|
2022-09-20 22:58:32 +03:00
|
|
|
|
|
|
|
describe('MetaService', () => {
|
|
|
|
let app: TestingModule;
|
|
|
|
let metaService: MetaService;
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
app = await Test.createTestingModule({
|
|
|
|
imports: [
|
|
|
|
GlobalModule,
|
|
|
|
CoreModule,
|
|
|
|
],
|
|
|
|
}).compile();
|
|
|
|
|
|
|
|
app.enableShutdownHooks();
|
|
|
|
|
|
|
|
metaService = app.get<MetaService>(MetaService, { strict: false });
|
2022-12-14 07:26:25 +02:00
|
|
|
|
|
|
|
// Make it cached
|
|
|
|
await metaService.fetch();
|
2022-09-20 22:58:32 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
await app.close();
|
|
|
|
});
|
|
|
|
|
2023-02-02 11:18:25 +02:00
|
|
|
test('fetch (cache)', async () => {
|
2022-09-20 22:58:32 +03:00
|
|
|
const db = app.get<DataSource>(DI.db);
|
|
|
|
const spy = jest.spyOn(db, 'transaction');
|
|
|
|
|
|
|
|
const result = await metaService.fetch();
|
|
|
|
|
|
|
|
expect(result.id).toBe('x');
|
|
|
|
expect(spy).toHaveBeenCalledTimes(0);
|
|
|
|
});
|
2022-09-21 22:59:58 +03:00
|
|
|
|
2023-02-02 11:18:25 +02:00
|
|
|
test('fetch (force)', async () => {
|
2022-09-20 22:58:32 +03:00
|
|
|
const db = app.get<DataSource>(DI.db);
|
|
|
|
const spy = jest.spyOn(db, 'transaction');
|
|
|
|
|
|
|
|
const result = await metaService.fetch(true);
|
|
|
|
|
|
|
|
expect(result.id).toBe('x');
|
|
|
|
expect(spy).toHaveBeenCalledTimes(1);
|
2022-12-14 07:26:25 +02:00
|
|
|
});
|
2022-09-20 22:58:32 +03:00
|
|
|
});
|