mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-24 03:05:12 +00:00
c2370a1be6
* chore: Add the SPDX information to each file Add copyright and licensing information as defined in version 3.0 of the REUSE Specification. * tweak format --------- Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
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 type { MetasRepository } from '@/models/index.js';
|
|
import { DI } from '@/di-symbols.js';
|
|
import { MetaService } from '@/core/MetaService.js';
|
|
import { CoreModule } from '@/core/CoreModule.js';
|
|
import type { DataSource } from 'typeorm';
|
|
import type { TestingModule } from '@nestjs/testing';
|
|
|
|
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 });
|
|
|
|
// Make it cached
|
|
await metaService.fetch();
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await app.close();
|
|
});
|
|
|
|
test('fetch (cache)', async () => {
|
|
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);
|
|
});
|
|
|
|
test('fetch (force)', async () => {
|
|
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);
|
|
});
|
|
});
|