@api-client/core 0.11.1 → 0.11.2

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.
@@ -11,6 +11,8 @@ import {
11
11
  ValidationError,
12
12
  RemovePropertyException,
13
13
  RemoveAssociationException,
14
+ RemoveEntityException,
15
+ ForeignAssociationException,
14
16
  } from '../../../src/index.js'
15
17
 
16
18
  test.group('constructor() with defaults', (group) => {
@@ -265,6 +267,47 @@ test.group('new()', (group) => {
265
267
  assoc.new({})
266
268
  }, 'Invalid data entity definition.')
267
269
  })
270
+
271
+ test('sets the fields as a copy', ({ assert }) => {
272
+ const src = new DataEntity(root)
273
+ const p1 = src.addNamedProperty('p1')
274
+ const a1 = src.addNamedAssociation('a1')
275
+ const assoc = new DataEntity(root)
276
+ const init = src.toJSON()
277
+ assoc.new(init)
278
+ assert.deepEqual(assoc.fields, [
279
+ { type: 'property', key: p1.key },
280
+ { type: 'association', key: a1.key },
281
+ ])
282
+ const p2 = src.addNamedProperty('p2')
283
+ init.fields!.push({ type: 'property', key: p2.key })
284
+ assert.deepEqual(assoc.fields, [
285
+ { type: 'property', key: p1.key },
286
+ { type: 'association', key: a1.key },
287
+ ])
288
+ })
289
+
290
+ test('resets fields when not in the input', ({ assert }) => {
291
+ const assoc = new DataEntity(root)
292
+ assoc.addNamedProperty('p1')
293
+ assoc.addNamedAssociation('a1')
294
+ assoc.new(base)
295
+ assert.deepEqual(assoc.fields, [])
296
+ })
297
+
298
+ test('creates fields when missing', ({ assert }) => {
299
+ const assoc = new DataEntity(root)
300
+ const p1 = assoc.addNamedProperty('p1')
301
+ const a1 = assoc.addNamedAssociation('a1')
302
+ const init = assoc.toJSON()
303
+ delete init.fields
304
+ const instance = new DataEntity(root)
305
+ instance.new(init)
306
+ assert.deepEqual(instance.fields, [
307
+ { type: 'property', key: p1.key },
308
+ { type: 'association', key: a1.key },
309
+ ])
310
+ })
268
311
  })
269
312
 
270
313
  test.group('toJSON()', (group) => {
@@ -358,6 +401,37 @@ test.group('toJSON()', (group) => {
358
401
  base.addNamedAssociation('a2')
359
402
  assert.deepEqual(result.associations, [a1.key])
360
403
  })
404
+
405
+ test('serializes fields as a copy', ({ assert }) => {
406
+ const p1 = base.addNamedProperty('p1')
407
+ const a1 = base.addNamedAssociation('a1')
408
+ const result = base.toJSON()
409
+ assert.deepEqual(result.fields, [
410
+ { type: 'property', key: p1.key },
411
+ { type: 'association', key: a1.key },
412
+ ])
413
+ base.addNamedProperty('p2')
414
+ assert.deepEqual(result.fields, [
415
+ { type: 'property', key: p1.key },
416
+ { type: 'association', key: a1.key },
417
+ ])
418
+ })
419
+
420
+ test('does not serialize fields when empty', ({ assert }) => {
421
+ const result = base.toJSON()
422
+ assert.isUndefined(result.fields)
423
+ })
424
+
425
+ test('does not serialize deprecated by default', ({ assert }) => {
426
+ const result = base.toJSON()
427
+ assert.isUndefined(result.deprecated)
428
+ })
429
+
430
+ test('serialize the set deprecated', ({ assert }) => {
431
+ base.deprecated = false
432
+ const result = base.toJSON()
433
+ assert.isFalse(result.deprecated)
434
+ })
361
435
  })
362
436
 
363
437
  test.group('remove()', (group) => {
@@ -399,6 +473,16 @@ test.group('remove()', (group) => {
399
473
  assert.deepEqual(e2.associations, [a2])
400
474
  assert.deepEqual(root.definitions.associations, [a2])
401
475
  })
476
+
477
+ test('throws when removing an entity that is a target', ({ assert }) => {
478
+ // const e3 = m1.addEntity('e3')
479
+ e2.addTargetAssociation(e1.key)
480
+ assert.throws(
481
+ () => e1.remove(),
482
+ RemoveEntityException as unknown as ErrorConstructor,
483
+ `Cannot remove entity ${e1.info.name} because it is used as a target in associations in entities: e2.`
484
+ )
485
+ })
402
486
  })
