@api-client/core 0.11.11 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Testing.md +1 -1
- package/bin/plugins/events/EventPlugin.ts +61 -0
- package/bin/plugins/events/assert.ts +193 -0
- package/bin/plugins/events/types.ts +6 -0
- package/bin/test.ts +8 -1
- package/build/src/amf/AmfShapeGenerator.d.ts +6 -3
- package/build/src/amf/AmfShapeGenerator.d.ts.map +1 -1
- package/build/src/amf/AmfShapeGenerator.js +4 -1
- package/build/src/amf/AmfShapeGenerator.js.map +1 -1
- package/build/src/amf/AmfTypes.d.ts +2 -2
- package/build/src/amf/AmfTypes.d.ts.map +1 -1
- package/build/src/amf/AmfTypes.js.map +1 -1
- package/build/src/amf/DataValueGenerator.d.ts +15 -15
- package/build/src/amf/DataValueGenerator.d.ts.map +1 -1
- package/build/src/amf/DataValueGenerator.js +14 -14
- package/build/src/amf/DataValueGenerator.js.map +1 -1
- package/build/src/browser.d.ts +12 -9
- package/build/src/browser.d.ts.map +1 -1
- package/build/src/browser.js +11 -8
- package/build/src/browser.js.map +1 -1
- package/build/src/exceptions/attach_exception.d.ts +11 -0
- package/build/src/exceptions/attach_exception.d.ts.map +1 -0
- package/build/src/exceptions/attach_exception.js +11 -0
- package/build/src/exceptions/attach_exception.js.map +1 -0
- package/build/src/exceptions/detach_exception.d.ts +11 -0
- package/build/src/exceptions/detach_exception.d.ts.map +1 -0
- package/build/src/exceptions/detach_exception.js +11 -0
- package/build/src/exceptions/detach_exception.js.map +1 -0
- package/build/src/exceptions/remove_model_exception.d.ts +8 -0
- package/build/src/exceptions/remove_model_exception.d.ts.map +1 -0
- package/build/src/exceptions/remove_model_exception.js +8 -0
- package/build/src/exceptions/remove_model_exception.js.map +1 -0
- package/build/src/exceptions/remove_namespace_exception.d.ts +8 -0
- package/build/src/exceptions/remove_namespace_exception.d.ts.map +1 -0
- package/build/src/exceptions/remove_namespace_exception.js +8 -0
- package/build/src/exceptions/remove_namespace_exception.js.map +1 -0
- package/build/src/index.d.ts +12 -9
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js +11 -8
- package/build/src/index.js.map +1 -1
- package/build/src/legacy.d.ts +8 -0
- package/build/src/legacy.d.ts.map +1 -1
- package/build/src/legacy.js +9 -0
- package/build/src/legacy.js.map +1 -1
- package/build/src/modeling/Bindings.d.ts +2 -2
- package/build/src/modeling/Bindings.d.ts.map +1 -1
- package/build/src/modeling/Bindings.js.map +1 -1
- package/build/src/modeling/DataDomain.d.ts +601 -0
- package/build/src/modeling/DataDomain.d.ts.map +1 -0
- package/build/src/modeling/DataDomain.js +1142 -0
- package/build/src/modeling/DataDomain.js.map +1 -0
- package/build/src/modeling/DataFormat.d.ts +42 -41
- package/build/src/modeling/DataFormat.d.ts.map +1 -1
- package/build/src/modeling/DataFormat.js +30 -131
- package/build/src/modeling/DataFormat.js.map +1 -1
- package/build/src/modeling/DomainAssociation.d.ts +281 -0
- package/build/src/modeling/DomainAssociation.d.ts.map +1 -0
- package/build/src/modeling/DomainAssociation.js +440 -0
- package/build/src/modeling/DomainAssociation.js.map +1 -0
- package/build/src/modeling/DomainElement.d.ts +33 -0
- package/build/src/modeling/DomainElement.d.ts.map +1 -0
- package/build/src/modeling/DomainElement.js +32 -0
- package/build/src/modeling/DomainElement.js.map +1 -0
- package/build/src/modeling/DomainEntity.d.ts +383 -0
- package/build/src/modeling/DomainEntity.d.ts.map +1 -0
- package/build/src/modeling/DomainEntity.js +718 -0
- package/build/src/modeling/DomainEntity.js.map +1 -0
- package/build/src/modeling/DomainFile.d.ts +25 -0
- package/build/src/modeling/DomainFile.d.ts.map +1 -0
- package/build/src/modeling/DomainFile.js +86 -0
- package/build/src/modeling/DomainFile.js.map +1 -0
- package/build/src/modeling/DomainImpactAnalysis.d.ts +60 -47
- package/build/src/modeling/DomainImpactAnalysis.d.ts.map +1 -1
- package/build/src/modeling/DomainImpactAnalysis.js +201 -132
- package/build/src/modeling/DomainImpactAnalysis.js.map +1 -1
- package/build/src/modeling/DomainModel.d.ts +226 -0
- package/build/src/modeling/DomainModel.d.ts.map +1 -0
- package/build/src/modeling/DomainModel.js +401 -0
- package/build/src/modeling/DomainModel.js.map +1 -0
- package/build/src/modeling/DomainNamespace.d.ts +268 -0
- package/build/src/modeling/DomainNamespace.d.ts.map +1 -0
- package/build/src/modeling/DomainNamespace.js +512 -0
- package/build/src/modeling/DomainNamespace.js.map +1 -0
- package/build/src/modeling/DomainProperty.d.ts +281 -0
- package/build/src/modeling/DomainProperty.d.ts.map +1 -0
- package/build/src/modeling/DomainProperty.js +560 -0
- package/build/src/modeling/DomainProperty.js.map +1 -0
- package/build/src/modeling/DomainSerialization.d.ts +40 -0
- package/build/src/modeling/DomainSerialization.d.ts.map +1 -0
- package/build/src/modeling/DomainSerialization.js +288 -0
- package/build/src/modeling/DomainSerialization.js.map +1 -0
- package/build/src/modeling/DomainVersioning.d.ts +17 -0
- package/build/src/modeling/DomainVersioning.d.ts.map +1 -0
- package/build/src/modeling/DomainVersioning.js +124 -0
- package/build/src/modeling/DomainVersioning.js.map +1 -0
- package/build/src/modeling/GraphUtils.d.ts +8 -0
- package/build/src/modeling/GraphUtils.d.ts.map +1 -0
- package/build/src/modeling/GraphUtils.js +26 -0
- package/build/src/modeling/GraphUtils.js.map +1 -0
- package/build/src/modeling/amf/ShapeGenerator.d.ts +164 -0
- package/build/src/modeling/amf/ShapeGenerator.d.ts.map +1 -0
- package/build/src/modeling/amf/ShapeGenerator.js +492 -0
- package/build/src/modeling/amf/ShapeGenerator.js.map +1 -0
- package/build/src/modeling/{DataAssociation.d.ts → legacy/DataAssociation.d.ts} +10 -5
- package/build/src/modeling/legacy/DataAssociation.d.ts.map +1 -0
- package/build/src/modeling/{DataAssociation.js → legacy/DataAssociation.js} +9 -6
- package/build/src/modeling/legacy/DataAssociation.js.map +1 -0
- package/build/src/modeling/{DataEntity.d.ts → legacy/DataEntity.d.ts} +12 -7
- package/build/src/modeling/legacy/DataEntity.d.ts.map +1 -0
- package/build/src/modeling/{DataEntity.js → legacy/DataEntity.js} +19 -18
- package/build/src/modeling/legacy/DataEntity.js.map +1 -0
- package/build/src/modeling/{DataEntityBuilder.d.ts → legacy/DataEntityBuilder.d.ts} +3 -2
- package/build/src/modeling/legacy/DataEntityBuilder.d.ts.map +1 -0
- package/build/src/modeling/{DataEntityBuilder.js → legacy/DataEntityBuilder.js} +3 -2
- package/build/src/modeling/legacy/DataEntityBuilder.js.map +1 -0
- package/build/src/modeling/legacy/DataImpactAnalysis.d.ts +298 -0
- package/build/src/modeling/legacy/DataImpactAnalysis.d.ts.map +1 -0
- package/build/src/modeling/legacy/DataImpactAnalysis.js +441 -0
- package/build/src/modeling/legacy/DataImpactAnalysis.js.map +1 -0
- package/build/src/modeling/{DataModel.d.ts → legacy/DataModel.d.ts} +6 -4
- package/build/src/modeling/legacy/DataModel.d.ts.map +1 -0
- package/build/src/modeling/{DataModel.js → legacy/DataModel.js} +7 -6
- package/build/src/modeling/legacy/DataModel.js.map +1 -0
- package/build/src/modeling/{DataNamespace.d.ts → legacy/DataNamespace.d.ts} +22 -3
- package/build/src/modeling/legacy/DataNamespace.d.ts.map +1 -0
- package/build/src/modeling/{DataNamespace.js → legacy/DataNamespace.js} +7 -3
- package/build/src/modeling/legacy/DataNamespace.js.map +1 -0
- package/build/src/modeling/{DataProperty.d.ts → legacy/DataProperty.d.ts} +13 -5
- package/build/src/modeling/legacy/DataProperty.d.ts.map +1 -0
- package/build/src/modeling/{DataProperty.js → legacy/DataProperty.js} +8 -5
- package/build/src/modeling/legacy/DataProperty.js.map +1 -0
- package/build/src/modeling/observed.d.ts +67 -0
- package/build/src/modeling/observed.d.ts.map +1 -0
- package/build/src/modeling/observed.js +230 -0
- package/build/src/modeling/observed.js.map +1 -0
- package/build/src/modeling/types.d.ts +165 -1
- package/build/src/modeling/types.d.ts.map +1 -1
- package/build/src/modeling/types.js.map +1 -1
- package/build/src/models/Thing.d.ts +26 -5
- package/build/src/models/Thing.d.ts.map +1 -1
- package/build/src/models/Thing.js +193 -91
- package/build/src/models/Thing.js.map +1 -1
- package/build/src/models/kinds.d.ts +31 -6
- package/build/src/models/kinds.d.ts.map +1 -1
- package/build/src/models/kinds.js +31 -6
- package/build/src/models/kinds.js.map +1 -1
- package/build/src/models/store/DataFile.d.ts +3 -1
- package/build/src/models/store/DataFile.d.ts.map +1 -1
- package/build/src/models/store/DataFile.js +2 -0
- package/build/src/models/store/DataFile.js.map +1 -1
- package/build/src/models/types.d.ts +12 -0
- package/build/src/models/types.d.ts.map +1 -0
- package/build/src/models/types.js +2 -0
- package/build/src/models/types.js.map +1 -0
- package/build/src/runtime/store/FilesSdk.d.ts +2 -2
- package/build/src/runtime/store/FilesSdk.d.ts.map +1 -1
- package/build/src/runtime/store/FilesSdk.js.map +1 -1
- package/data/models/example-generator-api.json +16 -16
- package/package.json +20 -6
- package/readme.md +1 -1
- package/src/amf/AmfShapeGenerator.ts +7 -4
- package/src/amf/AmfTypes.ts +2 -2
- package/src/amf/DataValueGenerator.ts +21 -21
- package/src/exceptions/attach_exception.ts +11 -0
- package/src/exceptions/detach_exception.ts +11 -0
- package/src/exceptions/remove_model_exception.ts +8 -0
- package/src/exceptions/remove_namespace_exception.ts +8 -0
- package/src/modeling/Bindings.ts +2 -2
- package/src/modeling/DataDomain.ts +1221 -0
- package/src/modeling/DataFormat.ts +54 -163
- package/src/modeling/DomainAssociation.ts +476 -0
- package/src/modeling/DomainElement.ts +50 -0
- package/src/modeling/DomainEntity.ts +769 -0
- package/src/modeling/DomainFile.ts +94 -0
- package/src/modeling/DomainImpactAnalysis.ts +218 -144
- package/src/modeling/DomainModel.ts +421 -0
- package/src/modeling/DomainNamespace.ts +537 -0
- package/src/modeling/DomainProperty.ts +548 -0
- package/src/modeling/DomainSerialization.ts +312 -0
- package/src/modeling/DomainVersioning.ts +144 -0
- package/src/modeling/GraphUtils.ts +28 -0
- package/src/modeling/amf/ShapeGenerator.ts +552 -0
- package/src/modeling/graph.md +115 -0
- package/src/modeling/{DataAssociation.ts → legacy/DataAssociation.ts} +13 -8
- package/src/modeling/{DataEntity.ts → legacy/DataEntity.ts} +28 -23
- package/src/modeling/{DataEntityBuilder.ts → legacy/DataEntityBuilder.ts} +4 -3
- package/src/modeling/legacy/DataImpactAnalysis.ts +530 -0
- package/src/modeling/{DataModel.ts → legacy/DataModel.ts} +10 -8
- package/src/modeling/{DataNamespace.ts → legacy/DataNamespace.ts} +23 -5
- package/src/modeling/{DataProperty.ts → legacy/DataProperty.ts} +15 -7
- package/src/modeling/observed.ts +267 -0
- package/src/modeling/types.ts +174 -1
- package/src/models/Thing.ts +70 -5
- package/src/models/kinds.ts +32 -6
- package/src/models/store/DataFile.ts +3 -1
- package/src/models/types.ts +11 -0
- package/src/runtime/store/FilesSdk.ts +2 -2
- package/tests/unit/amf/data_value_generator.spec.ts +15 -15
- package/tests/unit/legacy-transformers/ARC-legacy-import.spec.ts +1 -1
- package/tests/unit/modeling/amf/shape_generator.spec.ts +1174 -0
- package/tests/unit/modeling/data_domain.spec.ts +444 -0
- package/tests/unit/modeling/data_domain_associations.spec.ts +279 -0
- package/tests/unit/modeling/data_domain_change_observers.spec.ts +681 -0
- package/tests/unit/modeling/data_domain_entities.spec.ts +449 -0
- package/tests/unit/modeling/data_domain_foreign.spec.ts +355 -0
- package/tests/unit/modeling/data_domain_models.spec.ts +658 -0
- package/tests/unit/modeling/data_domain_namespaces.spec.ts +668 -0
- package/tests/unit/modeling/data_domain_property.spec.ts +264 -0
- package/tests/unit/modeling/data_domain_serialization.spec.ts +294 -0
- package/tests/unit/modeling/domain.property.spec.ts +822 -0
- package/tests/unit/modeling/domain_asociation.spec.ts +643 -0
- package/tests/unit/modeling/domain_asociation_targets.spec.ts +350 -0
- package/tests/unit/modeling/domain_entity.spec.ts +730 -0
- package/tests/unit/modeling/domain_entity_associations.spec.ts +330 -0
- package/tests/unit/modeling/domain_entity_example_generator_json.spec.ts +988 -0
- package/tests/unit/modeling/domain_entity_example_generator_xml.spec.ts +1451 -0
- package/tests/unit/modeling/domain_entity_fields.spec.ts +113 -0
- package/tests/unit/modeling/domain_entity_generators.spec.ts +20 -0
- package/tests/unit/modeling/domain_entity_parents.spec.ts +291 -0
- package/tests/unit/modeling/domain_entity_properties.spec.ts +305 -0
- package/tests/unit/modeling/{data_file.spec.ts → domain_file.spec.ts} +29 -85
- package/tests/unit/modeling/domain_impact_analysis.spec.ts +452 -0
- package/tests/unit/modeling/domain_model.spec.ts +568 -0
- package/tests/unit/modeling/domain_model_entities.spec.ts +408 -0
- package/tests/unit/modeling/domain_namespace.spec.ts +514 -0
- package/tests/unit/modeling/domain_namespace_models.spec.ts +324 -0
- package/tests/unit/modeling/domain_namespace_namespaces.spec.ts +404 -0
- package/tests/unit/modeling/domain_versioning.spec.ts +140 -0
- package/tests/unit/{amf → modeling/legacy}/amf_shape_generator.spec.ts +11 -11
- package/tests/unit/modeling/{data_association.spec.ts → legacy/data_association.spec.ts} +3 -11
- package/tests/unit/modeling/{data_entity.spec.ts → legacy/data_entity.spec.ts} +10 -8
- package/tests/unit/modeling/{data_entity_generator_json.spec.ts → legacy/data_entity_generator_json.spec.ts} +1 -1
- package/tests/unit/modeling/{data_entity_generator_xml.spec.ts → legacy/data_entity_generator_xml.spec.ts} +1 -1
- package/tests/unit/modeling/{data_model.spec.ts → legacy/data_model.spec.ts} +3 -3
- package/tests/unit/modeling/{data_namespace.spec.ts → legacy/data_namespace.spec.ts} +3 -10
- package/tests/unit/modeling/{data_property.spec.ts → legacy/data_property.spec.ts} +3 -6
- package/tests/unit/modeling/{impact_analysis.spec.ts → legacy/impact_analysis.spec.ts} +9 -9
- package/tests/unit/models/File/new.spec.ts +1 -1
- package/tests/unit/models/HttpProject.spec.ts +3 -3
- package/tsconfig.node.json +35 -0
- package/build/src/modeling/DataAssociation.d.ts.map +0 -1
- package/build/src/modeling/DataAssociation.js.map +0 -1
- package/build/src/modeling/DataEntity.d.ts.map +0 -1
- package/build/src/modeling/DataEntity.js.map +0 -1
- package/build/src/modeling/DataEntityBuilder.d.ts.map +0 -1
- package/build/src/modeling/DataEntityBuilder.js.map +0 -1
- package/build/src/modeling/DataModel.d.ts.map +0 -1
- package/build/src/modeling/DataModel.js.map +0 -1
- package/build/src/modeling/DataNamespace.d.ts.map +0 -1
- package/build/src/modeling/DataNamespace.js.map +0 -1
- package/build/src/modeling/DataProperty.d.ts.map +0 -1
- package/build/src/modeling/DataProperty.js.map +0 -1
|
@@ -0,0 +1,643 @@
|
|
|
1
|
+
import { test } from '@japa/runner'
|
|
2
|
+
import {
|
|
3
|
+
DomainAssociation,
|
|
4
|
+
AmfShapes,
|
|
5
|
+
DomainAssociationKind,
|
|
6
|
+
Thing,
|
|
7
|
+
AssociationBinding,
|
|
8
|
+
DataDomain,
|
|
9
|
+
DataFormat,
|
|
10
|
+
} from '../../../src/index.js'
|
|
11
|
+
|
|
12
|
+
test.group('DomainAssociation.createSchema()', () => {
|
|
13
|
+
test('creates a valid schema with default values', ({ assert }) => {
|
|
14
|
+
const schema = DomainAssociation.createSchema()
|
|
15
|
+
assert.equal(schema.kind, DomainAssociationKind)
|
|
16
|
+
assert.typeOf(schema.key, 'string')
|
|
17
|
+
assert.isDefined(schema.info)
|
|
18
|
+
assert.deepEqual(schema.info, Thing.fromJSON({ name: 'New association' }).toJSON())
|
|
19
|
+
assert.isUndefined(schema.schema)
|
|
20
|
+
assert.isUndefined(schema.multiple)
|
|
21
|
+
assert.isUndefined(schema.required)
|
|
22
|
+
assert.isUndefined(schema.bindings)
|
|
23
|
+
assert.isUndefined(schema.targets)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('creates a schema with provided key', ({ assert }) => {
|
|
27
|
+
const key = 'test-key'
|
|
28
|
+
const schema = DomainAssociation.createSchema({ key })
|
|
29
|
+
assert.equal(schema.key, key)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('creates a schema with provided info', ({ assert }) => {
|
|
33
|
+
const info = { name: 'Test Association', description: 'Test description' }
|
|
34
|
+
const schema = DomainAssociation.createSchema({ info })
|
|
35
|
+
assert.deepEqual(schema.info, Thing.fromJSON(info).toJSON())
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
test('creates a schema with provided schema', ({ assert }) => {
|
|
39
|
+
const schemaDefinition: AmfShapes.IApiAssociationShape = { linked: false }
|
|
40
|
+
const schema = DomainAssociation.createSchema({ schema: schemaDefinition })
|
|
41
|
+
assert.deepEqual(schema.schema, schemaDefinition)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
test('creates a schema with provided multiple', ({ assert }) => {
|
|
45
|
+
const schema = DomainAssociation.createSchema({ multiple: true })
|
|
46
|
+
assert.isTrue(schema.multiple)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
test('creates a schema with provided required', ({ assert }) => {
|
|
50
|
+
const schema = DomainAssociation.createSchema({ required: true })
|
|
51
|
+
assert.isTrue(schema.required)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
test('creates a schema with provided bindings', ({ assert }) => {
|
|
55
|
+
const bindings: AssociationBinding[] = [{ type: 'web', schema: { hidden: true } }]
|
|
56
|
+
const schema = DomainAssociation.createSchema({ bindings })
|
|
57
|
+
assert.deepEqual(schema.bindings, bindings)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
test('creates a schema with provided targets', ({ assert }) => {
|
|
61
|
+
const targets = [{ key: 'target1', domain: 'domain1' }, { key: 'target2' }]
|
|
62
|
+
const schema = DomainAssociation.createSchema({ targets })
|
|
63
|
+
assert.deepEqual(schema.targets, targets)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test('creates a schema with all properties', ({ assert }) => {
|
|
67
|
+
const key = 'test-key'
|
|
68
|
+
const info = { name: 'Test Association', description: 'Test description' }
|
|
69
|
+
const schemaDefinition: AmfShapes.IApiAssociationShape = { linked: false }
|
|
70
|
+
const multiple = true
|
|
71
|
+
const required = true
|
|
72
|
+
const bindings: AssociationBinding[] = [{ type: 'web', schema: { hidden: false } }]
|
|
73
|
+
const targets = [{ key: 'target1', domain: 'domain1' }, { key: 'target2' }]
|
|
74
|
+
|
|
75
|
+
const schema = DomainAssociation.createSchema({
|
|
76
|
+
key,
|
|
77
|
+
info,
|
|
78
|
+
schema: schemaDefinition,
|
|
79
|
+
multiple,
|
|
80
|
+
required,
|
|
81
|
+
bindings,
|
|
82
|
+
targets,
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
assert.equal(schema.key, key)
|
|
86
|
+
assert.deepEqual(schema.info, Thing.fromJSON(info).toJSON())
|
|
87
|
+
assert.deepEqual(schema.schema, schemaDefinition)
|
|
88
|
+
assert.equal(schema.multiple, multiple)
|
|
89
|
+
assert.equal(schema.required, required)
|
|
90
|
+
assert.deepEqual(schema.bindings, bindings)
|
|
91
|
+
assert.deepEqual(schema.targets, targets)
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
test('creates a schema with cloned bindings', ({ assert }) => {
|
|
95
|
+
const bindings: AssociationBinding[] = [{ type: 'web', schema: { hidden: true } }]
|
|
96
|
+
const schema = DomainAssociation.createSchema({ bindings })
|
|
97
|
+
assert.deepEqual(schema.bindings, bindings)
|
|
98
|
+
assert.notStrictEqual(schema.bindings, bindings)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
test('creates a schema with cloned targets', ({ assert }) => {
|
|
102
|
+
const targets = [{ key: 'target1', domain: 'domain1' }, { key: 'target2' }]
|
|
103
|
+
const schema = DomainAssociation.createSchema({ targets })
|
|
104
|
+
assert.deepEqual(schema.targets, targets)
|
|
105
|
+
assert.notStrictEqual(schema.targets, targets)
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
test('creates a schema with cloned schema', ({ assert }) => {
|
|
109
|
+
const schemaDefinition: AmfShapes.IApiAssociationShape = { linked: false }
|
|
110
|
+
const schema = DomainAssociation.createSchema({ schema: schemaDefinition })
|
|
111
|
+
assert.deepEqual(schema.schema, schemaDefinition)
|
|
112
|
+
assert.notStrictEqual(schema.schema, schemaDefinition)
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
test.group('DomainAssociation.constructor()', () => {
|
|
117
|
+
test('creates a valid instance with default values', ({ assert }) => {
|
|
118
|
+
const dataDomain = new DataDomain()
|
|
119
|
+
const parentKey = 'test-parent'
|
|
120
|
+
const association = new DomainAssociation(dataDomain, parentKey)
|
|
121
|
+
assert.equal(association.kind, DomainAssociationKind)
|
|
122
|
+
assert.typeOf(association.key, 'string')
|
|
123
|
+
assert.deepEqual(association.info.toJSON(), Thing.fromJSON({ name: 'New association' }).toJSON())
|
|
124
|
+
assert.isUndefined(association.schema)
|
|
125
|
+
assert.isUndefined(association.multiple)
|
|
126
|
+
assert.isUndefined(association.required)
|
|
127
|
+
assert.deepEqual(association.bindings, [])
|
|
128
|
+
assert.deepEqual(association.targets, [])
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
test('creates an instance with provided key', ({ assert }) => {
|
|
132
|
+
const dataDomain = new DataDomain()
|
|
133
|
+
const parentKey = 'test-parent'
|
|
134
|
+
const key = 'test-key'
|
|
135
|
+
const association = new DomainAssociation(dataDomain, parentKey, { key })
|
|
136
|
+
assert.equal(association.key, key)
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
test('creates an instance with provided info', ({ assert }) => {
|
|
140
|
+
const dataDomain = new DataDomain()
|
|
141
|
+
const parentKey = 'test-parent'
|
|
142
|
+
const info = { name: 'Test Association', description: 'Test description' }
|
|
143
|
+
const association = new DomainAssociation(dataDomain, parentKey, { info })
|
|
144
|
+
assert.deepEqual(association.info.toJSON(), Thing.fromJSON(info).toJSON())
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
test('creates an instance with provided schema', ({ assert }) => {
|
|
148
|
+
const dataDomain = new DataDomain()
|
|
149
|
+
const parentKey = 'test-parent'
|
|
150
|
+
const schemaDefinition: AmfShapes.IApiAssociationShape = { linked: false }
|
|
151
|
+
const association = new DomainAssociation(dataDomain, parentKey, { schema: schemaDefinition })
|
|
152
|
+
assert.deepEqual(association.schema, schemaDefinition)
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
test('creates an instance with provided multiple', ({ assert }) => {
|
|
156
|
+
const dataDomain = new DataDomain()
|
|
157
|
+
const parentKey = 'test-parent'
|
|
158
|
+
const association = new DomainAssociation(dataDomain, parentKey, { multiple: true })
|
|
159
|
+
assert.isTrue(association.multiple)
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
test('creates an instance with provided required', ({ assert }) => {
|
|
163
|
+
const dataDomain = new DataDomain()
|
|
164
|
+
const parentKey = 'test-parent'
|
|
165
|
+
const association = new DomainAssociation(dataDomain, parentKey, { required: true })
|
|
166
|
+
assert.isTrue(association.required)
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
test('creates an instance with provided bindings', ({ assert }) => {
|
|
170
|
+
const dataDomain = new DataDomain()
|
|
171
|
+
const parentKey = 'test-parent'
|
|
172
|
+
const bindings: AssociationBinding[] = [{ type: 'web', schema: { hidden: true } }]
|
|
173
|
+
const association = new DomainAssociation(dataDomain, parentKey, { bindings })
|
|
174
|
+
assert.deepEqual(association.bindings, bindings)
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
test('creates an instance with provided targets', ({ assert }) => {
|
|
178
|
+
const dataDomain = new DataDomain()
|
|
179
|
+
const parentKey = 'test-parent'
|
|
180
|
+
const targets = [{ key: 'target1', domain: 'domain1' }, { key: 'target2' }]
|
|
181
|
+
const association = new DomainAssociation(dataDomain, parentKey, { targets })
|
|
182
|
+
assert.deepEqual(association.targets, targets)
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
test('creates an instance with all properties', ({ assert }) => {
|
|
186
|
+
const dataDomain = new DataDomain()
|
|
187
|
+
const parentKey = 'test-parent'
|
|
188
|
+
const key = 'test-key'
|
|
189
|
+
const info = { name: 'Test Association', description: 'Test description' }
|
|
190
|
+
const schemaDefinition: AmfShapes.IApiAssociationShape = { linked: false }
|
|
191
|
+
const multiple = true
|
|
192
|
+
const required = true
|
|
193
|
+
const bindings: AssociationBinding[] = [{ type: 'web', schema: { hidden: false } }]
|
|
194
|
+
const targets = [{ key: 'target1', domain: 'domain1' }, { key: 'target2' }]
|
|
195
|
+
|
|
196
|
+
const association = new DomainAssociation(dataDomain, parentKey, {
|
|
197
|
+
key,
|
|
198
|
+
info,
|
|
199
|
+
schema: schemaDefinition,
|
|
200
|
+
multiple,
|
|
201
|
+
required,
|
|
202
|
+
bindings,
|
|
203
|
+
targets,
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
assert.equal(association.key, key)
|
|
207
|
+
assert.deepEqual(association.info.toJSON(), Thing.fromJSON(info).toJSON())
|
|
208
|
+
assert.deepEqual(association.schema, schemaDefinition)
|
|
209
|
+
assert.equal(association.multiple, multiple)
|
|
210
|
+
assert.equal(association.required, required)
|
|
211
|
+
assert.deepEqual(association.bindings, bindings)
|
|
212
|
+
assert.deepEqual(association.targets, targets)
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
test('creates an instance with cloned bindings', ({ assert }) => {
|
|
216
|
+
const dataDomain = new DataDomain()
|
|
217
|
+
const parentKey = 'test-parent'
|
|
218
|
+
const bindings: AssociationBinding[] = [{ type: 'web', schema: { hidden: true } }]
|
|
219
|
+
const association = new DomainAssociation(dataDomain, parentKey, { bindings })
|
|
220
|
+
assert.deepEqual(association.bindings, bindings)
|
|
221
|
+
assert.notStrictEqual(association.bindings, bindings)
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
test('creates an instance with cloned targets', ({ assert }) => {
|
|
225
|
+
const dataDomain = new DataDomain()
|
|
226
|
+
const parentKey = 'test-parent'
|
|
227
|
+
const targets = [{ key: 'target1', domain: 'domain1' }, { key: 'target2' }]
|
|
228
|
+
const association = new DomainAssociation(dataDomain, parentKey, { targets })
|
|
229
|
+
assert.deepEqual(association.targets, targets)
|
|
230
|
+
assert.notStrictEqual(association.targets, targets)
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
test('creates an instance with cloned schema', ({ assert }) => {
|
|
234
|
+
const dataDomain = new DataDomain()
|
|
235
|
+
const parentKey = 'test-parent'
|
|
236
|
+
const schemaDefinition: AmfShapes.IApiAssociationShape = { linked: false }
|
|
237
|
+
const association = new DomainAssociation(dataDomain, parentKey, { schema: schemaDefinition })
|
|
238
|
+
assert.deepEqual(association.schema, schemaDefinition)
|
|
239
|
+
assert.notStrictEqual(association.schema, schemaDefinition)
|
|
240
|
+
})
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
test.group('DomainAssociation.toJSON()', () => {
|
|
244
|
+
test('returns a valid JSON representation with default values', ({ assert }) => {
|
|
245
|
+
const dataDomain = new DataDomain()
|
|
246
|
+
const parentKey = 'test-parent'
|
|
247
|
+
const association = new DomainAssociation(dataDomain, parentKey)
|
|
248
|
+
const json = association.toJSON()
|
|
249
|
+
assert.equal(json.kind, DomainAssociationKind)
|
|
250
|
+
assert.typeOf(json.key, 'string')
|
|
251
|
+
assert.deepEqual(json.info, Thing.fromJSON({ name: 'New association' }).toJSON())
|
|
252
|
+
assert.isUndefined(json.schema)
|
|
253
|
+
assert.isUndefined(json.multiple)
|
|
254
|
+
assert.isUndefined(json.required)
|
|
255
|
+
assert.isUndefined(json.bindings)
|
|
256
|
+
assert.isUndefined(json.targets)
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
test('returns a JSON representation with provided key', ({ assert }) => {
|
|
260
|
+
const dataDomain = new DataDomain()
|
|
261
|
+
const parentKey = 'test-parent'
|
|
262
|
+
const key = 'test-key'
|
|
263
|
+
const association = new DomainAssociation(dataDomain, parentKey, { key })
|
|
264
|
+
const json = association.toJSON()
|
|
265
|
+
assert.equal(json.key, key)
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
test('returns a JSON representation with provided info', ({ assert }) => {
|
|
269
|
+
const dataDomain = new DataDomain()
|
|
270
|
+
const parentKey = 'test-parent'
|
|
271
|
+
const info = { name: 'Test Association', description: 'Test description' }
|
|
272
|
+
const association = new DomainAssociation(dataDomain, parentKey, { info })
|
|
273
|
+
const json = association.toJSON()
|
|
274
|
+
assert.deepEqual(json.info, Thing.fromJSON(info).toJSON())
|
|
275
|
+
})
|
|
276
|
+
|
|
277
|
+
test('returns a JSON representation with provided schema', ({ assert }) => {
|
|
278
|
+
const dataDomain = new DataDomain()
|
|
279
|
+
const parentKey = 'test-parent'
|
|
280
|
+
const schemaDefinition: AmfShapes.IApiAssociationShape = { linked: false }
|
|
281
|
+
const association = new DomainAssociation(dataDomain, parentKey, { schema: schemaDefinition })
|
|
282
|
+
const json = association.toJSON()
|
|
283
|
+
assert.deepEqual(json.schema, schemaDefinition)
|
|
284
|
+
assert.notStrictEqual(json.schema, schemaDefinition)
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
test('returns a JSON representation with provided multiple', ({ assert }) => {
|
|
288
|
+
const dataDomain = new DataDomain()
|
|
289
|
+
const parentKey = 'test-parent'
|
|
290
|
+
const association = new DomainAssociation(dataDomain, parentKey, { multiple: true })
|
|
291
|
+
const json = association.toJSON()
|
|
292
|
+
assert.isTrue(json.multiple)
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
test('returns a JSON representation with provided required', ({ assert }) => {
|
|
296
|
+
const dataDomain = new DataDomain()
|
|
297
|
+
const parentKey = 'test-parent'
|
|
298
|
+
const association = new DomainAssociation(dataDomain, parentKey, { required: true })
|
|
299
|
+
const json = association.toJSON()
|
|
300
|
+
assert.isTrue(json.required)
|
|
301
|
+
})
|
|
302
|
+
|
|
303
|
+
test('returns a JSON representation with provided bindings', ({ assert }) => {
|
|
304
|
+
const dataDomain = new DataDomain()
|
|
305
|
+
const parentKey = 'test-parent'
|
|
306
|
+
const bindings: AssociationBinding[] = [{ type: 'web', schema: { hidden: true } }]
|
|
307
|
+
const association = new DomainAssociation(dataDomain, parentKey, { bindings })
|
|
308
|
+
const json = association.toJSON()
|
|
309
|
+
assert.deepEqual(json.bindings, bindings)
|
|
310
|
+
assert.notStrictEqual(json.bindings, bindings)
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
test('returns a JSON representation with provided targets', ({ assert }) => {
|
|
314
|
+
const dataDomain = new DataDomain()
|
|
315
|
+
const parentKey = 'test-parent'
|
|
316
|
+
const targets = [{ key: 'target1', domain: 'domain1' }, { key: 'target2' }]
|
|
317
|
+
const association = new DomainAssociation(dataDomain, parentKey, { targets })
|
|
318
|
+
const json = association.toJSON()
|
|
319
|
+
assert.deepEqual(json.targets, targets)
|
|
320
|
+
assert.notStrictEqual(json.targets, targets)
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
test('returns a JSON representation with all properties', ({ assert }) => {
|
|
324
|
+
const dataDomain = new DataDomain()
|
|
325
|
+
const parentKey = 'test-parent'
|
|
326
|
+
const key = 'test-key'
|
|
327
|
+
const info = { name: 'Test Association', description: 'Test description' }
|
|
328
|
+
const schemaDefinition: AmfShapes.IApiAssociationShape = { linked: false }
|
|
329
|
+
const multiple = true
|
|
330
|
+
const required = true
|
|
331
|
+
const bindings: AssociationBinding[] = [{ type: 'web', schema: { hidden: false } }]
|
|
332
|
+
const targets = [{ key: 'target1', domain: 'domain1' }, { key: 'target2' }]
|
|
333
|
+
|
|
334
|
+
const association = new DomainAssociation(dataDomain, parentKey, {
|
|
335
|
+
key,
|
|
336
|
+
info,
|
|
337
|
+
schema: schemaDefinition,
|
|
338
|
+
multiple,
|
|
339
|
+
required,
|
|
340
|
+
bindings,
|
|
341
|
+
targets,
|
|
342
|
+
})
|
|
343
|
+
|
|
344
|
+
const json = association.toJSON()
|
|
345
|
+
|
|
346
|
+
assert.equal(json.key, key)
|
|
347
|
+
assert.deepEqual(json.info, Thing.fromJSON(info).toJSON())
|
|
348
|
+
assert.deepEqual(json.schema, schemaDefinition)
|
|
349
|
+
assert.equal(json.multiple, multiple)
|
|
350
|
+
assert.equal(json.required, required)
|
|
351
|
+
assert.deepEqual(json.bindings, bindings)
|
|
352
|
+
assert.deepEqual(json.targets, targets)
|
|
353
|
+
})
|
|
354
|
+
|
|
355
|
+
test('returns a JSON representation with cloned bindings', ({ assert }) => {
|
|
356
|
+
const dataDomain = new DataDomain()
|
|
357
|
+
const parentKey = 'test-parent'
|
|
358
|
+
const bindings: AssociationBinding[] = [{ type: 'web', schema: { hidden: true } }]
|
|
359
|
+
const association = new DomainAssociation(dataDomain, parentKey, { bindings })
|
|
360
|
+
const json = association.toJSON()
|
|
361
|
+
assert.deepEqual(json.bindings, bindings)
|
|
362
|
+
assert.notStrictEqual(json.bindings, bindings)
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
test('returns a JSON representation with cloned targets', ({ assert }) => {
|
|
366
|
+
const dataDomain = new DataDomain()
|
|
367
|
+
const parentKey = 'test-parent'
|
|
368
|
+
const targets = [{ key: 'target1', domain: 'domain1' }, { key: 'target2' }]
|
|
369
|
+
const association = new DomainAssociation(dataDomain, parentKey, { targets })
|
|
370
|
+
const json = association.toJSON()
|
|
371
|
+
assert.deepEqual(json.targets, targets)
|
|
372
|
+
assert.notStrictEqual(json.targets, targets)
|
|
373
|
+
})
|
|
374
|
+
|
|
375
|
+
test('returns a JSON representation with cloned schema', ({ assert }) => {
|
|
376
|
+
const dataDomain = new DataDomain()
|
|
377
|
+
const parentKey = 'test-parent'
|
|
378
|
+
const schemaDefinition: AmfShapes.IApiAssociationShape = { linked: false }
|
|
379
|
+
const association = new DomainAssociation(dataDomain, parentKey, { schema: schemaDefinition })
|
|
380
|
+
const json = association.toJSON()
|
|
381
|
+
assert.deepEqual(json.schema, schemaDefinition)
|
|
382
|
+
assert.notStrictEqual(json.schema, schemaDefinition)
|
|
383
|
+
})
|
|
384
|
+
|
|
385
|
+
test('returns a JSON representation with cloned schema when it is set after creation', ({ assert }) => {
|
|
386
|
+
const dataDomain = new DataDomain()
|
|
387
|
+
const parentKey = 'test-parent'
|
|
388
|
+
const association = new DomainAssociation(dataDomain, parentKey)
|
|
389
|
+
const schemaDefinition: AmfShapes.IApiAssociationShape = { linked: false }
|
|
390
|
+
association.schema = schemaDefinition
|
|
391
|
+
const json = association.toJSON()
|
|
392
|
+
assert.deepEqual(json.schema, schemaDefinition)
|
|
393
|
+
assert.notStrictEqual(json.schema, schemaDefinition)
|
|
394
|
+
})
|
|
395
|
+
|
|
396
|
+
test('returns a JSON representation with cloned bindings when it is set after creation', ({ assert }) => {
|
|
397
|
+
const dataDomain = new DataDomain()
|
|
398
|
+
const parentKey = 'test-parent'
|
|
399
|
+
const association = new DomainAssociation(dataDomain, parentKey)
|
|
400
|
+
const bindings: AssociationBinding[] = [{ type: 'web', schema: { hidden: true } }]
|
|
401
|
+
association.bindings = bindings
|
|
402
|
+
const json = association.toJSON()
|
|
403
|
+
assert.deepEqual(json.bindings, bindings)
|
|
404
|
+
assert.notStrictEqual(json.bindings, bindings)
|
|
405
|
+
})
|
|
406
|
+
|
|
407
|
+
test('returns a JSON representation with cloned targets when it is set after creation', ({ assert }) => {
|
|
408
|
+
const dataDomain = new DataDomain()
|
|
409
|
+
const parentKey = 'test-parent'
|
|
410
|
+
const association = new DomainAssociation(dataDomain, parentKey)
|
|
411
|
+
const targets = [{ key: 'target1', domain: 'domain1' }, { key: 'target2' }]
|
|
412
|
+
association.targets = targets
|
|
413
|
+
const json = association.toJSON()
|
|
414
|
+
assert.deepEqual(json.targets, targets)
|
|
415
|
+
assert.notStrictEqual(json.targets, targets)
|
|
416
|
+
})
|
|
417
|
+
})
|
|
418
|
+
|
|
419
|
+
test.group('DomainAssociation.getParentInstance()', () => {
|
|
420
|
+
test('returns the parent entity when the association is a child', ({ assert }) => {
|
|
421
|
+
const dataDomain = new DataDomain()
|
|
422
|
+
const model = dataDomain.addModel()
|
|
423
|
+
const entity = model.addEntity()
|
|
424
|
+
const association = entity.addAssociation()
|
|
425
|
+
const parent = association.getParentInstance()
|
|
426
|
+
assert.deepEqual(parent, entity)
|
|
427
|
+
})
|
|
428
|
+
|
|
429
|
+
test('returns undefined when the association has no parent', ({ assert }) => {
|
|
430
|
+
const dataDomain = new DataDomain()
|
|
431
|
+
const association = new DomainAssociation(dataDomain, 'non-existent-entity')
|
|
432
|
+
dataDomain.graph.setNode(association.key, association)
|
|
433
|
+
const parent = association.getParentInstance()
|
|
434
|
+
assert.isUndefined(parent)
|
|
435
|
+
})
|
|
436
|
+
|
|
437
|
+
test('returns the correct parent when there are multiple levels of nesting', ({ assert }) => {
|
|
438
|
+
const dataDomain = new DataDomain()
|
|
439
|
+
const model = dataDomain.addModel()
|
|
440
|
+
const entity = model.addEntity()
|
|
441
|
+
const association = entity.addAssociation()
|
|
442
|
+
const parent = association.getParentInstance()
|
|
443
|
+
assert.deepEqual(parent, entity)
|
|
444
|
+
})
|
|
445
|
+
|
|
446
|
+
test('returns undefined when the parent entity is removed from the graph', ({ assert }) => {
|
|
447
|
+
const dataDomain = new DataDomain()
|
|
448
|
+
const model = dataDomain.addModel()
|
|
449
|
+
const entity = model.addEntity()
|
|
450
|
+
const association = entity.addAssociation()
|
|
451
|
+
dataDomain.graph.removeNode(entity.key)
|
|
452
|
+
const parent = association.getParentInstance()
|
|
453
|
+
assert.isUndefined(parent)
|
|
454
|
+
})
|
|
455
|
+
})
|
|
456
|
+
|
|
457
|
+
test.group('DomainAssociation.remove()', () => {
|
|
458
|
+
test('removes the association from the parent entity', ({ assert }) => {
|
|
459
|
+
const dataDomain = new DataDomain()
|
|
460
|
+
const model = dataDomain.addModel()
|
|
461
|
+
const entity = model.addEntity()
|
|
462
|
+
const association = entity.addAssociation()
|
|
463
|
+
association.remove()
|
|
464
|
+
assert.isFalse(dataDomain.graph.hasNode(association.key))
|
|
465
|
+
assert.deepEqual(entity.fields, [])
|
|
466
|
+
})
|
|
467
|
+
|
|
468
|
+
test('throws if the parent entity does not have the association', ({ assert }) => {
|
|
469
|
+
const dataDomain = new DataDomain()
|
|
470
|
+
const model = dataDomain.addModel()
|
|
471
|
+
const entity1 = model.addEntity()
|
|
472
|
+
const entity2 = model.addEntity()
|
|
473
|
+
const association = entity1.addAssociation()
|
|
474
|
+
assert.throws(() => {
|
|
475
|
+
entity2.removeAssociation(association.key)
|
|
476
|
+
}, `Unable to find a connection between this entity and the ${association.key} association`)
|
|
477
|
+
})
|
|
478
|
+
|
|
479
|
+
test('removes the association from the graph', ({ assert }) => {
|
|
480
|
+
const dataDomain = new DataDomain()
|
|
481
|
+
const model = dataDomain.addModel()
|
|
482
|
+
const entity = model.addEntity()
|
|
483
|
+
const association = entity.addAssociation()
|
|
484
|
+
association.remove()
|
|
485
|
+
assert.isFalse(dataDomain.graph.hasNode(association.key))
|
|
486
|
+
})
|
|
487
|
+
|
|
488
|
+
test('removes the association from the parent entity fields', ({ assert }) => {
|
|
489
|
+
const dataDomain = new DataDomain()
|
|
490
|
+
const model = dataDomain.addModel()
|
|
491
|
+
const entity = model.addEntity()
|
|
492
|
+
const association = entity.addAssociation()
|
|
493
|
+
association.remove()
|
|
494
|
+
assert.deepEqual(entity.fields, [])
|
|
495
|
+
})
|
|
496
|
+
|
|
497
|
+
test('removes the association from the graph when it has targets', ({ assert }) => {
|
|
498
|
+
const dataDomain = new DataDomain()
|
|
499
|
+
const model = dataDomain.addModel()
|
|
500
|
+
const entity1 = model.addEntity()
|
|
501
|
+
const entity2 = model.addEntity()
|
|
502
|
+
const association = entity1.addAssociation()
|
|
503
|
+
association.addTarget(entity2)
|
|
504
|
+
association.remove()
|
|
505
|
+
assert.isFalse(dataDomain.graph.hasNode(association.key))
|
|
506
|
+
assert.isFalse(dataDomain.graph.hasEdge(association.key, entity2.key))
|
|
507
|
+
})
|
|
508
|
+
})
|
|
509
|
+
|
|
510
|
+
test.group('DomainAssociation.ensureSchema()', () => {
|
|
511
|
+
test('creates the schema object if it does not exist', ({ assert }) => {
|
|
512
|
+
const dataDomain = new DataDomain()
|
|
513
|
+
const association = new DomainAssociation(dataDomain, 'test-parent')
|
|
514
|
+
assert.isUndefined(association.schema)
|
|
515
|
+
const schema = association.ensureSchema()
|
|
516
|
+
assert.isDefined(association.schema)
|
|
517
|
+
assert.deepEqual(schema, {})
|
|
518
|
+
assert.deepEqual(schema, schema)
|
|
519
|
+
})
|
|
520
|
+
|
|
521
|
+
test('returns the existing schema object if it exists', ({ assert }) => {
|
|
522
|
+
const dataDomain = new DataDomain()
|
|
523
|
+
const schemaDefinition: AmfShapes.IApiAssociationShape = { linked: false }
|
|
524
|
+
const association = new DomainAssociation(dataDomain, 'test-parent', { schema: schemaDefinition })
|
|
525
|
+
const originalSchema = association.schema
|
|
526
|
+
const schema = association.ensureSchema()
|
|
527
|
+
assert.deepEqual(schema, schemaDefinition)
|
|
528
|
+
assert.strictEqual(schema, originalSchema)
|
|
529
|
+
})
|
|
530
|
+
|
|
531
|
+
test('does not modify the existing schema object', ({ assert }) => {
|
|
532
|
+
const dataDomain = new DataDomain()
|
|
533
|
+
const schemaDefinition: AmfShapes.IApiAssociationShape = { linked: false }
|
|
534
|
+
const association = new DomainAssociation(dataDomain, 'test-parent', { schema: schemaDefinition })
|
|
535
|
+
const originalSchema = association.schema
|
|
536
|
+
association.ensureSchema()
|
|
537
|
+
assert.deepEqual(association.schema, schemaDefinition)
|
|
538
|
+
assert.strictEqual(association.schema, originalSchema)
|
|
539
|
+
})
|
|
540
|
+
})
|
|
541
|
+
|
|
542
|
+
test.group('DomainAssociation.isValidAttribute()', () => {
|
|
543
|
+
test('returns true for valid data association attributes', ({ assert }) => {
|
|
544
|
+
const validAttributes: DataFormat.DomainAttributeAttribute[] = ['required', 'multiple']
|
|
545
|
+
validAttributes.forEach((attribute) => {
|
|
546
|
+
assert.isTrue(DomainAssociation.isValidAttribute(attribute), `Attribute "${attribute}" should be valid`)
|
|
547
|
+
})
|
|
548
|
+
})
|
|
549
|
+
|
|
550
|
+
test('returns false for invalid data association attributes', ({ assert }) => {
|
|
551
|
+
assert.isFalse(DomainAssociation.isValidAttribute('invalid-attribute'))
|
|
552
|
+
assert.isFalse(DomainAssociation.isValidAttribute(123))
|
|
553
|
+
assert.isFalse(DomainAssociation.isValidAttribute(true))
|
|
554
|
+
assert.isFalse(DomainAssociation.isValidAttribute({}))
|
|
555
|
+
assert.isFalse(DomainAssociation.isValidAttribute([]))
|
|
556
|
+
assert.isFalse(DomainAssociation.isValidAttribute(null))
|
|
557
|
+
assert.isFalse(DomainAssociation.isValidAttribute(undefined))
|
|
558
|
+
})
|
|
559
|
+
|
|
560
|
+
test('returns false for non-string values', ({ assert }) => {
|
|
561
|
+
assert.isFalse(DomainAssociation.isValidAttribute(123))
|
|
562
|
+
assert.isFalse(DomainAssociation.isValidAttribute(true))
|
|
563
|
+
assert.isFalse(DomainAssociation.isValidAttribute({}))
|
|
564
|
+
assert.isFalse(DomainAssociation.isValidAttribute([]))
|
|
565
|
+
assert.isFalse(DomainAssociation.isValidAttribute(null))
|
|
566
|
+
assert.isFalse(DomainAssociation.isValidAttribute(undefined))
|
|
567
|
+
})
|
|
568
|
+
|
|
569
|
+
test('returns false for empty string', ({ assert }) => {
|
|
570
|
+
assert.isFalse(DomainAssociation.isValidAttribute(''))
|
|
571
|
+
})
|
|
572
|
+
})
|
|
573
|
+
|
|
574
|
+
test.group('DomainAssociation.getWebBinding()', () => {
|
|
575
|
+
test('creates web bindings if they do not exist', ({ assert }) => {
|
|
576
|
+
const dataDomain = new DataDomain()
|
|
577
|
+
const association = new DomainAssociation(dataDomain, 'test-parent')
|
|
578
|
+
const webBindings = association.getWebBinding()
|
|
579
|
+
assert.isDefined(webBindings)
|
|
580
|
+
assert.deepEqual(webBindings, {})
|
|
581
|
+
assert.lengthOf(association.bindings, 1)
|
|
582
|
+
assert.equal(association.bindings[0].type, 'web')
|
|
583
|
+
})
|
|
584
|
+
|
|
585
|
+
test('returns existing web bindings if they exist', ({ assert }) => {
|
|
586
|
+
const dataDomain = new DataDomain()
|
|
587
|
+
const association = new DomainAssociation(dataDomain, 'test-parent', {
|
|
588
|
+
bindings: [{ type: 'web', schema: { hidden: true } }],
|
|
589
|
+
})
|
|
590
|
+
const webBindings = association.getWebBinding()
|
|
591
|
+
assert.isDefined(webBindings)
|
|
592
|
+
assert.deepEqual(webBindings, { hidden: true })
|
|
593
|
+
assert.lengthOf(association.bindings, 1)
|
|
594
|
+
assert.equal(association.bindings[0].type, 'web')
|
|
595
|
+
})
|
|
596
|
+
|
|
597
|
+
test('does not modify existing web bindings object', ({ assert }) => {
|
|
598
|
+
const dataDomain = new DataDomain()
|
|
599
|
+
const association = new DomainAssociation(dataDomain, 'test-parent', {
|
|
600
|
+
bindings: [{ type: 'web', schema: { hidden: true } }],
|
|
601
|
+
})
|
|
602
|
+
const originalBindings = association.bindings[0].schema
|
|
603
|
+
association.getWebBinding()
|
|
604
|
+
assert.deepEqual(association.bindings[0].schema, { hidden: true })
|
|
605
|
+
assert.deepEqual(association.bindings[0].schema, originalBindings)
|
|
606
|
+
})
|
|
607
|
+
|
|
608
|
+
test('notifies change when creating new bindings', async ({ assert }) => {
|
|
609
|
+
const dataDomain = new DataDomain()
|
|
610
|
+
const association = new DomainAssociation(dataDomain, 'test-parent')
|
|
611
|
+
const webBindings = association.getWebBinding()
|
|
612
|
+
assert.isDefined(webBindings)
|
|
613
|
+
await assert.dispatches(dataDomain, 'change', { timeout: 20 })
|
|
614
|
+
})
|
|
615
|
+
})
|
|
616
|
+
|
|
617
|
+
test.group('DomainAssociation.readBinding()', () => {
|
|
618
|
+
test('returns undefined if no binding exists for the given type', ({ assert }) => {
|
|
619
|
+
const dataDomain = new DataDomain()
|
|
620
|
+
const association = new DomainAssociation(dataDomain, 'test-parent')
|
|
621
|
+
const binding = association.readBinding('web')
|
|
622
|
+
assert.isUndefined(binding)
|
|
623
|
+
})
|
|
624
|
+
|
|
625
|
+
test('returns the web binding schema if it exists', ({ assert }) => {
|
|
626
|
+
const dataDomain = new DataDomain()
|
|
627
|
+
const association = new DomainAssociation(dataDomain, 'test-parent', {
|
|
628
|
+
bindings: [{ type: 'web', schema: { hidden: true } }],
|
|
629
|
+
})
|
|
630
|
+
const webBindings = association.readBinding('web')
|
|
631
|
+
assert.deepEqual(webBindings, { hidden: true })
|
|
632
|
+
})
|
|
633
|
+
|
|
634
|
+
test('returns undefined if the binding exists but has no schema', ({ assert }) => {
|
|
635
|
+
const dataDomain = new DataDomain()
|
|
636
|
+
const association = new DomainAssociation(dataDomain, 'test-parent', {
|
|
637
|
+
// @ts-expect-error Testing undefined schema
|
|
638
|
+
bindings: [{ type: 'web', schema: undefined }],
|
|
639
|
+
})
|
|
640
|
+
const webBindings = association.readBinding('web')
|
|
641
|
+
assert.isUndefined(webBindings)
|
|
642
|
+
})
|
|
643
|
+
})
|