32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { getMetadataArgsStorage } from 'typeorm';
|
|
import { User } from '../../users/entities/user.entity';
|
|
|
|
describe('AddHelpTextsEnabled1785520800000', () => {
|
|
it('adds a reversible enabled-by-default user preference', async () => {
|
|
const migrationModule = require('./1785520800000-AddHelpTextsEnabled');
|
|
const migration = new migrationModule.AddHelpTextsEnabled1785520800000();
|
|
const queryRunner = { query: jest.fn() } as any;
|
|
|
|
await migration.up(queryRunner);
|
|
expect(queryRunner.query).toHaveBeenCalledWith(
|
|
'ALTER TABLE "user" ADD "helpTextsEnabled" boolean NOT NULL DEFAULT true',
|
|
);
|
|
|
|
queryRunner.query.mockClear();
|
|
await migration.down(queryRunner);
|
|
expect(queryRunner.query).toHaveBeenCalledWith(
|
|
'ALTER TABLE "user" DROP COLUMN "helpTextsEnabled"',
|
|
);
|
|
});
|
|
|
|
it('keeps the user entity default aligned with the migration', () => {
|
|
const column = getMetadataArgsStorage().columns.find(
|
|
(candidate) =>
|
|
candidate.target === User &&
|
|
candidate.propertyName === 'helpTextsEnabled',
|
|
);
|
|
|
|
expect(column?.options).toMatchObject({ type: Boolean, default: true });
|
|
});
|
|
});
|