403
487
 
404
488
  test.group('addTypedProperty()', (group) => {
@@ -639,6 +723,22 @@ test.group('addForeignAssociation()', (group) => {
639
723
  const a1 = e1.addForeignAssociation(e2.key, n2.key, 'my name')
640
724
  assert.equal(a1.info.name, 'my name')
641
725
  })
726
+
727
+ test('throws when the foreign namespace is not defined', ({ assert }) => {
728
+ assert.throws(
729
+ () => e1.addForeignAssociation(e2.key, 'unknown'),
730
+ ForeignAssociationException as unknown as ErrorConstructor,
731
+ 'Trying to add a foreign association but the foreign namespace is not defined.'
732
+ )
733
+ })
734
+
735
+ test('throws when adding a foreign association that targets the same entity', ({ assert }) => {
736
+ assert.throws(
737
+ () => e1.addForeignAssociation(e1.key, n1.key),
738
+ ForeignAssociationException as unknown as ErrorConstructor,
739
+ 'Trying to add a foreign association but the foreign namespace is not defined.'
740
+ )
741
+ })
642
742
  })
643
743
 
644
744
  test.group('removeAssociation()', (group) => {
@@ -777,6 +877,23 @@ test.group('getComputedChildren()', (group) => {
777
877
  const result = e1.getComputedChildren()
778
878
  assert.deepEqual(result, [e2])
779
879
  })
880
+
881
+ test('returns grandchildren', ({ assert }) => {
882
+ const e2 = m1.addEntity('e2')
883
+ const e3 = m1.addEntity('e3')
884
+ e2.addParent(e1.key)
885
+ e3.addParent(e2.key)
886
+ const result = e1.getComputedChildren()
887
+ assert.deepEqual(result, [e2])
888
+ })
889
+
890
+ test('returns empty array when no direct children', ({ assert }) => {
891
+ const e2 = m1.addEntity('e2')
892
+ const e3 = m1.addEntity('e3')
893
+ e3.addParent(e2.key)
894
+ const result = e1.getComputedChildren()
895
+ assert.deepEqual(result, [])
896
+ })
780
897
  })
781
898
 
782
899
  test.group('getComputedAssociations()', (group) => {
@@ -842,6 +959,37 @@ test.group('getComputedAssociations()', (group) => {
842
959
  const result = e1.getComputedAssociations()
843
960
  assert.deepEqual(result, [])
844
961
  })
962
+
963
+ test('returns multiple associations', ({ assert }) => {
964
+ const e2 = m1.addEntity('e2')
965
+ const e3 = m1.addEntity('e3')
966
+ e1.addTargetAssociation(e2.key)
967
+ e1.addTargetAssociation(e3.key)
968
+
969
+ const result = e1.getComputedAssociations()
970
+ assert.deepEqual(result.sort(), [e2, e3].sort())
971
+ })
972
+
973
+ test('returns indirect associations', ({ assert }) => {
974
+ const e2 = m1.addEntity('e2')
975
+ const e3 = m1.addEntity('e3')
976
+ e1.addTargetAssociation(e2.key)
977
+ e2.addTargetAssociation(e3.key)
978
+
979
+ const result = e1.getComputedAssociations()
980
+ assert.deepEqual(result, [e2])
981
+ })
982
+
983
+ test('returns multiple targets', ({ assert }) => {
984
+ const e2 = m1.addEntity('e2')
985
+ const e3 = m1.addEntity('e3')
986
+ const a1 = e1.addNamedAssociation('a1')
987
+ a1.addTarget(e2)
988
+ a1.addTarget(e3)
989
+
990
+ const result = e1.getComputedAssociations()
991
+ assert.deepEqual(result.sort(), [e2, e3].sort())
992
+ })
845
993
  })
846
994
 
847
995
  test.group('associationPath()', (group) => {
@@ -924,12 +1072,71 @@ test.group('associationPath()', (group) => {
924
1072
  })
925
1073
  })
926
1074
 
