test(server): move tests out of src folder (#4366)

This commit is contained in:
LongYinan
2023-09-15 00:34:14 -07:00
committed by GitHub
parent b5e8fecfd0
commit 1aec1ce7d0
36 changed files with 233 additions and 159 deletions

View File

@@ -0,0 +1,46 @@
/// <reference types="../src/global.d.ts" />
import { Test, TestingModule } from '@nestjs/testing';
import ava, { TestFn } from 'ava';
import { ConfigModule } from '../src/config';
import { SessionModule, SessionService } from '../src/session';
const test = ava as TestFn<{
session: SessionService;
app: TestingModule;
}>;
test.beforeEach(async t => {
const module = await Test.createTestingModule({
imports: [
ConfigModule.forRoot({
redis: {
enabled: false,
},
}),
SessionModule,
],
}).compile();
const session = module.get(SessionService);
t.context.app = module;
t.context.session = session;
});
test.afterEach.always(async t => {
await t.context.app.close();
});
test('should be able to set session', async t => {
const { session } = t.context;
await session.set('test', 'value');
t.is(await session.get('test'), 'value');
});
test('should be expired by ttl', async t => {
const { session } = t.context;
await session.set('test', 'value', 100);
t.is(await session.get('test'), 'value');
await new Promise(resolve => setTimeout(resolve, 500));
t.is(await session.get('test'), undefined);
});