Merge branch 'feature/manager-guide'
This commit is contained in:
24
myteamwallet_backend/src/auth/dto/auth-update.dto.spec.ts
Normal file
24
myteamwallet_backend/src/auth/dto/auth-update.dto.spec.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { validate } from 'class-validator';
|
||||
import { AuthUpdateDto } from './auth-update.dto';
|
||||
|
||||
describe('AuthUpdateDto help preference', () => {
|
||||
it('rejects a non-boolean helpTextsEnabled value', async () => {
|
||||
const dto = Object.assign(new AuthUpdateDto(), {
|
||||
helpTextsEnabled: 'yes',
|
||||
});
|
||||
|
||||
const errors = await validate(dto);
|
||||
|
||||
expect(errors.some((error) => error.property === 'helpTextsEnabled')).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it('accepts a boolean helpTextsEnabled value without requiring profile fields', async () => {
|
||||
const dto = Object.assign(new AuthUpdateDto(), {
|
||||
helpTextsEnabled: false,
|
||||
});
|
||||
|
||||
await expect(validate(dto)).resolves.toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -1,8 +1,12 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsNotEmpty, IsOptional, MinLength, Validate } from 'class-validator';
|
||||
import { IsBoolean, IsNotEmpty, IsOptional, MinLength } from 'class-validator';
|
||||
import { IsExist } from '../../utils/validators/is-exists.validator';
|
||||
|
||||
export class AuthUpdateDto {
|
||||
@ApiProperty({ default: true })
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
helpTextsEnabled?: boolean;
|
||||
|
||||
@ApiProperty({ example: 'John' })
|
||||
@IsOptional()
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddHelpTextsEnabled1785520800000 implements MigrationInterface {
|
||||
name = 'AddHelpTextsEnabled1785520800000';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
'ALTER TABLE "user" ADD "helpTextsEnabled" boolean NOT NULL DEFAULT true',
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
'ALTER TABLE "user" DROP COLUMN "helpTextsEnabled"',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
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 });
|
||||
});
|
||||
});
|
||||
@@ -65,6 +65,9 @@ export class User extends EntityHelper {
|
||||
@Column({ nullable: true })
|
||||
lastName: string | null;
|
||||
|
||||
@Column({ default: true })
|
||||
helpTextsEnabled: boolean;
|
||||
|
||||
@ManyToOne(() => Role, {
|
||||
eager: true,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user