1075
+ test.group('associationPath() - More Complex Scenarios', (group) => {
1076
+ let root: DataNamespace
1077
+ let model: DataModel
1078
+ let entityA: DataEntity
1079
+ let entityB: DataEntity
1080
+ let entityC: DataEntity
1081
+ let entityD: DataEntity
1082
+ let foreignRoot: DataNamespace
1083
+ let foreignEntity: DataEntity
1084
+
1085
+ group.each.setup(() => {
1086
+ root = new DataNamespace()
1087
+ model = root.addDataModel('model')
1088
+ entityA = model.addEntity('entityA')
1089
+ entityB = model.addEntity('entityB')
1090
+ entityC = model.addEntity('entityC')
1091
+ entityD = model.addEntity('entityD')
1092
+
1093
+ foreignRoot = new DataNamespace()
1094
+ root.addForeign(foreignRoot)
1095
+ const foreignModel = foreignRoot.addDataModel('foreignModel')
1096
+ foreignEntity = foreignModel.addEntity('foreignEntity')
1097
+ })
1098
+
1099
+ test('returns multiple paths when multiple indirect associations', ({ assert }) => {
1100
+ entityA.addTargetAssociation(entityB.key)
1101
+ entityA.addTargetAssociation(entityC.key)
1102
+ entityB.addTargetAssociation(entityD.key)
1103
+ entityC.addTargetAssociation(entityD.key)
1104
+ const result = [...entityA.associationPath(entityD.key)]
1105
+ assert.deepEqual(result, [
1106
+ [entityA.key, entityC.key, entityD.key],
1107
+ [entityA.key, entityB.key, entityD.key],
1108
+ ])
1109
+ })
1110
+
1111
+ test('returns empty array when not associated', ({ assert }) => {
1112
+ entityA.addTargetAssociation(entityB.key)
1113
+ const result = [...entityA.associationPath(entityC.key)]
1114
+ assert.deepEqual(result, [])
1115
+ })
1116
+
1117
+ test('returns empty array when no associations in foreign namespaces', ({ assert }) => {
1118
+ entityA.addForeignAssociation(foreignEntity.key, foreignRoot.key)
1119
+ const result = [...entityA.associationPath(entityB.key)]
1120
+ assert.deepEqual(result, [])
1121
+ })
1122
+
1123
+ test('returns the path when foreign association', ({ assert }) => {
1124
+ entityA.addForeignAssociation(foreignEntity.key, foreignRoot.key)
1125
+ const result = [...entityA.associationPath(foreignEntity.key)]
1126
+ assert.deepEqual(result, [[entityA.key, foreignEntity.key]])
1127
+ })
1128
+ })
1129
+
927
1130
  test.group('isAssociated()', (group) => {
928
1131
  let root: DataNamespace
929
1132
  let m1: DataModel
930
1133
  let e1: DataEntity
931
1134
  let e2: DataEntity
932
1135
  let e3: DataEntity
1136
+ let e4: DataEntity
1137
+
1138
+ let foreignRoot: DataNamespace
1139
+ let foreignEntity: DataEntity
933
1140
 
934
1141
  group.each.setup(() => {
935
1142
  root = new DataNamespace()
@@ -937,6 +1144,12 @@ test.group('isAssociated()', (group) => {
937
1144
  e1 = m1.addEntity('e1')
938
1145
  e2 = m1.addEntity('e2')
939
1146
  e3 = m1.addEntity('e3')
1147
+ e4 = m1.addEntity('e4')
1148
+
1149
+ foreignRoot = new DataNamespace()
1150
+ root.addForeign(foreignRoot)
1151
+ const foreignModel = foreignRoot.addDataModel('foreignModel')
1152
+ foreignEntity = foreignModel.addEntity('foreignEntity')
940
1153
  })
941
1154
 
942
1155
  test('returns true when testing self', ({ assert }) => {
@@ -962,6 +1175,41 @@ test.group('isAssociated()', (group) => {
962
1175
  const result = e1.isAssociated(e3.key)
963
1176
  assert.isFalse(result)
964
1177
  })
1178
+
1179
+ test('returns true when has multiple paths', ({ assert }) => {
1180
+ e1.addTargetAssociation(e2.key)
1181
+ e1.addTargetAssociation(e3.key)
1182
+ e3.addTargetAssociation(e4.key)
1183
+ e2.addTargetAssociation(e4.key)
1184
+ const result = e1.isAssociated(e4.key)
1185
+ assert.isTrue(result)
1186
+ })
1187
+
1188
+ test('returns false when has no path', ({ assert }) => {
1189
+ e1.addTargetAssociation(e2.key)
1190
+ const result = e1.isAssociated(e3.key)
1191
+ assert.isFalse(result)
1192
+ })
1193
+
1194
+ test('returns false when no association', ({ assert }) => {
1195
+ const result = DataEntity.isAssociated(e1, e2)
1196
+ assert.isFalse(result)
1197
+ })
1198
+
1199
+ test('returns true when foreign association', ({ assert }) => {
1200
+ e1.addForeignAssociation(foreignEntity.key, foreignRoot.key)
1201
+ const result = DataEntity.isAssociated(e1, foreignEntity)
1202
+ assert.isTrue(result)
1203
+ })
1204
+
1205
+ test('returns true when has multiple paths', ({ assert }) => {
1206
+ e1.addTargetAssociation(e2.key)
1207
+ e1.addTargetAssociation(e3.key)
1208
+ e3.addTargetAssociation(e4.key)
1209
+ e2.addTargetAssociation(e4.key)
1210
+ const result = DataEntity.isAssociated(e1, e4)
1211
+ assert.isTrue(result)
1212
+ })
965
1213
  })
966
1214
 
967
1215
  test.group('getRelatedEntities()', (group) => {
@@ -983,6 +1231,7 @@ test.group('getRelatedEntities()', (group) => {
983
1231
  e1b = m1.addEntity('e1b')
984
1232
  e2a = m2.addEntity('e2a')
985
1233
  m2.addEntity('e2b')
1234
+ m2.addEntity('e2b')
986
1235
  })
987
1236
 
988
1237
  test('reads entities from the same namespace', ({ assert }) => {
@@ -1006,6 +1255,13 @@ test.group('getRelatedEntities()', (group) => {
1006
1255
  const result = e1a.getRelatedEntities()
1007
1256
  assert.deepEqual(result, [e1b, e2a])
1008
1257
  })
1258
+
1259
+ test('returns multiple related entities', ({ assert }) => {
1260
+ e1b.addTargetAssociation(e1a)
1261
+ e2a.addTargetAssociation(e1a)
1262
+ const result = e1a.getRelatedEntities()
1263
+ assert.deepEqual(result.sort(), [e1b, e2a].sort())
1264
+ })
1009
1265
  })
1010
1266
 
1011
1267
  test.group('breadcrumbs()', (group) => {
@@ -1014,6 +1270,14 @@ test.group('breadcrumbs()', (group) => {
1014
1270
  root = new DataNamespace()
1015
1271
  })
1016
1272
 
1273
+ test('adds root and self', ({ assert }) => {
1274
+ const e1 = new DataEntity(root)
1275
+ const result = e1.breadcrumbs()
1276
+ assert.lengthOf(result, 2, 'has the entire path')
1277
+ assert.equal(result[0].key, root.key, 'has the root as first')
1278
+ assert.equal(result[1].key, e1.key, 'has the entity as last')
1279
+ })
1280
+
1017
1281
  test('adds root, data model, and self', ({ assert }) => {
1018
1282
  const m1 = root.addDataModel('m1')
1019
1283
  const e1 = m1.addEntity('e1')
@@ -1128,6 +1392,39 @@ test.group('removeTag()', (group) => {
1128
1392
  })
1129
1393
  })
1130
1394
 
1395
+ test.group('addTag() and removeTag() - More Scenarios', (group) => {
1396
+ let root: DataNamespace
1397
+ let m1: DataModel
1398
+ let e1: DataEntity
1399
+
1400
+ group.each.setup(() => {
1401
+ root = new DataNamespace()
1402
+ m1 = root.addDataModel('m1')
1403
+ e1 = m1.addEntity('e1')
1404
+ })
1405
+
1406
+ test('adds multiple tags to the property', ({ assert }) => {
1407
+ e1.addTag('Test1')
1408
+ e1.addTag('Test2')
1409
+ assert.deepEqual(e1.tags, ['Test1', 'Test2'])
1410
+ })
1411
+
1412
+ test('removes multiple tags from the property', ({ assert }) => {
1413
+ e1.addTag('t1')
1414
+ e1.addTag('t2')
1415
+ e1.addTag('t3')
1416
+ e1.removeTag('t1')
1417
+ e1.removeTag('t3')
1418
+ assert.deepEqual(e1.tags, ['t2'])
1419
+ })
1420
+
1421
+ test('removes a tag case insensitive', ({ assert }) => {
1422
+ e1.addTag('Test')
1423
+ e1.removeTag('teSt')
1424
+ assert.deepEqual(e1.tags, [])
1425
+ })
1426
+ })
1427
+
1131
1428
  test.group('toApiShape()', (group) => {
1132
1429
  let root: DataNamespace
1133
1430
  let m1: DataModel
@@ -1302,6 +1599,43 @@ test.group('addParent()', (group) => {
1302
1599
  assert.doesNotThrow(() => entity2.addParent(entity3.key))
1303
1600
  assert.deepEqual(entity2.parents, [entity3.key])
1304
1601
  })
1602
+
1603
+ test('throws an error when adding the same parent twice', ({ assert }) => {
1604
+ entity2.addParent(entity1.key)
1605
+ assert.throws(
1606
+ () => entity2.addParent(entity1.key),
1607
+ ValidationError as unknown as ErrorConstructor,
1608
+ `Parent ${entity1.key} already exists.`
1609
+ )
1610
+ })
1611
+
1612
+ test('adds multiple parents', ({ assert }) => {
1613
+ entity3.addParent(entity1.key)
1614
+ entity3.addParent(entity2.key)
1615
+ assert.deepEqual(entity3.parents.sort(), [entity1.key, entity2.key].sort())
1616
+ })
1617
+ })
1618
+
1619
+ test.group('DataEntity - getParent()', (group) => {
1620
+ let root: DataNamespace
1621
+ let model: DataModel
1622
+ let entity1: DataEntity
1623
+
1624
+ group.each.setup(() => {
1625
+ root = new DataNamespace()
1626
+ model = root.addDataModel('model')
1627
+ entity1 = model.addEntity('entity1')
1628
+ })
1629
+
1630
+ test('returns undefined when the entity is not in a model', ({ assert }) => {
1631
+ const result = new DataEntity(root).getParent()
1632
+ assert.isUndefined(result)
1633
+ })
1634
+
1635
+ test('returns the parent data model', ({ assert }) => {
1636
+ const result = entity1.getParent()
1637
+ assert.instanceOf(result, DataModel)
1638
+ })
1305
1639
  })
1306
1640
 
1307
1641
  test.group('hasCircularParent()', (group) => {
@@ -1354,6 +1688,13 @@ test.group('hasCircularParent()', (group) => {
1354
1688
  assert.isTrue(entity2.hasCircularParent(entity1.key))
1355
1689
  assert.isTrue(entity3.hasCircularParent(entity1.key))
1356
1690
  })
1691
+
1692
+ test('returns true when indirect circular dependency - multiple parents', ({ assert }) => {
1693
+ entity1.addParent(entity2.key)
1694
+ entity1.addParent(entity3.key)
1695
+ entity2.addParent(entity4.key)
1696
+ assert.isTrue(entity4.hasCircularParent(entity1.key))
1697
+ })
1357
1698
  })
1358
1699
 
1359
1700
  test.group('associationPath()', (group) => {
@@ -1466,3 +1807,143 @@ test.group('getRelatedEntities()', (group) => {
1466
1807
  assert.deepEqual(result, [entityA, entityD])
1467
1808
  })
1468
1809
  })
1810
+
1811
+ test.group('listProperties()', (group) => {
1812
+ let root: DataNamespace
1813
+ let m1: DataModel
1814
+ let e1: DataEntity
1815
+ let p1: DataProperty
1816
+ let p2: DataProperty
1817
+
1818
+ group.each.setup(() => {
1819
+ root = new DataNamespace()
1820
+ m1 = root.addDataModel('m1')
1821
+ e1 = m1.addEntity('e1')
1822
+ p1 = e1.addNamedProperty('p1')
1823
+ p2 = e1.addNamedProperty('p2')
1824
+ })
1825
+
1826
+ test('lists all properties', ({ assert }) => {
1827
+ const result = e1.listProperties()
1828
+ assert.deepEqual(result, [p1, p2])
1829
+ })
1830
+
1831
+ test('returns a copy of the array', ({ assert }) => {
1832
+ const result = e1.listProperties()
1833
+ result.pop()
1834
+ assert.lengthOf(e1.properties, 2)
1835
+ })
1836
+ })
1837
+
1838
+ test.group('listAssociations()', (group) => {
1839
+ let root: DataNamespace
1840
+ let m1: DataModel
1841
+ let e1: DataEntity
1842
+ let a1: DataAssociation
1843
+ let a2: DataAssociation
1844
+
1845
+ group.each.setup(() => {
1846
+ root = new DataNamespace()
1847
+ m1 = root.addDataModel('m1')
1848
+ e1 = m1.addEntity('e1')
1849
+ a1 = e1.addNamedAssociation('a1')
1850
+ a2 = e1.addNamedAssociation('a2')
1851
+ })
1852
+
1853
+ test('lists all associations', ({ assert }) => {
1854
+ const result = e1.listAssociations()
1855
+ assert.deepEqual(result, [a1, a2])
1856
+ })
1857
+
1858
+ test('returns a copy of the array', ({ assert }) => {
1859
+ const result = e1.listAssociations()
1860
+ result.pop()
1861
+ assert.lengthOf(e1.associations, 2)
1862
+ })
1863
+ })
1864
+
1865
+ test.group('listFields()', (group) => {
1866
+ let root: DataNamespace
1867
+ let m1: DataModel
1868
+ let e1: DataEntity
1869
+ let p1: DataProperty
1870
+ let p2: DataProperty
1871
+ let a1: DataAssociation
1872
+ let a2: DataAssociation
1873
+
1874
+ group.each.setup(() => {
1875
+ root = new DataNamespace()
1876
+ m1 = root.addDataModel('m1')
1877
+ e1 = m1.addEntity('e1')
1878
+ p1 = e1.addNamedProperty('p1')
1879
+ p2 = e1.addNamedProperty('p2')
1880
+ a1 = e1.addNamedAssociation('a1')
1881
+ a2 = e1.addNamedAssociation('a2')
1882
+ })
1883
+
1884
+ test('lists all fields in order', ({ assert }) => {
1885
+ const result = e1.listFields()
1886
+ assert.deepEqual(result, [p1, p2, a1, a2])
1887
+ })
1888
+
1889
+ test('returns a copy of the array', ({ assert }) => {
1890
+ const result = e1.listFields()
1891
+ result.pop()
1892
+ assert.lengthOf(e1.fields, 4)
1893
+ })
1894
+
1895
+ test('returns fields in the order of the fields array', ({ assert }) => {
1896
+ e1.moveField(p1.key, 3)
1897
+ const result = e1.listFields()
1898
+ assert.deepEqual(result, [p2, a1, a2, p1])
1899
+ })
1900
+ })
1901
+
1902
+ test.group('moveField()', (group) => {
1903
+ let root: DataNamespace
1904
+ let m1: DataModel
1905
+ let e1: DataEntity
1906
+ let p1: DataProperty
1907
+ let p2: DataProperty
1908
+ let a1: DataAssociation
1909
+ let a2: DataAssociation
1910
+
1911
+ group.each.setup(() => {
1912
+ root = new DataNamespace()
1913
+ m1 = root.addDataModel('m1')
1914
+ e1 = m1.addEntity('e1')
1915
+ p1 = e1.addNamedProperty('p1')
1916
+ p2 = e1.addNamedProperty('p2')
1917
+ a1 = e1.addNamedAssociation('a1')
1918
+ a2 = e1.addNamedAssociation('a2')
1919
+ })
1920
+
1921
+ test('moves the field to a new index', ({ assert }) => {
1922
+ e1.moveField(p1.key, 3)
1923
+ assert.deepEqual(
1924
+ e1.fields.map((i) => i.key),
1925
+ [p2.key, a1.key, a2.key, p1.key]
1926
+ )
1927
+ })
1928
+
1929
+ test('Moving a field to the same index', ({ assert }) => {
1930
+ e1.moveField(p1.key, 0)
1931
+ assert.deepEqual(
1932
+ e1.fields.map((i) => i.key),
1933
+ [p1.key, p2.key, a1.key, a2.key]
1934
+ )
1935
+ })
1936
+
1937
+ test('throws when the field does not exist', ({ assert }) => {
1938
+ assert.throws(
1939
+ () => e1.moveField('unknown', 0),
1940
+ ValidationError as unknown as ErrorConstructor,
1941
+ 'Validation failure'
1942
+ )
1943
+ })
1944
+
1945
+ test('throws when the index is out of bounds', ({ assert }) => {
1946
+ assert.throws(() => e1.moveField(p1.key, -1), ValidationError as unknown as ErrorConstructor, 'Validation failure')
1947
+ assert.throws(() => e1.moveField(p1.key, 4), ValidationError as unknown as ErrorConstructor, 'Validation failure')
1948
+ })
1949
+ })