Skip to content
Permalink
Browse files

fixed tests

  • Loading branch information
marcj committed Jan 14, 2020
1 parent c78bcca commit aaa6b10f906a65ebc8eae61564d19cf34b85b4a0
Showing with 74 additions and 42 deletions.
  1. +3 −0 packages/core/src/decorators.ts
  2. +42 −20 packages/core/tests/plain-to.spec.ts
  3. +29 −22 packages/mongo/tests/to-mongo.spec.ts
@@ -68,6 +68,7 @@ export interface PropertySchemaSerialized {
isOptional?: true;
isId?: true;
isPartial?: true;
typeSet?: true;
allowLabelsAsValue?: true;
methodName?: string;
templateArgs?: PropertySchemaSerialized[];
@@ -141,6 +142,7 @@ export class PropertySchema {
if (this.isId) props['isId'] = true;
if (this.isPartial) props['isPartial'] = true;
if (this.allowLabelsAsValue) props['allowLabelsAsValue'] = true;
if (this.typeSet) props['typeSet'] = true;
if (this.methodName) props['methodName'] = this.methodName;

if (this.templateArgs) {
@@ -172,6 +174,7 @@ export class PropertySchema {
if (props['isId']) p.isId = true;
if (props['isPartial']) p.isPartial = true;
if (props['allowLabelsAsValue']) p.allowLabelsAsValue = true;
if (props['typeSet']) p.typeSet = true;
if (props['methodName']) p.methodName = props['methodName'];

if (props['templateArgs']) {
@@ -9,7 +9,7 @@ import {
partialPlainToClass,
plainToClass
} from "../src/mapper";
import {f, ParentReference} from "..";
import {f, ParentReference, PropertySchema} from "..";
import {DocumentClass} from "./document-scenario/DocumentClass";
import {PageClass} from "./document-scenario/PageClass";
import {PageCollection} from "./document-scenario/PageCollection";
@@ -96,6 +96,14 @@ test('getResolvedReflection deep', () => {

test('getResolvedReflection deep decorator', () => {
expect(getResolvedReflection(SimpleModel, 'childrenCollection.0')!).toEqual({
"propertySchema": PropertySchema.fromJSON({
"classType": "sub",
"isArray": true,
"isDecorated": true,
"name": "items",
"type": "class",
"typeSet": true,
}),
resolvedClassType: SimpleModel,
resolvedPropertyName: 'childrenCollection',
type: 'class',
@@ -106,6 +114,11 @@ test('getResolvedReflection deep decorator', () => {
});

expect(getResolvedReflection(SimpleModel, 'childrenCollection.0.label')!).toEqual({
"propertySchema": PropertySchema.fromJSON({
"name": "label",
"type": "string",
"typeSet": true,
}),
resolvedClassType: SubModel,
resolvedPropertyName: 'label',
type: 'string',
@@ -243,6 +256,11 @@ test('partial document', () => {
expect(document['pages.0.children'].get(0).name).toBe('7');

expect(getResolvedReflection(DocumentClass, 'pages.0.name')).toEqual({
"propertySchema": PropertySchema.fromJSON({
"name": "name",
"type": "string",
"typeSet": true,
}),
resolvedClassType: PageClass,
resolvedPropertyName: 'name',
type: 'string',
@@ -252,25 +270,28 @@ test('partial document', () => {
partial: false,
});

expect(getResolvedReflection(DocumentClass, 'pages.0.children')).toEqual({
resolvedClassType: PageClass,
resolvedPropertyName: 'children',
type: 'class',
typeValue: PageCollection,
array: false,
map: false,
partial: false,
});
{
const a = getResolvedReflection(DocumentClass, 'pages.0.children');
expect(a!.resolvedClassType).toBe(PageClass);
expect(a!.resolvedPropertyName).toBe('children');
expect(a!.type).toBe('class');
expect(a!.typeValue).toBe(PageCollection);
expect(a!.array).toBe(false);
expect(a!.map).toBe(false);
expect(a!.partial).toBe(false);
}

expect(getResolvedReflection(DocumentClass, 'pages.0.children.0.name')).toEqual({
resolvedClassType: PageClass,
resolvedPropertyName: 'name',
type: 'string',
typeValue: undefined,
array: false,
map: false,
partial: false,
});

{
const a = getResolvedReflection(DocumentClass, 'pages.0.children.0.name');
expect(a!.resolvedClassType).toBe(PageClass);
expect(a!.resolvedPropertyName).toBe('name');
expect(a!.type).toBe('string');
expect(a!.typeValue).toBe(undefined);
expect(a!.array).toBe(false);
expect(a!.map).toBe(false);
expect(a!.partial).toBe(false);
}
});

test('test enum string', () => {
@@ -341,7 +362,8 @@ test('test enum labels', () => {


test('partial edge cases', () => {
class Config {}
class Config {
}

class User {
@f
@@ -4,7 +4,7 @@ import {
f,
forwardRef,
getResolvedReflection,
ParentReference,
ParentReference, PropertySchema,
} from "@marcj/marshal";
import {Plan, SimpleModel, SubModel} from "@marcj/marshal/tests/entities";
import {Binary, ObjectID} from "mongodb";
@@ -64,8 +64,9 @@ test('make sure undefined is undefined', () => {

class Model {
constructor(
@f.optional()
public name?: string){}
@f.optional()
public name?: string) {
}
}

{
@@ -497,6 +498,11 @@ test('partial document', () => {
expect(document['pages.0.children'][0].name).toBe('7');

expect(getResolvedReflection(DocumentClass, 'pages.0.name')).toEqual({
"propertySchema": PropertySchema.fromJSON({
"name": "name",
"type": "string",
"typeSet": true,
}),
resolvedClassType: PageClass,
resolvedPropertyName: 'name',
type: 'string',
@@ -506,23 +512,24 @@ test('partial document', () => {
partial: false,
});

expect(getResolvedReflection(DocumentClass, 'pages.0.children')).toEqual({
resolvedClassType: PageClass,
resolvedPropertyName: 'children',
type: 'class',
typeValue: PageCollection,
array: false,
map: false,
partial: false,
});
{
const a1 = getResolvedReflection(DocumentClass, 'pages.0.children');
expect(a1!.resolvedClassType).toBe(PageClass);
expect(a1!.resolvedPropertyName).toBe('children');
expect(a1!.type).toBe('class');
expect(a1!.typeValue).toBe(PageCollection);
expect(a1!.array).toBe(false);
expect(a1!.map).toBe(false);
expect(a1!.partial).toBe(false);
}

expect(getResolvedReflection(DocumentClass, 'pages.0.children.0.name')).toEqual({
resolvedClassType: PageClass,
resolvedPropertyName: 'name',
type: 'string',
typeValue: undefined,
array: false,
map: false,
partial: false,
});
});
{
const a1 = getResolvedReflection(DocumentClass, 'pages.0.children.0.name');
expect(a1!.resolvedClassType).toBe(PageClass);
expect(a1!.resolvedPropertyName).toBe('name');
expect(a1!.type).toBe('string');
expect(a1!.typeValue).toBe(undefined);
expect(a1!.array).toBe(false);
expect(a1!.map).toBe(false);
expect(a1!.partial).toBe(false);
} });

0 comments on commit aaa6b10

Please sign in to comment.
You can’t perform that action at this time.