-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: migration from single to multi value select works automatically (#…
…1809) Co-authored-by: Sebastian <sebastian.leidig@gmail.com>
- Loading branch information
1 parent
cafa57e
commit 201df90
Showing
2 changed files
with
75 additions
and
7 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
src/app/core/entity/schema-datatypes/datatype-array.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { EntitySchemaField } from "../schema/entity-schema-field"; | ||
import { EntitySchemaService } from "../schema/entity-schema.service"; | ||
import { ConfigurableEnumDatatype } from "../../configurable-enum/configurable-enum-datatype/configurable-enum-datatype"; | ||
import { defaultInteractionTypes } from "../../config/default-config/default-interaction-types"; | ||
import { arrayEntitySchemaDatatype } from "./datatype-array"; | ||
|
||
describe("Schema data type: array", () => { | ||
let schemaService: EntitySchemaService; | ||
const schema: EntitySchemaField = { | ||
dataType: "array", | ||
innerDataType: "configurable-enum", | ||
additional: "test", | ||
}; | ||
beforeEach(() => { | ||
schemaService = new EntitySchemaService(); | ||
schemaService.registerSchemaDatatype( | ||
new ConfigurableEnumDatatype({ | ||
getEnumValues: () => defaultInteractionTypes, | ||
} as any) | ||
); | ||
}); | ||
|
||
it("should transform enums inside arrays", () => { | ||
const value = defaultInteractionTypes.map(({ id }) => id); | ||
|
||
const obj = arrayEntitySchemaDatatype.transformToObjectFormat( | ||
value, | ||
schema, | ||
schemaService | ||
); | ||
|
||
expect(obj).toEqual(defaultInteractionTypes); | ||
|
||
const db = arrayEntitySchemaDatatype.transformToDatabaseFormat( | ||
obj, | ||
schema, | ||
schemaService | ||
); | ||
|
||
expect(db).toEqual(value); | ||
}); | ||
|
||
it("should automatically wrap value into array (and transform to inner type) if not an array yet", () => { | ||
const value = defaultInteractionTypes[1].id; | ||
|
||
const obj = arrayEntitySchemaDatatype.transformToObjectFormat( | ||
value, | ||
schema, | ||
schemaService | ||
); | ||
|
||
expect(obj).toEqual([defaultInteractionTypes[1]]); | ||
}); | ||
|
||
it("should transform empty values as an empty array", () => { | ||
let obj = arrayEntitySchemaDatatype.transformToObjectFormat( | ||
undefined, | ||
schema, | ||
schemaService | ||
); | ||
expect(obj).toEqual([]); | ||
|
||
obj = arrayEntitySchemaDatatype.transformToObjectFormat( | ||
"", | ||
schema, | ||
schemaService | ||
); | ||
expect(obj).toEqual([]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters