зеркало из https://github.com/microsoft/paris.git
Bug fix: serializing nested value objects wasn't working.
This commit is contained in:
Родитель
899a5e48bf
Коммит
6605b4bb16
|
@ -0,0 +1,9 @@
|
||||||
|
# [1.3.6] (2018-11-25)
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* `Modeler.serializeModel` was serializing nested value objects as `undefined`
|
||||||
|
|
||||||
|
### Tests
|
||||||
|
|
||||||
|
* Added test for `Modeler.serializeModel` with nested value object.
|
|
@ -348,7 +348,7 @@ export class Modeler {
|
||||||
else modelValue = itemFieldValue.map((item: any) => DataTransformersService.serialize(entityField.arrayOf, item));
|
else modelValue = itemFieldValue.map((item: any) => DataTransformersService.serialize(entityField.arrayOf, item));
|
||||||
} else modelValue = null;
|
} else modelValue = null;
|
||||||
}
|
}
|
||||||
else if (fieldRepository)
|
else if (fieldRepository && fieldRepository.entity)
|
||||||
modelValue = isNilValue ? fieldRepository.modelConfig.getDefaultValue() || null : itemFieldValue.id;
|
modelValue = isNilValue ? fieldRepository.modelConfig.getDefaultValue() || null : itemFieldValue.id;
|
||||||
else if (fieldValueObjectType)
|
else if (fieldValueObjectType)
|
||||||
modelValue = isNilValue ? fieldValueObjectType.getDefaultValue() || null : this.serializeModel(itemFieldValue, fieldValueObjectType, serializationData);
|
modelValue = isNilValue ? fieldValueObjectType.getDefaultValue() || null : this.serializeModel(itemFieldValue, fieldValueObjectType, serializationData);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@microsoft/paris",
|
"name": "@microsoft/paris",
|
||||||
"version": "1.3.5",
|
"version": "1.3.6",
|
||||||
"description": "Library for the implementation of Domain Driven Design with TypeScript + RxJS",
|
"description": "Library for the implementation of Domain Driven Design with TypeScript + RxJS",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
|
@ -15,6 +15,9 @@ import {EntityModelBase} from "../../lib/config/entity-model.base";
|
||||||
import {Repository} from "../../lib/api/repository/repository";
|
import {Repository} from "../../lib/api/repository/repository";
|
||||||
import {EntityField} from "../../lib/config/decorators/entity-field.decorator";
|
import {EntityField} from "../../lib/config/decorators/entity-field.decorator";
|
||||||
import {TodoStatus} from "../mock/todo-status.entity";
|
import {TodoStatus} from "../mock/todo-status.entity";
|
||||||
|
import {ModelBase} from "../../lib/config/model.base";
|
||||||
|
import {ValueObject} from "../../lib/config/decorators/value-object.decorator";
|
||||||
|
import {ModelConfig} from "../../lib/config/model-config";
|
||||||
|
|
||||||
describe('Modeler', () => {
|
describe('Modeler', () => {
|
||||||
let paris: Paris;
|
let paris: Paris;
|
||||||
|
@ -247,9 +250,24 @@ describe('Modeler', () => {
|
||||||
let serializeItem:jest.Mock;
|
let serializeItem:jest.Mock;
|
||||||
let serializedItemRepo:Repository<any>;
|
let serializedItemRepo:Repository<any>;
|
||||||
|
|
||||||
|
let serializedEntityWithValueObject:{ new(data:any):any };
|
||||||
|
let serializedEntityWithValueObjectRepo:Repository<any>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
serializeItem = jest.fn();
|
serializeItem = jest.fn();
|
||||||
|
|
||||||
|
@ValueObject({
|
||||||
|
singularName: 'property',
|
||||||
|
pluralName: 'property'
|
||||||
|
})
|
||||||
|
class SerializedEntityPropertyValueObject extends ModelBase {
|
||||||
|
@EntityField()
|
||||||
|
prop1: string;
|
||||||
|
|
||||||
|
@EntityField()
|
||||||
|
prop2: string;
|
||||||
|
}
|
||||||
|
|
||||||
@Entity({
|
@Entity({
|
||||||
singularName: "Serialized entity",
|
singularName: "Serialized entity",
|
||||||
pluralName: "Serialized entities",
|
pluralName: "Serialized entities",
|
||||||
|
@ -260,8 +278,21 @@ describe('Modeler', () => {
|
||||||
@EntityField() name:string;
|
@EntityField() name:string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Entity({
|
||||||
|
singularName: "Serialized entity2",
|
||||||
|
pluralName: "Serialized entities2",
|
||||||
|
endpoint: "serialized2",
|
||||||
|
})
|
||||||
|
class SerializedEntityWithValueObject extends EntityModelBase {
|
||||||
|
@EntityField() name:string;
|
||||||
|
@EntityField() val: SerializedEntityPropertyValueObject;
|
||||||
|
}
|
||||||
|
|
||||||
serializedEntity = SerializedEntity;
|
serializedEntity = SerializedEntity;
|
||||||
serializedItemRepo = paris.getRepository(SerializedEntity);
|
serializedItemRepo = paris.getRepository(SerializedEntity);
|
||||||
|
|
||||||
|
serializedEntityWithValueObject = SerializedEntityWithValueObject;
|
||||||
|
serializedEntityWithValueObjectRepo = paris.getRepository(SerializedEntityWithValueObject);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("calls the entity's `serializeItem` method with the proper params", () => {
|
it("calls the entity's `serializeItem` method with the proper params", () => {
|
||||||
|
@ -271,5 +302,11 @@ describe('Modeler', () => {
|
||||||
serializedItemRepo.save(newSerializedItem, null, serializationData);
|
serializedItemRepo.save(newSerializedItem, null, serializationData);
|
||||||
expect(serializeItem).toBeCalledWith(newSerializedItem, newSerializedItem, (<DataEntityType<any>>serializedEntity).entityConfig, paris.config, serializationData);
|
expect(serializeItem).toBeCalledWith(newSerializedItem, newSerializedItem, (<DataEntityType<any>>serializedEntity).entityConfig, paris.config, serializationData);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it ("serializes the entity with the nested value object intact", () => {
|
||||||
|
const newSerializedItem = { name: 'test', val: { prop1: 'test', prop2: 'test2' } };
|
||||||
|
const serializedModel:Record<string, any> = paris.modeler.serializeModel<any>(newSerializedItem, serializedEntityWithValueObjectRepo.modelConfig as ModelConfig<any>);
|
||||||
|
expect(serializedModel['val']).toBeDefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Загрузка…
Ссылка в новой задаче