✨ unit test
This commit is contained in:
@@ -8,6 +8,7 @@ const ajv = new Ajv({
|
||||
removeAdditional: "all",
|
||||
useDefaults: true,
|
||||
coerceTypes: true,
|
||||
// @ts-ignore
|
||||
validateFormats: false,
|
||||
allowUnionTypes: true,
|
||||
});
|
||||
@@ -23,12 +24,18 @@ export class BaseClass extends BaseEntity {
|
||||
this.assign(props);
|
||||
|
||||
if (!this.construct.schema) this.construct.schema = { ...schema, $ref: `#/definitions/${this.construct.name}` };
|
||||
|
||||
this.id = this.opts.id || Snowflake.generate();
|
||||
}
|
||||
|
||||
get construct(): any {
|
||||
return this.constructor;
|
||||
}
|
||||
|
||||
get metadata() {
|
||||
return this.construct.getRepository().metadata;
|
||||
}
|
||||
|
||||
assign(props: any) {
|
||||
if (!props || typeof props !== "object") return;
|
||||
|
||||
@@ -39,8 +46,6 @@ export class BaseClass extends BaseEntity {
|
||||
|
||||
Object.defineProperty(this, key, { value: props[key] });
|
||||
}
|
||||
|
||||
this.id = this.opts.id || Snowflake.generate();
|
||||
}
|
||||
|
||||
@BeforeUpdate()
|
||||
@@ -48,10 +53,7 @@ export class BaseClass extends BaseEntity {
|
||||
validate() {
|
||||
const valid = ajv.validate(this.construct.schema, this.toJSON());
|
||||
if (!valid) throw ajv.errors;
|
||||
}
|
||||
|
||||
get metadata() {
|
||||
return this.construct.getRepository().metadata;
|
||||
return this;
|
||||
}
|
||||
|
||||
toJSON(): any {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Column, Entity, JoinColumn, OneToMany, OneToOne } from "typeorm";
|
||||
import { Column, Entity, JoinColumn, OneToMany } from "typeorm";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { BitField } from "../util/BitField";
|
||||
import { Relationship } from "./Relationship";
|
||||
|
||||
Reference in New Issue
Block a user