Better org of tests
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
roots: ['src'],
|
roots: ['tests'],
|
||||||
|
moduleNameMapper: {
|
||||||
|
'src/(.*)': '<rootDir>/src/$1',
|
||||||
|
},
|
||||||
preset: 'ts-jest',
|
preset: 'ts-jest',
|
||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
coverageReporters: [
|
coverageReporters: [
|
||||||
|
|||||||
22
tests/decorators/exclude.spec.ts
Normal file
22
tests/decorators/exclude.spec.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import 'reflect-metadata';
|
||||||
|
import { Serde } from "src/serde";
|
||||||
|
import { Exclude } from 'src/decorators';
|
||||||
|
|
||||||
|
class ExcludeTestModel extends Serde<ExcludeTestModel> {
|
||||||
|
name: string;
|
||||||
|
date: Date;
|
||||||
|
description: string;
|
||||||
|
@Exclude() frontendField: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('@Exclude() Decorator', () => {
|
||||||
|
it('should remove properties marked during serialize', () => {
|
||||||
|
const testModel = new ExcludeTestModel().deserialize({
|
||||||
|
name: 'test model',
|
||||||
|
description: 'this is a test model',
|
||||||
|
frontendField: 'test field'
|
||||||
|
});
|
||||||
|
const serializedModel = testModel.serialize();
|
||||||
|
expect(serializedModel).toEqual({ name: 'test model', description: 'this is a test model' });
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,48 +1,28 @@
|
|||||||
import { Serde } from 'src/serde';
|
import 'reflect-metadata';
|
||||||
import { Exclude, Pluck } from 'src/decorators';
|
import { Serde } from "src/serde";
|
||||||
|
import { Pluck } from 'src/decorators';
|
||||||
class ExcludeTestModel extends Serde<ExcludeTestModel> {
|
|
||||||
name: string;
|
|
||||||
date: Date;
|
|
||||||
description: string;
|
|
||||||
@Exclude() frontendField: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
class PluckArrayTestModel extends Serde<PluckArrayTestModel> {
|
class PluckArrayTestModel extends Serde<PluckArrayTestModel> {
|
||||||
name: string;
|
name: string;
|
||||||
@Pluck(['id']) nestedProperties: { id: number, name: string }[];
|
@Pluck(['id']) nestedProperties: { id: number, name: string }[];
|
||||||
}
|
}
|
||||||
|
|
||||||
class PluckArrayTestTwoModel extends Serde<PluckArrayTestTwoModel> {
|
class PluckArrayTestTwoModel extends Serde<PluckArrayTestTwoModel> {
|
||||||
name: string;
|
name: string;
|
||||||
@Pluck('id') nestedProperties: { id: number, name: string }[];
|
@Pluck('id') nestedProperties: { id: number, name: string }[];
|
||||||
}
|
}
|
||||||
|
|
||||||
class PluckObjectTestModel extends Serde<PluckObjectTestModel> {
|
class PluckObjectTestModel extends Serde<PluckObjectTestModel> {
|
||||||
name: string;
|
name: string;
|
||||||
@Pluck(['id']) nestedProperty: { id: number, name: string };
|
@Pluck(['id']) nestedProperty: { id: number, name: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
class PluckObjectTestTwoModel extends Serde<PluckObjectTestTwoModel> {
|
class PluckObjectTestTwoModel extends Serde<PluckObjectTestTwoModel> {
|
||||||
name: string;
|
name: string;
|
||||||
@Pluck('id') nestedProperty: { id: number, name: string };
|
@Pluck('id') nestedProperty: { id: number, name: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('Serde', () => {
|
describe('@Pluck() Decorator', () => {
|
||||||
|
|
||||||
describe('@Exclude() decorator tests', () => {
|
|
||||||
it('should remove properties marked during serialize', () => {
|
|
||||||
const testModel = new ExcludeTestModel().deserialize({
|
|
||||||
name: 'test model',
|
|
||||||
description: 'this is a test model',
|
|
||||||
frontendField: 'test field'
|
|
||||||
});
|
|
||||||
const serializedModel = testModel.serialize();
|
|
||||||
expect(serializedModel).toEqual({ name: 'test model', description: 'this is a test model' });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('@Pluck() decorator tests', () => {
|
|
||||||
it('should pluck \'id\' (property: T[]) from marked property during serialize', () => {
|
it('should pluck \'id\' (property: T[]) from marked property during serialize', () => {
|
||||||
const testModel = new PluckArrayTestModel().deserialize({
|
const testModel = new PluckArrayTestModel().deserialize({
|
||||||
name: 'test model',
|
name: 'test model',
|
||||||
@@ -89,4 +69,3 @@ describe('Serde', () => {
|
|||||||
expect(serializedModel).toEqual({ name: 'test model', nestedProperty: 2 });
|
expect(serializedModel).toEqual({ name: 'test model', nestedProperty: 2 });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
@@ -22,6 +22,6 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"src/**/*", "test/**/*"
|
"src/**/*", "tests/**/*"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user