Commit b7413ee6 authored by nanahira's avatar nanahira

add unit tests

parent 061028cf
import 'reflect-metadata';
export * from './src/crud-base';
export * from './src/bases';
export * from './src/decorators';
......
import { TimeBase } from './time-base';
import { Generated, SelectQueryBuilder } from 'typeorm';
import { applyQueryProperty } from '../utility/query';
import { applyQueryProperty } from '../utility';
import {
IntColumn,
MergePropertyDecorators,
......
import { CreateDateColumn, DeleteDateColumn, UpdateDateColumn } from 'typeorm';
import { PageSettingsDto } from '../dto/page-settings';
import { PageSettingsDto } from '../dto';
import { NotColumn } from '../decorators';
export interface DeletionWise {
......@@ -36,8 +36,10 @@ export class TimeBase
return;
}
// eslint-disable-next-line @typescript-eslint/no-empty-function
async prepareForSaving(): Promise<void> {}
// eslint-disable-next-line @typescript-eslint/no-empty-function
afterSaving() {}
}
......
describe('Sample test.', () => {
it('should pass', () => {
expect(true).toBe(true);
import { Index } from 'typeorm';
import { plainToInstance } from 'class-transformer';
import { EnumColumn, IntColumn, StringColumn } from '../src/decorators';
import { IdBase } from '../src/bases';
import { validate } from 'class-validator';
enum Gender {
F = 'F',
M = 'M',
}
class User extends IdBase() {
@Index()
@StringColumn(5, {
required: true,
})
name: string;
@IntColumn('int', { unsigned: true })
age: number;
@EnumColumn(Gender)
gender: Gender;
}
describe('nicot', () => {
it('create entity class', () => {
const good1 = plainToInstance(User, { name: 'John', age: 20 });
const good2 = plainToInstance(User, {
name: 'John',
age: 20,
gender: Gender.M,
});
const bad1 = plainToInstance(User, { name: 'John111', age: 20 });
const bad2 = plainToInstance(User, { age: 20 });
const bad3 = plainToInstance(User, { name: 'John', age: -1 });
const bad4 = plainToInstance(User, {
name: 'John',
age: 20,
gender: 'foo',
});
expect(validate(good1)).resolves.toEqual([]);
expect(validate(good2)).resolves.toEqual([]);
expect(validate(bad1)).resolves.not.toEqual([]);
expect(validate(bad2)).resolves.not.toEqual([]);
expect(validate(bad3)).resolves.not.toEqual([]);
expect(validate(bad4)).resolves.not.toEqual([]);
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment