forked from wangziqi/gongxue-base
refactor: resolve remaining field audit issues
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { getDataSourceToken } from '@nestjs/typeorm';
|
||||
import { DatabaseMigrationsService } from './database-migrations.service';
|
||||
|
||||
describe('DatabaseMigrationsService — classroom status normalization', () => {
|
||||
it('normalizes legacy persisted statuses to available', async () => {
|
||||
const runner = {
|
||||
connect: jest.fn(),
|
||||
release: jest.fn(),
|
||||
getTables: jest.fn().mockResolvedValue([{ name: 'classrooms' }]),
|
||||
query: jest.fn().mockResolvedValue(undefined),
|
||||
};
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
DatabaseMigrationsService,
|
||||
{
|
||||
provide: getDataSourceToken(),
|
||||
useValue: {
|
||||
options: { type: 'better-sqlite3' },
|
||||
createQueryRunner: jest.fn().mockReturnValue(runner),
|
||||
},
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
const service = module.get(DatabaseMigrationsService) as DatabaseMigrationsService & {
|
||||
normalizeClassroomStatuses(): Promise<void>;
|
||||
};
|
||||
|
||||
await service.normalizeClassroomStatuses();
|
||||
|
||||
expect(runner.query).toHaveBeenCalledWith(
|
||||
expect.stringContaining("status NOT IN ('available', 'maintenance', 'archived')"),
|
||||
);
|
||||
expect(runner.release).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user