pure-orm 4.0.0 → 4.0.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.
Files changed (217) hide show
  1. package/README.md +97 -43
  2. package/coverage/clover.xml +969 -626
  3. package/coverage/coverage-final.json +34 -22
  4. package/coverage/lcov-report/dist/src/core.js.html +220 -190
  5. package/coverage/lcov-report/dist/src/driver-integrations/index.html +97 -0
  6. package/coverage/lcov-report/dist/src/driver-integrations/pgp.js.html +240 -0
  7. package/coverage/lcov-report/dist/src/index.html +44 -18
  8. package/coverage/lcov-report/dist/src/index.js.html +2 -2
  9. package/coverage/lcov-report/dist/src/orm.js.html +125 -119
  10. package/coverage/lcov-report/dist/test-utils/blog/entities.js.html +1 -1
  11. package/coverage/lcov-report/dist/test-utils/blog/index.html +1 -1
  12. package/coverage/lcov-report/dist/test-utils/blog/models/article.js.html +15 -15
  13. package/coverage/lcov-report/dist/test-utils/blog/models/article_tag.js.html +7 -7
  14. package/coverage/lcov-report/dist/test-utils/blog/models/index.html +1 -1
  15. package/coverage/lcov-report/dist/test-utils/blog/models/person.js.html +13 -13
  16. package/coverage/lcov-report/dist/test-utils/blog/models/tag.js.html +4 -4
  17. package/coverage/lcov-report/dist/test-utils/five/entities.js.html +1 -1
  18. package/coverage/lcov-report/dist/test-utils/five/index.html +1 -1
  19. package/coverage/lcov-report/dist/test-utils/five/models/index.html +1 -1
  20. package/coverage/lcov-report/dist/test-utils/five/models/line-item.js.html +1 -1
  21. package/coverage/lcov-report/dist/test-utils/five/models/order.js.html +1 -1
  22. package/coverage/lcov-report/dist/test-utils/five/models/parcel-event.js.html +1 -1
  23. package/coverage/lcov-report/dist/test-utils/five/models/parcel-line-item.js.html +1 -1
  24. package/coverage/lcov-report/dist/test-utils/five/models/parcel.js.html +1 -1
  25. package/coverage/lcov-report/dist/test-utils/fourteen/entities.js.html +87 -0
  26. package/coverage/lcov-report/dist/test-utils/fourteen/index.html +97 -0
  27. package/coverage/lcov-report/dist/test-utils/fourteen/models/customer.js.html +159 -0
  28. package/coverage/lcov-report/dist/test-utils/fourteen/models/index.html +110 -0
  29. package/coverage/lcov-report/dist/test-utils/fourteen/models/person.js.html +138 -0
  30. package/coverage/lcov-report/dist/test-utils/nine/entities.js.html +1 -1
  31. package/coverage/lcov-report/dist/test-utils/nine/index.html +1 -1
  32. package/coverage/lcov-report/dist/test-utils/nine/models/feature-switch.js.html +1 -1
  33. package/coverage/lcov-report/dist/test-utils/nine/models/index.html +1 -1
  34. package/coverage/lcov-report/dist/test-utils/order/entities.js.html +11 -11
  35. package/coverage/lcov-report/dist/test-utils/order/index.html +1 -1
  36. package/coverage/lcov-report/dist/test-utils/order/models/index.html +1 -1
  37. package/coverage/lcov-report/dist/test-utils/order/models/line-item.js.html +24 -24
  38. package/coverage/lcov-report/dist/test-utils/order/models/order.js.html +42 -42
  39. package/coverage/lcov-report/dist/test-utils/order/models/product-variant.js.html +23 -23
  40. package/coverage/lcov-report/dist/test-utils/order/models/product.js.html +17 -17
  41. package/coverage/lcov-report/dist/test-utils/order/models/utm-source.js.html +12 -12
  42. package/coverage/lcov-report/dist/test-utils/order-more/entities.js.html +1 -1
  43. package/coverage/lcov-report/dist/test-utils/order-more/index.html +1 -1
  44. package/coverage/lcov-report/dist/test-utils/order-more/models/actual-product-variant.js.html +1 -1
  45. package/coverage/lcov-report/dist/test-utils/order-more/models/color.js.html +1 -1
  46. package/coverage/lcov-report/dist/test-utils/order-more/models/customer.js.html +1 -1
  47. package/coverage/lcov-report/dist/test-utils/order-more/models/gender.js.html +1 -1
  48. package/coverage/lcov-report/dist/test-utils/order-more/models/index.html +1 -1
  49. package/coverage/lcov-report/dist/test-utils/order-more/models/inventory-level.js.html +1 -1
  50. package/coverage/lcov-report/dist/test-utils/order-more/models/line-item.js.html +1 -1
  51. package/coverage/lcov-report/dist/test-utils/order-more/models/order.js.html +1 -1
  52. package/coverage/lcov-report/dist/test-utils/order-more/models/parcel-event.js.html +1 -1
  53. package/coverage/lcov-report/dist/test-utils/order-more/models/parcel-line-item.js.html +1 -1
  54. package/coverage/lcov-report/dist/test-utils/order-more/models/parcel.js.html +1 -1
  55. package/coverage/lcov-report/dist/test-utils/order-more/models/physical-address.js.html +1 -1
  56. package/coverage/lcov-report/dist/test-utils/order-more/models/product-variant-image.js.html +1 -1
  57. package/coverage/lcov-report/dist/test-utils/order-more/models/product-variant.js.html +1 -1
  58. package/coverage/lcov-report/dist/test-utils/order-more/models/product.js.html +1 -1
  59. package/coverage/lcov-report/dist/test-utils/order-more/models/refund.js.html +1 -1
  60. package/coverage/lcov-report/dist/test-utils/order-more/models/shipment-actual-product-variant.js.html +1 -1
  61. package/coverage/lcov-report/dist/test-utils/order-more/models/shipment.js.html +1 -1
  62. package/coverage/lcov-report/dist/test-utils/order-more/models/size.js.html +1 -1
  63. package/coverage/lcov-report/dist/test-utils/order-more/models/utm-medium.js.html +1 -1
  64. package/coverage/lcov-report/dist/test-utils/order-more/models/utm-source.js.html +1 -1
  65. package/coverage/lcov-report/dist/test-utils/six/entities.js.html +1 -1
  66. package/coverage/lcov-report/dist/test-utils/six/index.html +1 -1
  67. package/coverage/lcov-report/dist/test-utils/six/models/customer.js.html +1 -1
  68. package/coverage/lcov-report/dist/test-utils/six/models/index.html +1 -1
  69. package/coverage/lcov-report/dist/test-utils/six/models/line-item.js.html +1 -1
  70. package/coverage/lcov-report/dist/test-utils/six/models/order.js.html +1 -1
  71. package/coverage/lcov-report/dist/test-utils/six/models/parcel-line-item.js.html +1 -1
  72. package/coverage/lcov-report/dist/test-utils/six/models/parcel.js.html +1 -1
  73. package/coverage/lcov-report/dist/test-utils/thirteen/entities.js.html +1 -1
  74. package/coverage/lcov-report/dist/test-utils/thirteen/index.html +1 -1
  75. package/coverage/lcov-report/dist/test-utils/thirteen/models/audience.js.html +1 -1
  76. package/coverage/lcov-report/dist/test-utils/thirteen/models/brand.js.html +1 -1
  77. package/coverage/lcov-report/dist/test-utils/thirteen/models/category.js.html +1 -1
  78. package/coverage/lcov-report/dist/test-utils/thirteen/models/index.html +1 -1
  79. package/coverage/lcov-report/dist/test-utils/thirteen/models/member.js.html +1 -1
  80. package/coverage/lcov-report/dist/test-utils/thirteen/models/passion.js.html +1 -1
  81. package/coverage/lcov-report/dist/test-utils/thirteen/models/product.js.html +1 -1
  82. package/coverage/lcov-report/dist/test-utils/thirteen/models/recommendation-audience.js.html +1 -1
  83. package/coverage/lcov-report/dist/test-utils/thirteen/models/recommendation.js.html +1 -1
  84. package/coverage/lcov-report/dist/test-utils/three/index.html +1 -1
  85. package/coverage/lcov-report/dist/test-utils/three/results.js.html +1 -1
  86. package/coverage/lcov-report/dist/test-utils/twelve/entities.js.html +1 -1
  87. package/coverage/lcov-report/dist/test-utils/twelve/index.html +1 -1
  88. package/coverage/lcov-report/dist/test-utils/twelve/models/index.html +1 -1
  89. package/coverage/lcov-report/dist/test-utils/twelve/models/member.js.html +1 -1
  90. package/coverage/lcov-report/dist/test-utils/twelve/models/prompt.js.html +1 -1
  91. package/coverage/lcov-report/dist/test-utils/two/index.html +1 -1
  92. package/coverage/lcov-report/dist/test-utils/two/results.js.html +1 -1
  93. package/coverage/lcov-report/index.html +105 -27
  94. package/coverage/lcov-report/src/core.ts.html +235 -196
  95. package/coverage/lcov-report/src/driver-integrations/index.html +97 -0
  96. package/coverage/lcov-report/src/driver-integrations/pgp.ts.html +345 -0
  97. package/coverage/lcov-report/src/index.html +44 -18
  98. package/coverage/lcov-report/src/index.ts.html +3 -15
  99. package/coverage/lcov-report/src/orm.ts.html +256 -130
  100. package/coverage/lcov-report/test-utils/blog/entities.ts.html +1 -1
  101. package/coverage/lcov-report/test-utils/blog/index.html +1 -1
  102. package/coverage/lcov-report/test-utils/blog/models/article.ts.html +15 -15
  103. package/coverage/lcov-report/test-utils/blog/models/article_tag.ts.html +7 -7
  104. package/coverage/lcov-report/test-utils/blog/models/index.html +1 -1
  105. package/coverage/lcov-report/test-utils/blog/models/person.ts.html +13 -13
  106. package/coverage/lcov-report/test-utils/blog/models/tag.ts.html +4 -4
  107. package/coverage/lcov-report/test-utils/five/entities.ts.html +1 -1
  108. package/coverage/lcov-report/test-utils/five/index.html +1 -1
  109. package/coverage/lcov-report/test-utils/five/models/index.html +1 -1
  110. package/coverage/lcov-report/test-utils/five/models/line-item.ts.html +1 -1
  111. package/coverage/lcov-report/test-utils/five/models/order.ts.html +1 -1
  112. package/coverage/lcov-report/test-utils/five/models/parcel-event.ts.html +1 -1
  113. package/coverage/lcov-report/test-utils/five/models/parcel-line-item.ts.html +1 -1
  114. package/coverage/lcov-report/test-utils/five/models/parcel.ts.html +1 -1
  115. package/coverage/lcov-report/test-utils/fourteen/entities.ts.html +78 -0
  116. package/coverage/lcov-report/test-utils/fourteen/index.html +97 -0
  117. package/coverage/lcov-report/test-utils/fourteen/models/customer.ts.html +177 -0
  118. package/coverage/lcov-report/test-utils/fourteen/models/index.html +110 -0
  119. package/coverage/lcov-report/test-utils/fourteen/models/person.ts.html +150 -0
  120. package/coverage/lcov-report/test-utils/nine/entities.ts.html +1 -1
  121. package/coverage/lcov-report/test-utils/nine/index.html +1 -1
  122. package/coverage/lcov-report/test-utils/nine/models/feature-switch.ts.html +1 -1
  123. package/coverage/lcov-report/test-utils/nine/models/index.html +1 -1
  124. package/coverage/lcov-report/test-utils/order/entities.ts.html +5 -5
  125. package/coverage/lcov-report/test-utils/order/index.html +1 -1
  126. package/coverage/lcov-report/test-utils/order/models/index.html +1 -1
  127. package/coverage/lcov-report/test-utils/order/models/line-item.ts.html +18 -18
  128. package/coverage/lcov-report/test-utils/order/models/order.ts.html +37 -37
  129. package/coverage/lcov-report/test-utils/order/models/product-variant.ts.html +18 -18
  130. package/coverage/lcov-report/test-utils/order/models/product.ts.html +13 -13
  131. package/coverage/lcov-report/test-utils/order/models/utm-source.ts.html +8 -8
  132. package/coverage/lcov-report/test-utils/order-more/entities.ts.html +1 -1
  133. package/coverage/lcov-report/test-utils/order-more/index.html +1 -1
  134. package/coverage/lcov-report/test-utils/order-more/models/actual-product-variant.ts.html +1 -1
  135. package/coverage/lcov-report/test-utils/order-more/models/color.ts.html +1 -1
  136. package/coverage/lcov-report/test-utils/order-more/models/customer.ts.html +1 -1
  137. package/coverage/lcov-report/test-utils/order-more/models/gender.ts.html +1 -1
  138. package/coverage/lcov-report/test-utils/order-more/models/index.html +1 -1
  139. package/coverage/lcov-report/test-utils/order-more/models/inventory-level.ts.html +1 -1
  140. package/coverage/lcov-report/test-utils/order-more/models/line-item.ts.html +1 -1
  141. package/coverage/lcov-report/test-utils/order-more/models/order.ts.html +1 -1
  142. package/coverage/lcov-report/test-utils/order-more/models/parcel-event.ts.html +1 -1
  143. package/coverage/lcov-report/test-utils/order-more/models/parcel-line-item.ts.html +1 -1
  144. package/coverage/lcov-report/test-utils/order-more/models/parcel.ts.html +1 -1
  145. package/coverage/lcov-report/test-utils/order-more/models/physical-address.ts.html +1 -1
  146. package/coverage/lcov-report/test-utils/order-more/models/product-variant-image.ts.html +1 -1
  147. package/coverage/lcov-report/test-utils/order-more/models/product-variant.ts.html +1 -1
  148. package/coverage/lcov-report/test-utils/order-more/models/product.ts.html +1 -1
  149. package/coverage/lcov-report/test-utils/order-more/models/refund.ts.html +1 -1
  150. package/coverage/lcov-report/test-utils/order-more/models/shipment-actual-product-variant.ts.html +1 -1
  151. package/coverage/lcov-report/test-utils/order-more/models/shipment.ts.html +1 -1
  152. package/coverage/lcov-report/test-utils/order-more/models/size.ts.html +1 -1
  153. package/coverage/lcov-report/test-utils/order-more/models/utm-medium.ts.html +1 -1
  154. package/coverage/lcov-report/test-utils/order-more/models/utm-source.ts.html +1 -1
  155. package/coverage/lcov-report/test-utils/six/entities.ts.html +1 -1
  156. package/coverage/lcov-report/test-utils/six/index.html +1 -1
  157. package/coverage/lcov-report/test-utils/six/models/customer.ts.html +1 -1
  158. package/coverage/lcov-report/test-utils/six/models/index.html +1 -1
  159. package/coverage/lcov-report/test-utils/six/models/line-item.ts.html +1 -1
  160. package/coverage/lcov-report/test-utils/six/models/order.ts.html +1 -1
  161. package/coverage/lcov-report/test-utils/six/models/parcel-line-item.ts.html +1 -1
  162. package/coverage/lcov-report/test-utils/six/models/parcel.ts.html +1 -1
  163. package/coverage/lcov-report/test-utils/thirteen/entities.ts.html +1 -1
  164. package/coverage/lcov-report/test-utils/thirteen/index.html +1 -1
  165. package/coverage/lcov-report/test-utils/thirteen/models/audience.ts.html +1 -1
  166. package/coverage/lcov-report/test-utils/thirteen/models/brand.ts.html +1 -1
  167. package/coverage/lcov-report/test-utils/thirteen/models/category.ts.html +1 -1
  168. package/coverage/lcov-report/test-utils/thirteen/models/index.html +1 -1
  169. package/coverage/lcov-report/test-utils/thirteen/models/member.ts.html +1 -1
  170. package/coverage/lcov-report/test-utils/thirteen/models/passion.ts.html +1 -1
  171. package/coverage/lcov-report/test-utils/thirteen/models/product.ts.html +1 -1
  172. package/coverage/lcov-report/test-utils/thirteen/models/recommendation-audience.ts.html +1 -1
  173. package/coverage/lcov-report/test-utils/thirteen/models/recommendation.ts.html +1 -1
  174. package/coverage/lcov-report/test-utils/three/index.html +1 -1
  175. package/coverage/lcov-report/test-utils/three/results.js.html +1 -1
  176. package/coverage/lcov-report/test-utils/twelve/entities.ts.html +1 -1
  177. package/coverage/lcov-report/test-utils/twelve/index.html +1 -1
  178. package/coverage/lcov-report/test-utils/twelve/models/index.html +1 -1
  179. package/coverage/lcov-report/test-utils/twelve/models/member.ts.html +1 -1
  180. package/coverage/lcov-report/test-utils/twelve/models/prompt.ts.html +1 -1
  181. package/coverage/lcov-report/test-utils/two/index.html +1 -1
  182. package/coverage/lcov-report/test-utils/two/results.js.html +1 -1
  183. package/coverage/lcov.info +1686 -1005
  184. package/dist/src/core.d.ts +1 -1
  185. package/dist/src/core.js +18 -8
  186. package/dist/src/core.spec.js +643 -540
  187. package/dist/src/driver-integrations/index.d.ts +1 -0
  188. package/dist/src/orm.d.ts +21 -0
  189. package/dist/src/orm.js +6 -2
  190. package/dist/src/orm.spec.d.ts +1 -0
  191. package/dist/src/orm.spec.js +102 -0
  192. package/dist/test-utils/fourteen/entities.d.ts +6 -0
  193. package/dist/test-utils/fourteen/entities.js +6 -0
  194. package/dist/test-utils/fourteen/entities.ts +3 -0
  195. package/dist/test-utils/fourteen/models/customer.d.ts +19 -0
  196. package/dist/test-utils/fourteen/models/customer.js +30 -0
  197. package/dist/test-utils/fourteen/models/customer.ts +36 -0
  198. package/dist/test-utils/fourteen/models/person.d.ts +17 -0
  199. package/dist/test-utils/fourteen/models/person.js +23 -0
  200. package/dist/test-utils/fourteen/models/person.ts +27 -0
  201. package/dist/test-utils/fourteen/results.json +8 -0
  202. package/dist/test-utils/order/entities.js +2 -2
  203. package/dist/test-utils/order/entities.ts +2 -2
  204. package/dist/test-utils/order/models/order.js +1 -1
  205. package/dist/test-utils/order/models/order.ts +1 -1
  206. package/package.json +1 -1
  207. package/src/core.spec.ts +1112 -986
  208. package/src/core.ts +27 -14
  209. package/src/driver-integrations/index.ts +2 -0
  210. package/src/orm.spec.ts +113 -0
  211. package/src/orm.ts +54 -8
  212. package/test-utils/fourteen/entities.ts +3 -0
  213. package/test-utils/fourteen/models/customer.ts +36 -0
  214. package/test-utils/fourteen/models/person.ts +27 -0
  215. package/test-utils/fourteen/results.json +8 -0
  216. package/test-utils/order/entities.ts +2 -2
  217. package/test-utils/order/models/order.ts +1 -1
@@ -10,6 +10,7 @@ const entities_5 = require("../test-utils/five/entities");
10
10
  const entities_6 = require("../test-utils/six/entities");
11
11
  const entities_7 = require("../test-utils/twelve/entities");
12
12
  const entities_8 = require("../test-utils/thirteen/entities");
13
+ const entities_9 = require("../test-utils/fourteen/entities");
13
14
  const article_1 = require("../test-utils/blog/models/article");
14
15
  const two = require('../test-utils/two/results');
15
16
  const three = require('../test-utils/three/results');
@@ -24,551 +25,653 @@ const ten = require('../test-utils/ten/results.json');
24
25
  const eleven = require('../test-utils/eleven/results.json');
25
26
  const twelve = require('../test-utils/twelve/results.json');
26
27
  const thirteen = require('../test-utils/thirteen/results.json');
27
- test('createOneFromDatabase where multiple rows reduce to one nested object (with all one-to-one or one-to-many tables)', () => {
28
- const core = (0, core_1.createCore)({ entities: entities_1.entities });
29
- const order = core.createOneFromDatabase(one);
30
- expect(Array.isArray(order)).toBe(false);
31
- expect(order === null || order === void 0 ? void 0 : order.id).toEqual(3866);
32
- expect(order === null || order === void 0 ? void 0 : order.utmSource.id).toEqual(6);
33
- expect(order === null || order === void 0 ? void 0 : order.lineItems.models.length).toEqual(6);
34
- expect(order.lineItems.models[0].id).toEqual(2271);
35
- expect(order.lineItems.models[0].productVariant.id).toEqual(163);
36
- expect(order.lineItems.models[0].productVariant.product.id).toEqual(1);
37
- expect(order.lineItems.models[1].id).toEqual(2272);
38
- expect(order.lineItems.models[1].productVariant.id).toEqual(186);
39
- expect(order.lineItems.models[1].productVariant.product.id).toEqual(1);
40
- expect(order.lineItems.models[2].id).toEqual(2273);
41
- expect(order.lineItems.models[2].productVariant.id).toEqual(213);
42
- expect(order.lineItems.models[2].productVariant.product.id).toEqual(1);
43
- expect(order.lineItems.models[3].id).toEqual(2274);
44
- expect(order.lineItems.models[3].productVariant.id).toEqual(207);
45
- expect(order.lineItems.models[3].productVariant.product.id).toEqual(1);
46
- expect(order.lineItems.models[4].id).toEqual(2275);
47
- expect(order.lineItems.models[4].productVariant.id).toEqual(296);
48
- expect(order.lineItems.models[4].productVariant.product.id).toEqual(5);
49
- expect(order.lineItems.models[5].id).toEqual(2276);
50
- expect(order.lineItems.models[5].productVariant.id).toEqual(308);
51
- expect(order.lineItems.models[5].productVariant.product.id).toEqual(3);
52
- });
53
- test('createOneFromDatabase where multiple rows reduce to one nested object (with many-to-many tables)', () => {
54
- const core = (0, core_1.createCore)({ entities: entities_2.entities });
55
- const article = core.createOneFromDatabase(two);
56
- expect(Array.isArray(article)).toBe(false);
57
- expect(article.id).toEqual(14);
58
- expect(article.person.id).toEqual(8);
59
- expect(article.articleTags.models.length).toEqual(10);
60
- expect(article.articleTags.models[0].id).toEqual(36);
61
- expect(article.articleTags.models[0].tag.id).toEqual(3);
62
- expect(article.articleTags.models[1].id).toEqual(37);
63
- expect(article.articleTags.models[1].tag.id).toEqual(4);
64
- expect(article.articleTags.models[2].id).toEqual(38);
65
- expect(article.articleTags.models[2].tag.id).toEqual(5);
66
- expect(article.articleTags.models[3].id).toEqual(39);
67
- expect(article.articleTags.models[3].tag.id).toEqual(6);
68
- expect(article.articleTags.models[4].id).toEqual(40);
69
- expect(article.articleTags.models[4].tag.id).toEqual(7);
70
- expect(article.articleTags.models[5].id).toEqual(41);
71
- expect(article.articleTags.models[5].tag.id).toEqual(8);
72
- expect(article.articleTags.models[6].id).toEqual(42);
73
- expect(article.articleTags.models[6].tag.id).toEqual(9);
74
- expect(article.articleTags.models[7].id).toEqual(43);
75
- expect(article.articleTags.models[7].tag.id).toEqual(11);
76
- expect(article.articleTags.models[8].id).toEqual(44);
77
- expect(article.articleTags.models[8].tag.id).toEqual(12);
78
- expect(article.articleTags.models[9].id).toEqual(45);
79
- expect(article.articleTags.models[9].tag.id).toEqual(16);
80
- });
81
- test('createFromDatabase where multiple rows reduce to many rows with nested objects (with many-to-many tables)', () => {
82
- const core = (0, core_1.createCore)({ entities: entities_2.entities });
83
- const articles = core.createFromDatabase(three);
84
- expect(Array.isArray(articles.models)).toBe(true);
85
- expect(articles instanceof article_1.Articles).toBe(true);
86
- expect(articles.models.length).toEqual(2);
87
- const first = articles.models[0];
88
- expect(first.person.id).toEqual(8);
89
- expect(first.articleTags.models.length).toEqual(10);
90
- expect(first.articleTags.models[0].id).toEqual(36);
91
- expect(first.articleTags.models[0].tag.id).toEqual(3);
92
- expect(first.articleTags.models[1].id).toEqual(37);
93
- expect(first.articleTags.models[1].tag.id).toEqual(4);
94
- expect(first.articleTags.models[2].id).toEqual(38);
95
- expect(first.articleTags.models[2].tag.id).toEqual(5);
96
- expect(first.articleTags.models[3].id).toEqual(39);
97
- expect(first.articleTags.models[3].tag.id).toEqual(6);
98
- expect(first.articleTags.models[4].id).toEqual(40);
99
- expect(first.articleTags.models[4].tag.id).toEqual(7);
100
- expect(first.articleTags.models[5].id).toEqual(41);
101
- expect(first.articleTags.models[5].tag.id).toEqual(8);
102
- expect(first.articleTags.models[6].id).toEqual(42);
103
- expect(first.articleTags.models[6].tag.id).toEqual(9);
104
- expect(first.articleTags.models[7].id).toEqual(43);
105
- expect(first.articleTags.models[7].tag.id).toEqual(11);
106
- expect(first.articleTags.models[8].id).toEqual(44);
107
- expect(first.articleTags.models[8].tag.id).toEqual(12);
108
- expect(first.articleTags.models[9].id).toEqual(45);
109
- expect(first.articleTags.models[9].tag.id).toEqual(16);
110
- const second = articles.models[1];
111
- expect(second.id).toEqual(12);
112
- expect(second.person.id).toEqual(17);
113
- expect(second.articleTags.models.length).toEqual(3);
114
- expect(second.articleTags.models[0].id).toEqual(33);
115
- expect(second.articleTags.models[0].tag.id).toEqual(1);
116
- expect(second.articleTags.models[1].id).toEqual(34);
117
- expect(second.articleTags.models[1].tag.id).toEqual(5);
118
- expect(second.articleTags.models[2].id).toEqual(35);
119
- expect(second.articleTags.models[2].tag.id).toEqual(15);
120
- });
121
- // Tests for where a deeply nested node which points to a node, is itself
122
- // reused (not recreated each time) so that nodes pointing to it all stack
123
- // together on it, rather than each attaching to different replica nodes
124
- // which overwrite themselves on the node it points to.
125
- // The example here is with the productVariant node being reused so that
126
- // productVariantImages append to it, instead of each productVariantImage
127
- // living on its own productVariant (which would keep overwriting itself
128
- // on the actualProductVariant node).
129
- test('createFromDatabase where node is already seen', () => {
130
- const core = (0, core_1.createCore)({ entities: entities_3.entities });
131
- const inventoryLevels = core.createFromDatabase(four);
132
- expect(inventoryLevels).toBeDefined();
133
- const first = inventoryLevels === null || inventoryLevels === void 0 ? void 0 : inventoryLevels.models[0];
134
- expect(first === null || first === void 0 ? void 0 : first.id).toEqual(15);
135
- expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.id).toEqual(120);
136
- expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models.length).toEqual(1);
137
- expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].actualProductVariantId).toEqual(120);
138
- // I think the above test is good enough, and not sure I actual care about below
139
- // expect(first.actualProductVariant.productVariants.models[0].actualProductVariant.id).toEqual(120);
140
- expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].id).toEqual(199);
141
- expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].color.id).toEqual(1);
142
- expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].gender.id).toEqual(1);
143
- expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].product.id).toEqual(1);
144
- expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].size.id).toEqual(4);
145
- expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].productVariantImages.models.length).toEqual(7);
146
- expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].productVariantImages.models[0].id).toEqual(621);
147
- expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].productVariantImages.models[1].id).toEqual(709);
148
- expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].productVariantImages.models[2].id).toEqual(797);
149
- expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].productVariantImages.models[3].id).toEqual(885);
150
- expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].productVariantImages.models[4].id).toEqual(973);
151
- expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].productVariantImages.models[5].id).toEqual(1061);
152
- expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].productVariantImages.models[6].id).toEqual(1149);
153
- const second = inventoryLevels === null || inventoryLevels === void 0 ? void 0 : inventoryLevels.models[1];
154
- expect(second === null || second === void 0 ? void 0 : second.id).toEqual(35);
155
- expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.id).toEqual(125);
156
- expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models.length).toEqual(1);
157
- expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].actualProductVariantId).toEqual(125);
158
- // I think the above test is good enough, and not sure I actual care about below
159
- // expect(second.actualProductVariant.productVariants.models[0].actualProductVariant.id).toEqual(125);
160
- expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].id).toEqual(209);
161
- expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].color.id).toEqual(1);
162
- expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].gender.id).toEqual(1);
163
- expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].product.id).toEqual(1);
164
- expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].size.id).toEqual(9);
165
- expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].productVariantImages.models.length).toEqual(7);
166
- expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].productVariantImages.models[0].id).toEqual(679);
167
- expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].productVariantImages.models[1].id).toEqual(767);
168
- expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].productVariantImages.models[2].id).toEqual(855);
169
- expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].productVariantImages.models[3].id).toEqual(943);
170
- expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].productVariantImages.models[4].id).toEqual(1031);
171
- expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].productVariantImages.models[5].id).toEqual(1119);
172
- expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].productVariantImages.models[6].id).toEqual(1207);
173
- });
174
- // Test for a nested object (eg, parcel) with objects in it that referenced to
175
- // it (eg, parcel_events), correctly placing the objects (parcel_events) in
176
- // its (parcel) collection of models, and not errantly placing the established
177
- // parent node (parcel) as a direct reference of the child (parcel_event).
178
- // For example: the errant behavior was:
179
- // Parcel1
180
- // ParcelEvent1
181
- // Parcel1
182
- // ParcelEvent2
183
- // Instead of:
184
- // Parcel1
185
- // ParcelEvent1
186
- // ParcelEvent2
187
- // NOTE: if this test ever breaks, you can widdle the five.json file to just
188
- // the two relevant line items of the one relevant order. This test should
189
- // be doing that, but since code coverage all-around isn't great and I already
190
- // had this fuller json dump from production, I just used it all - YOLO.
191
- test('createFromDatabase where a deeply nested models property was misbehaving', () => {
192
- const core = (0, core_1.createCore)({ entities: entities_5.entities });
193
- const orders = core.createFromDatabase(five);
194
- // The assertion that failed when the bug was present
195
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models.length).toEqual(2);
196
- // Lots of other assertions that are unrelated and shouldn't be here except
197
- // I'm insecure about the lack of tests so just going at it cause I can.
198
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].id).toEqual(14219);
199
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].email).toEqual('tswift@kujo.com');
200
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models.length).toEqual(2);
201
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].id).toEqual(17298);
202
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].orderId).toEqual(14219);
203
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].id).toEqual(17297);
204
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].orderId).toEqual(14219);
205
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models.length).toEqual(1);
206
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].id).toEqual(1);
207
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].parcelId).toEqual(1);
208
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].lineItemId).toEqual(17297);
209
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].parcel.id).toEqual(1);
210
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models.length).toEqual(2);
211
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models[0].id).toEqual(3);
212
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models[0].parcelId).toEqual(1);
213
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models[0].status).toEqual('in_transit');
214
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models[1].id).toEqual(1);
215
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models[1].parcelId).toEqual(1);
216
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models[1].status).toEqual('placed');
217
- expect(orders === null || orders === void 0 ? void 0 : orders.models[1].id).toEqual(13888);
218
- expect(orders === null || orders === void 0 ? void 0 : orders.models[1].email).toEqual('tswift@kujo.com');
219
- expect(orders === null || orders === void 0 ? void 0 : orders.models[1].lineItems.models.length).toEqual(1);
220
- expect(orders === null || orders === void 0 ? void 0 : orders.models[1].lineItems.models[0].id).toEqual(16900);
221
- expect(orders === null || orders === void 0 ? void 0 : orders.models[1].lineItems.models[0].orderId).toEqual(13888);
222
- });
223
- // Problem:
224
- // Parcel
225
- // ParcelLineItem
226
- // LineItem
227
- // Order
228
- // Customer
229
- // ParcelLineItem
230
- // LineItem
231
- // [MISSING ORDER]
232
- // Issue occcurs in nestClump
233
- // Problem only surfaced when custom was included
234
- test('createOneFromDatabase where a deeply nested models property was misbehaving', () => {
235
- const core = (0, core_1.createCore)({ entities: entities_6.entities });
236
- const parcel = core.createOneFromDatabase(six);
237
- // The assertion that failed when the bug was present
238
- expect(parcel.parcelLineItems.models[1].lineItem.order).toBeDefined();
239
- // Lots of other assertions that are unrelated and shouldn't be here except
240
- // I'm insecure about the lack of tests so just going at it cause I can.
241
- expect(parcel.id).toEqual(1);
242
- expect(parcel.parcelLineItems.models.length).toEqual(2);
243
- expect(parcel.parcelLineItems.models[0].id).toEqual(604);
244
- expect(parcel.parcelLineItems.models[0].lineItem.id).toEqual(17298);
245
- expect(parcel.parcelLineItems.models[0].lineItem.order.id).toEqual(14219);
246
- expect(parcel.parcelLineItems.models[0].lineItem.order.customer.id).toEqual(5390);
247
- expect(parcel.parcelLineItems.models[0].lineItem.order.customer.email).toEqual('tswift@kujo.com');
248
- expect(parcel.parcelLineItems.models[1].id).toEqual(605);
249
- expect(parcel.parcelLineItems.models[1].lineItem.id).toEqual(17297);
250
- expect(parcel.parcelLineItems.models[1].lineItem.order.id).toEqual(14219);
251
- expect(parcel.parcelLineItems.models[1].lineItem.order.customer.id).toEqual(5390);
252
- expect(parcel.parcelLineItems.models[1].lineItem.order.customer.email).toEqual('tswift@kujo.com');
253
- });
254
- // Problem:
255
- // InventoryLevel
256
- // ActualProductVariant
257
- // ProductVariant(1)
258
- // Color
259
- // ProductVariant(2)
260
- // Instead of:
261
- // InventoryLevel
262
- // ActualProductVariant
263
- // ProductVariant
264
- // Color
265
- // ProductVariant(2)
266
- // Color
267
- // Issue occcurs in nestClump
268
- test('createOneFromDatabase where a deeply nested models property was attaching to wrong parent', () => {
269
- const core = (0, core_1.createCore)({ entities: entities_3.entities });
270
- const inventoryLevel = core.createOneFromDatabase(seven);
271
- // The assertion that failed when the bug was present
272
- expect(inventoryLevel.actualProductVariant.productVariants.models[1]).toBeDefined();
273
- // Lots of other assertions that are unrelated and shouldn't be here except
274
- // I'm insecure about the lack of tests so just going at it cause I can.
275
- expect(inventoryLevel.id).toEqual(30);
276
- expect(inventoryLevel.actualProductVariant.id).toEqual(15);
277
- expect(inventoryLevel.actualProductVariant.productVariants.models.length).toEqual(2);
278
- expect(inventoryLevel.actualProductVariant.productVariants.models[0].id).toEqual(179);
279
- expect(inventoryLevel.actualProductVariant.productVariants.models[0].color.id).toEqual(4);
280
- expect(inventoryLevel.actualProductVariant.productVariants.models[0].gender.id).toEqual(1);
281
- expect(inventoryLevel.actualProductVariant.productVariants.models[0].size.id).toEqual(8);
282
- expect(inventoryLevel.actualProductVariant.productVariants.models[1].id).toEqual(180);
283
- expect(inventoryLevel.actualProductVariant.productVariants.models[1].color.id).toEqual(4);
284
- expect(inventoryLevel.actualProductVariant.productVariants.models[1].gender.id).toEqual(2);
285
- expect(inventoryLevel.actualProductVariant.productVariants.models[1].size.id).toEqual(11);
286
- });
287
- // Problem:
288
- // Shipment
289
- // ShipmentActualProductVariant
290
- // ActualProductVariant
291
- // ProductVariant(1)
292
- // Product
293
- // ProductVariant(2)
294
- // ShipmentActualProductVariant
295
- // ActualProductVariant
296
- // Instead of:
297
- // Shipment
298
- // ShipmentActualProductVariant
299
- // ActualProductVariant
300
- // ProductVariant(1)
301
- // Product
302
- // ShipmentActualProductVariant
303
- // ActualProductVariant
304
- // ProductVariant(2)
305
- // Product
306
- // Issue occcurs in nestClump
307
- test('createFromDatabase where a deeply nested models property was attaching to wrong parent 2', () => {
308
- const core = (0, core_1.createCore)({ entities: entities_3.entities });
309
- const shipments = core.createFromDatabase(eight);
310
- // The assertion that failed when the bug was present
311
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants).toBeDefined();
312
- // IN ADDITION TO ABOVE ASSERTION and helpful test description of what is
313
- // being tested, the below tests tease out some logic that was hitherto
314
- // incorrect. This "some logic" should be defined and have separate tests
315
- // and jazz, but my brain hurts so TLDR these below tests are important but
316
- // (somewhat?) unrelated to the example/assertion above. "Are you serious?!"
317
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models.length).toEqual(2);
318
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].id).toEqual(19);
319
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models.length).toEqual(2);
320
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].id).toEqual(25);
321
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].actualProductVariant.id).toEqual(65);
322
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models.length).toEqual(2);
323
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[0].id).toEqual(310);
324
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[0].product.id).toEqual(1);
325
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[0].size.id).toEqual(1);
326
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[0].color.id).toEqual(1);
327
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[0].gender.id).toEqual(1);
328
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[1].id).toEqual(309);
329
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[1].product.id).toEqual(2);
330
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[1].size.id).toEqual(4);
331
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[1].color.id).toEqual(1);
332
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[1].gender.id).toEqual(2);
333
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].id).toEqual(26);
334
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.id).toEqual(25);
335
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants.models.length).toEqual(2);
336
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants.models[0].id).toEqual(194);
337
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants.models[0].product.id).toEqual(1);
338
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants.models[0].size.id).toEqual(2);
339
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants.models[0].color.id).toEqual(1);
340
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants.models[0].gender.id).toEqual(1);
341
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants.models[1].id).toEqual(195);
342
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants.models[1].product.id).toEqual(2);
343
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants.models[1].size.id).toEqual(5);
344
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants.models[1].color.id).toEqual(1);
345
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants.models[1].gender.id).toEqual(2);
346
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].id).toEqual(18);
347
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models.length).toEqual(1);
348
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].id).toEqual(1);
349
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].actualProductVariant.id).toEqual(25);
350
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models.length).toEqual(2);
351
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[0].id).toEqual(194);
352
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[0].product.id).toEqual(1);
353
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[0].size.id).toEqual(2);
354
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[0].color.id).toEqual(1);
355
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[0].gender.id).toEqual(1);
356
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[1].id).toEqual(195);
357
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[1].product.id).toEqual(2);
358
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[1].size.id).toEqual(5);
359
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[1].color.id).toEqual(1);
360
- expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[1].gender.id).toEqual(2);
361
- });
362
- // Issue occcurs in nestClump
363
- // Problem is with only top level nodes
364
- test('createFromDatabase with just top level nodes', () => {
365
- const core = (0, core_1.createCore)({ entities: entities_4.entities });
366
- let featureSwitches;
367
- try {
368
- // This failed when the bug was present
369
- featureSwitches = core.createFromDatabase(nine);
370
- }
371
- catch (e) {
372
- expect(e).not.toBeDefined();
373
- }
374
- expect(featureSwitches).toBeDefined();
375
- // Lots of other assertions that are unrelated and shouldn't be here except
376
- // I'm insecure about the lack of tests so just going at it cause I can.
377
- expect(featureSwitches === null || featureSwitches === void 0 ? void 0 : featureSwitches.models.length).toEqual(2);
378
- expect(featureSwitches === null || featureSwitches === void 0 ? void 0 : featureSwitches.models[0].id).toEqual('google_one_tap_sign_in');
379
- expect(featureSwitches === null || featureSwitches === void 0 ? void 0 : featureSwitches.models[1].id).toEqual('website_live_chat');
28
+ const fourteen = require('../test-utils/fourteen/results.json');
29
+ describe('createFromDatabase', () => {
30
+ test('multiple rows reduce to one nested object (with all one-to-one or one-to-many tables)', () => {
31
+ const core = (0, core_1.createCore)({ entities: entities_1.entities });
32
+ const orders = core.createFromDatabase(one);
33
+ expect(orders.models.length).toEqual(1);
34
+ const order = orders.models[0];
35
+ expect(order === null || order === void 0 ? void 0 : order.id).toEqual(3866);
36
+ expect(order === null || order === void 0 ? void 0 : order.utmSource.id).toEqual(6);
37
+ expect(order === null || order === void 0 ? void 0 : order.lineItems.models.length).toEqual(6);
38
+ expect(order.lineItems.models[0].id).toEqual(2271);
39
+ expect(order.lineItems.models[0].productVariant.id).toEqual(163);
40
+ expect(order.lineItems.models[0].productVariant.product.id).toEqual(1);
41
+ expect(order.lineItems.models[1].id).toEqual(2272);
42
+ expect(order.lineItems.models[1].productVariant.id).toEqual(186);
43
+ expect(order.lineItems.models[1].productVariant.product.id).toEqual(1);
44
+ expect(order.lineItems.models[2].id).toEqual(2273);
45
+ expect(order.lineItems.models[2].productVariant.id).toEqual(213);
46
+ expect(order.lineItems.models[2].productVariant.product.id).toEqual(1);
47
+ expect(order.lineItems.models[3].id).toEqual(2274);
48
+ expect(order.lineItems.models[3].productVariant.id).toEqual(207);
49
+ expect(order.lineItems.models[3].productVariant.product.id).toEqual(1);
50
+ expect(order.lineItems.models[4].id).toEqual(2275);
51
+ expect(order.lineItems.models[4].productVariant.id).toEqual(296);
52
+ expect(order.lineItems.models[4].productVariant.product.id).toEqual(5);
53
+ expect(order.lineItems.models[5].id).toEqual(2276);
54
+ expect(order.lineItems.models[5].productVariant.id).toEqual(308);
55
+ expect(order.lineItems.models[5].productVariant.product.id).toEqual(3);
56
+ });
57
+ test('createFromDatabase where multiple rows reduce to one nested object (with many-to-many tables)', () => {
58
+ const core = (0, core_1.createCore)({ entities: entities_2.entities });
59
+ const articles = core.createFromDatabase(two);
60
+ expect(articles.models.length).toEqual(1);
61
+ const article = articles.models[0];
62
+ expect(article.id).toEqual(14);
63
+ expect(article.person.id).toEqual(8);
64
+ expect(article.articleTags.models.length).toEqual(10);
65
+ expect(article.articleTags.models[0].id).toEqual(36);
66
+ expect(article.articleTags.models[0].tag.id).toEqual(3);
67
+ expect(article.articleTags.models[1].id).toEqual(37);
68
+ expect(article.articleTags.models[1].tag.id).toEqual(4);
69
+ expect(article.articleTags.models[2].id).toEqual(38);
70
+ expect(article.articleTags.models[2].tag.id).toEqual(5);
71
+ expect(article.articleTags.models[3].id).toEqual(39);
72
+ expect(article.articleTags.models[3].tag.id).toEqual(6);
73
+ expect(article.articleTags.models[4].id).toEqual(40);
74
+ expect(article.articleTags.models[4].tag.id).toEqual(7);
75
+ expect(article.articleTags.models[5].id).toEqual(41);
76
+ expect(article.articleTags.models[5].tag.id).toEqual(8);
77
+ expect(article.articleTags.models[6].id).toEqual(42);
78
+ expect(article.articleTags.models[6].tag.id).toEqual(9);
79
+ expect(article.articleTags.models[7].id).toEqual(43);
80
+ expect(article.articleTags.models[7].tag.id).toEqual(11);
81
+ expect(article.articleTags.models[8].id).toEqual(44);
82
+ expect(article.articleTags.models[8].tag.id).toEqual(12);
83
+ expect(article.articleTags.models[9].id).toEqual(45);
84
+ expect(article.articleTags.models[9].tag.id).toEqual(16);
85
+ });
86
+ test('multiple rows reduce to many rows with nested objects (with many-to-many tables)', () => {
87
+ const core = (0, core_1.createCore)({ entities: entities_2.entities });
88
+ const articles = core.createFromDatabase(three);
89
+ expect(Array.isArray(articles.models)).toBe(true);
90
+ expect(articles instanceof article_1.Articles).toBe(true);
91
+ expect(articles.models.length).toEqual(2);
92
+ const first = articles.models[0];
93
+ expect(first.person.id).toEqual(8);
94
+ expect(first.articleTags.models.length).toEqual(10);
95
+ expect(first.articleTags.models[0].id).toEqual(36);
96
+ expect(first.articleTags.models[0].tag.id).toEqual(3);
97
+ expect(first.articleTags.models[1].id).toEqual(37);
98
+ expect(first.articleTags.models[1].tag.id).toEqual(4);
99
+ expect(first.articleTags.models[2].id).toEqual(38);
100
+ expect(first.articleTags.models[2].tag.id).toEqual(5);
101
+ expect(first.articleTags.models[3].id).toEqual(39);
102
+ expect(first.articleTags.models[3].tag.id).toEqual(6);
103
+ expect(first.articleTags.models[4].id).toEqual(40);
104
+ expect(first.articleTags.models[4].tag.id).toEqual(7);
105
+ expect(first.articleTags.models[5].id).toEqual(41);
106
+ expect(first.articleTags.models[5].tag.id).toEqual(8);
107
+ expect(first.articleTags.models[6].id).toEqual(42);
108
+ expect(first.articleTags.models[6].tag.id).toEqual(9);
109
+ expect(first.articleTags.models[7].id).toEqual(43);
110
+ expect(first.articleTags.models[7].tag.id).toEqual(11);
111
+ expect(first.articleTags.models[8].id).toEqual(44);
112
+ expect(first.articleTags.models[8].tag.id).toEqual(12);
113
+ expect(first.articleTags.models[9].id).toEqual(45);
114
+ expect(first.articleTags.models[9].tag.id).toEqual(16);
115
+ const second = articles.models[1];
116
+ expect(second.id).toEqual(12);
117
+ expect(second.person.id).toEqual(17);
118
+ expect(second.articleTags.models.length).toEqual(3);
119
+ expect(second.articleTags.models[0].id).toEqual(33);
120
+ expect(second.articleTags.models[0].tag.id).toEqual(1);
121
+ expect(second.articleTags.models[1].id).toEqual(34);
122
+ expect(second.articleTags.models[1].tag.id).toEqual(5);
123
+ expect(second.articleTags.models[2].id).toEqual(35);
124
+ expect(second.articleTags.models[2].tag.id).toEqual(15);
125
+ });
126
+ // Tests for where a deeply nested node which points to a node, is itself
127
+ // reused (not recreated each time) so that nodes pointing to it all stack
128
+ // together on it, rather than each attaching to different replica nodes
129
+ // which overwrite themselves on the node it points to.
130
+ // The example here is with the productVariant node being reused so that
131
+ // productVariantImages append to it, instead of each productVariantImage
132
+ // living on its own productVariant (which would keep overwriting itself
133
+ // on the actualProductVariant node).
134
+ test('node is already seen', () => {
135
+ const core = (0, core_1.createCore)({ entities: entities_3.entities });
136
+ const inventoryLevels = core.createFromDatabase(four);
137
+ expect(inventoryLevels).toBeDefined();
138
+ const first = inventoryLevels === null || inventoryLevels === void 0 ? void 0 : inventoryLevels.models[0];
139
+ expect(first === null || first === void 0 ? void 0 : first.id).toEqual(15);
140
+ expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.id).toEqual(120);
141
+ expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models.length).toEqual(1);
142
+ expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].actualProductVariantId).toEqual(120);
143
+ // I think the above test is good enough, and not sure I actual care about below
144
+ // expect(first.actualProductVariant.productVariants.models[0].actualProductVariant.id).toEqual(120);
145
+ expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].id).toEqual(199);
146
+ expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].color.id).toEqual(1);
147
+ expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].gender.id).toEqual(1);
148
+ expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].product.id).toEqual(1);
149
+ expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].size.id).toEqual(4);
150
+ expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].productVariantImages.models.length).toEqual(7);
151
+ expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].productVariantImages.models[0].id).toEqual(621);
152
+ expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].productVariantImages.models[1].id).toEqual(709);
153
+ expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].productVariantImages.models[2].id).toEqual(797);
154
+ expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].productVariantImages.models[3].id).toEqual(885);
155
+ expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].productVariantImages.models[4].id).toEqual(973);
156
+ expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].productVariantImages.models[5].id).toEqual(1061);
157
+ expect(first === null || first === void 0 ? void 0 : first.actualProductVariant.productVariants.models[0].productVariantImages.models[6].id).toEqual(1149);
158
+ const second = inventoryLevels === null || inventoryLevels === void 0 ? void 0 : inventoryLevels.models[1];
159
+ expect(second === null || second === void 0 ? void 0 : second.id).toEqual(35);
160
+ expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.id).toEqual(125);
161
+ expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models.length).toEqual(1);
162
+ expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].actualProductVariantId).toEqual(125);
163
+ // I think the above test is good enough, and not sure I actual care about below
164
+ // expect(second.actualProductVariant.productVariants.models[0].actualProductVariant.id).toEqual(125);
165
+ expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].id).toEqual(209);
166
+ expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].color.id).toEqual(1);
167
+ expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].gender.id).toEqual(1);
168
+ expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].product.id).toEqual(1);
169
+ expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].size.id).toEqual(9);
170
+ expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].productVariantImages.models.length).toEqual(7);
171
+ expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].productVariantImages.models[0].id).toEqual(679);
172
+ expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].productVariantImages.models[1].id).toEqual(767);
173
+ expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].productVariantImages.models[2].id).toEqual(855);
174
+ expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].productVariantImages.models[3].id).toEqual(943);
175
+ expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].productVariantImages.models[4].id).toEqual(1031);
176
+ expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].productVariantImages.models[5].id).toEqual(1119);
177
+ expect(second === null || second === void 0 ? void 0 : second.actualProductVariant.productVariants.models[0].productVariantImages.models[6].id).toEqual(1207);
178
+ });
179
+ // Test for a nested object (eg, parcel) with objects in it that referenced to
180
+ // it (eg, parcel_events), correctly placing the objects (parcel_events) in
181
+ // its (parcel) collection of models, and not errantly placing the established
182
+ // parent node (parcel) as a direct reference of the child (parcel_event).
183
+ // For example: the errant behavior was:
184
+ // Parcel1
185
+ // ParcelEvent1
186
+ // Parcel1
187
+ // ParcelEvent2
188
+ // Instead of:
189
+ // Parcel1
190
+ // ParcelEvent1
191
+ // ParcelEvent2
192
+ // NOTE: if this test ever breaks, you can widdle the five.json file to just
193
+ // the two relevant line items of the one relevant order. This test should
194
+ // be doing that, but since code coverage all-around isn't great and I already
195
+ // had this fuller json dump from production, I just used it all - YOLO.
196
+ test('a deeply nested models property was misbehaving', () => {
197
+ const core = (0, core_1.createCore)({ entities: entities_5.entities });
198
+ const orders = core.createFromDatabase(five);
199
+ // The assertion that failed when the bug was present
200
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models.length).toEqual(2);
201
+ // Lots of other assertions that are unrelated and shouldn't be here except
202
+ // I'm insecure about the lack of tests so just going at it cause I can.
203
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].id).toEqual(14219);
204
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].email).toEqual('tswift@kujo.com');
205
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models.length).toEqual(2);
206
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].id).toEqual(17298);
207
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].orderId).toEqual(14219);
208
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].id).toEqual(17297);
209
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].orderId).toEqual(14219);
210
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models.length).toEqual(1);
211
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].id).toEqual(1);
212
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].parcelId).toEqual(1);
213
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].lineItemId).toEqual(17297);
214
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].parcel.id).toEqual(1);
215
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models.length).toEqual(2);
216
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models[0].id).toEqual(3);
217
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models[0].parcelId).toEqual(1);
218
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models[0].status).toEqual('in_transit');
219
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models[1].id).toEqual(1);
220
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models[1].parcelId).toEqual(1);
221
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models[1].status).toEqual('placed');
222
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[1].id).toEqual(13888);
223
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[1].email).toEqual('tswift@kujo.com');
224
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[1].lineItems.models.length).toEqual(1);
225
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[1].lineItems.models[0].id).toEqual(16900);
226
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[1].lineItems.models[0].orderId).toEqual(13888);
227
+ });
228
+ // Problem:
229
+ // Parcel
230
+ // ParcelLineItem
231
+ // LineItem
232
+ // Order
233
+ // Customer
234
+ // ParcelLineItem
235
+ // LineItem
236
+ // [MISSING ORDER]
237
+ // Issue occcurs in nestClump
238
+ // Problem only surfaced when custom was included
239
+ test('a deeply nested models property was misbehaving', () => {
240
+ const core = (0, core_1.createCore)({ entities: entities_6.entities });
241
+ const parcels = core.createFromDatabase(six);
242
+ expect(parcels.models.length).toEqual(1);
243
+ const parcel = parcels.models[0];
244
+ // The assertion that failed when the bug was present
245
+ expect(parcel.parcelLineItems.models[1].lineItem.order).toBeDefined();
246
+ // Lots of other assertions that are unrelated and shouldn't be here except
247
+ // I'm insecure about the lack of tests so just going at it cause I can.
248
+ expect(parcel.id).toEqual(1);
249
+ expect(parcel.parcelLineItems.models.length).toEqual(2);
250
+ expect(parcel.parcelLineItems.models[0].id).toEqual(604);
251
+ expect(parcel.parcelLineItems.models[0].lineItem.id).toEqual(17298);
252
+ expect(parcel.parcelLineItems.models[0].lineItem.order.id).toEqual(14219);
253
+ expect(parcel.parcelLineItems.models[0].lineItem.order.customer.id).toEqual(5390);
254
+ expect(parcel.parcelLineItems.models[0].lineItem.order.customer.email).toEqual('tswift@kujo.com');
255
+ expect(parcel.parcelLineItems.models[1].id).toEqual(605);
256
+ expect(parcel.parcelLineItems.models[1].lineItem.id).toEqual(17297);
257
+ expect(parcel.parcelLineItems.models[1].lineItem.order.id).toEqual(14219);
258
+ expect(parcel.parcelLineItems.models[1].lineItem.order.customer.id).toEqual(5390);
259
+ expect(parcel.parcelLineItems.models[1].lineItem.order.customer.email).toEqual('tswift@kujo.com');
260
+ });
261
+ // Problem:
262
+ // InventoryLevel
263
+ // ActualProductVariant
264
+ // ProductVariant(1)
265
+ // Color
266
+ // ProductVariant(2)
267
+ // Instead of:
268
+ // InventoryLevel
269
+ // ActualProductVariant
270
+ // ProductVariant
271
+ // Color
272
+ // ProductVariant(2)
273
+ // Color
274
+ // Issue occcurs in nestClump
275
+ test('a deeply nested models property was attaching to wrong parent', () => {
276
+ const core = (0, core_1.createCore)({ entities: entities_3.entities });
277
+ const inventoryLevels = core.createFromDatabase(seven);
278
+ expect(inventoryLevels.models.length).toEqual(1);
279
+ const inventoryLevel = inventoryLevels.models[0];
280
+ // The assertion that failed when the bug was present
281
+ expect(inventoryLevel.actualProductVariant.productVariants.models[1]).toBeDefined();
282
+ // Lots of other assertions that are unrelated and shouldn't be here except
283
+ // I'm insecure about the lack of tests so just going at it cause I can.
284
+ expect(inventoryLevel.id).toEqual(30);
285
+ expect(inventoryLevel.actualProductVariant.id).toEqual(15);
286
+ expect(inventoryLevel.actualProductVariant.productVariants.models.length).toEqual(2);
287
+ expect(inventoryLevel.actualProductVariant.productVariants.models[0].id).toEqual(179);
288
+ expect(inventoryLevel.actualProductVariant.productVariants.models[0].color.id).toEqual(4);
289
+ expect(inventoryLevel.actualProductVariant.productVariants.models[0].gender.id).toEqual(1);
290
+ expect(inventoryLevel.actualProductVariant.productVariants.models[0].size.id).toEqual(8);
291
+ expect(inventoryLevel.actualProductVariant.productVariants.models[1].id).toEqual(180);
292
+ expect(inventoryLevel.actualProductVariant.productVariants.models[1].color.id).toEqual(4);
293
+ expect(inventoryLevel.actualProductVariant.productVariants.models[1].gender.id).toEqual(2);
294
+ expect(inventoryLevel.actualProductVariant.productVariants.models[1].size.id).toEqual(11);
295
+ });
296
+ // Problem:
297
+ // Shipment
298
+ // ShipmentActualProductVariant
299
+ // ActualProductVariant
300
+ // ProductVariant(1)
301
+ // Product
302
+ // ProductVariant(2)
303
+ // ShipmentActualProductVariant
304
+ // ActualProductVariant
305
+ // Instead of:
306
+ // Shipment
307
+ // ShipmentActualProductVariant
308
+ // ActualProductVariant
309
+ // ProductVariant(1)
310
+ // Product
311
+ // ShipmentActualProductVariant
312
+ // ActualProductVariant
313
+ // ProductVariant(2)
314
+ // Product
315
+ // Issue occcurs in nestClump
316
+ test('a deeply nested models property was attaching to wrong parent 2', () => {
317
+ const core = (0, core_1.createCore)({ entities: entities_3.entities });
318
+ const shipments = core.createFromDatabase(eight);
319
+ // The assertion that failed when the bug was present
320
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants).toBeDefined();
321
+ // IN ADDITION TO ABOVE ASSERTION and helpful test description of what is
322
+ // being tested, the below tests tease out some logic that was hitherto
323
+ // incorrect. This "some logic" should be defined and have separate tests
324
+ // and jazz, but my brain hurts so TLDR these below tests are important but
325
+ // (somewhat?) unrelated to the example/assertion above. "Are you serious?!"
326
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models.length).toEqual(2);
327
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].id).toEqual(19);
328
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models.length).toEqual(2);
329
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].id).toEqual(25);
330
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].actualProductVariant.id).toEqual(65);
331
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models.length).toEqual(2);
332
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[0].id).toEqual(310);
333
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[0].product.id).toEqual(1);
334
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[0].size.id).toEqual(1);
335
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[0].color.id).toEqual(1);
336
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[0].gender.id).toEqual(1);
337
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[1].id).toEqual(309);
338
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[1].product.id).toEqual(2);
339
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[1].size.id).toEqual(4);
340
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[1].color.id).toEqual(1);
341
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[1].gender.id).toEqual(2);
342
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].id).toEqual(26);
343
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.id).toEqual(25);
344
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants.models.length).toEqual(2);
345
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants.models[0].id).toEqual(194);
346
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants.models[0].product.id).toEqual(1);
347
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants.models[0].size.id).toEqual(2);
348
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants.models[0].color.id).toEqual(1);
349
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants.models[0].gender.id).toEqual(1);
350
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants.models[1].id).toEqual(195);
351
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants.models[1].product.id).toEqual(2);
352
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants.models[1].size.id).toEqual(5);
353
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants.models[1].color.id).toEqual(1);
354
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[0].shipmentActualProductVariants.models[1].actualProductVariant.productVariants.models[1].gender.id).toEqual(2);
355
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].id).toEqual(18);
356
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models.length).toEqual(1);
357
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].id).toEqual(1);
358
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].actualProductVariant.id).toEqual(25);
359
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models.length).toEqual(2);
360
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[0].id).toEqual(194);
361
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[0].product.id).toEqual(1);
362
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[0].size.id).toEqual(2);
363
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[0].color.id).toEqual(1);
364
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[0].gender.id).toEqual(1);
365
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[1].id).toEqual(195);
366
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[1].product.id).toEqual(2);
367
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[1].size.id).toEqual(5);
368
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[1].color.id).toEqual(1);
369
+ expect(shipments === null || shipments === void 0 ? void 0 : shipments.models[1].shipmentActualProductVariants.models[0].actualProductVariant.productVariants.models[1].gender.id).toEqual(2);
370
+ });
371
+ // Issue occcurs in nestClump
372
+ // Problem is with only top level nodes
373
+ test('just top level nodes', () => {
374
+ const core = (0, core_1.createCore)({ entities: entities_4.entities });
375
+ let featureSwitches;
376
+ try {
377
+ // This failed when the bug was present
378
+ featureSwitches = core.createFromDatabase(nine);
379
+ }
380
+ catch (e) {
381
+ expect(e).not.toBeDefined();
382
+ }
383
+ expect(featureSwitches).toBeDefined();
384
+ // Lots of other assertions that are unrelated and shouldn't be here except
385
+ // I'm insecure about the lack of tests so just going at it cause I can.
386
+ expect(featureSwitches === null || featureSwitches === void 0 ? void 0 : featureSwitches.models.length).toEqual(2);
387
+ expect(featureSwitches === null || featureSwitches === void 0 ? void 0 : featureSwitches.models[0].id).toEqual('google_one_tap_sign_in');
388
+ expect(featureSwitches === null || featureSwitches === void 0 ? void 0 : featureSwitches.models[1].id).toEqual('website_live_chat');
389
+ });
390
+ // Issue occcurs in nestClump
391
+ // Problem is when oldest parent is an empty join record and is not included
392
+ // which results in the oldest parent search returning -1 and parent heirarchy
393
+ // is thus messed up.
394
+ test('10', () => {
395
+ const core = (0, core_1.createCore)({ entities: entities_3.entities });
396
+ let orders;
397
+ try {
398
+ // This failed when the bug was present
399
+ orders = core.createFromDatabase(ten);
400
+ }
401
+ catch (e) {
402
+ expect(e).not.toBeDefined();
403
+ }
404
+ expect(orders).toBeDefined();
405
+ // Lots of other assertions that are unrelated and shouldn't be here except
406
+ // I'm insecure about the lack of tests so just going at it cause I can.
407
+ expect(orders === null || orders === void 0 ? void 0 : orders.models.length).toEqual(5);
408
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].id).toEqual(24591);
409
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].customer.id).toEqual(5390);
410
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].physicalAddress.id).toEqual(48982);
411
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models.length).toEqual(1);
412
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].id).toEqual(29883);
413
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].productVariant.id).toEqual(158);
414
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].productVariant.product.id).toEqual(1);
415
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].productVariant.size.id).toEqual(9);
416
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].productVariant.color.id).toEqual(3);
417
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].productVariant.gender.id).toEqual(1);
418
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].productVariant.productVariantImages.models.length).toEqual(1);
419
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].productVariant.productVariantImages.models[0].id).toEqual(17);
420
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models.length).toEqual(1);
421
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].id).toEqual(6100);
422
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.id).toEqual(5942);
423
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models.length).toEqual(14);
424
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[0].id).toEqual(193775);
425
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[1].id).toEqual(193774);
426
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[2].id).toEqual(193773);
427
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[3].id).toEqual(193425);
428
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[4].id).toEqual(193424);
429
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[5].id).toEqual(193423);
430
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[6].id).toEqual(192713);
431
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[7].id).toEqual(192712);
432
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[8].id).toEqual(192711);
433
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[9].id).toEqual(192709);
434
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[10].id).toEqual(192171);
435
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[11].id).toEqual(192170);
436
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[12].id).toEqual(192169);
437
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[13].id).toEqual(191790);
438
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[1].id).toEqual(24589);
439
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[1].customer.id).toEqual(5390);
440
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[1].physicalAddress.id).toEqual(48982);
441
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[1].lineItems.models.length).toEqual(1);
442
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[1].lineItems.models[0].id).toEqual(29880);
443
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[1].lineItems.models[0].productVariant.id).toEqual(158);
444
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[1].lineItems.models[0].productVariant.product.id).toEqual(1);
445
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[1].lineItems.models[0].productVariant.size.id).toEqual(9);
446
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[1].lineItems.models[0].productVariant.color.id).toEqual(3);
447
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[1].lineItems.models[0].productVariant.gender.id).toEqual(1);
448
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[1].lineItems.models[0].productVariant.productVariantImages.models.length).toEqual(1);
449
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[1].lineItems.models[0].productVariant.productVariantImages.models[0].id).toEqual(17);
450
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[2].id).toEqual(24587);
451
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[2].customer.id).toEqual(5390);
452
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[2].physicalAddress.id).toEqual(28145);
453
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models.length).toEqual(1);
454
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].id).toEqual(29877);
455
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].productVariant.id).toEqual(158);
456
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].productVariant.product.id).toEqual(1);
457
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].productVariant.size.id).toEqual(9);
458
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].productVariant.color.id).toEqual(3);
459
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].productVariant.gender.id).toEqual(1);
460
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].productVariant.productVariantImages.models.length).toEqual(1);
461
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].productVariant.productVariantImages.models[0].id).toEqual(17);
462
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].parcelLineItems.models.length).toEqual(1);
463
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].parcelLineItems.models[0].id).toEqual(6070);
464
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].parcelLineItems.models[0].parcel.id).toEqual(5914);
465
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models.length).toEqual(1);
466
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[0].id).toEqual(189194);
467
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].id).toEqual(14219);
468
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].customer.id).toEqual(5390);
469
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].physicalAddress.id).toEqual(28145);
470
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models.length).toEqual(2);
471
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].id).toEqual(17298);
472
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].productVariant.id).toEqual(353);
473
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].productVariant.product.id).toEqual(8);
474
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].productVariant.size.id).toEqual(20);
475
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].productVariant.color.id).toEqual(10);
476
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].productVariant.gender.id).toEqual(3);
477
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].productVariant.productVariantImages.models.length).toEqual(1);
478
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].productVariant.productVariantImages.models[0].id).toEqual(789);
479
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].parcelLineItems.models.length).toEqual(1);
480
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].parcelLineItems.models[0].id).toEqual(3338);
481
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].parcelLineItems.models[0].parcel.id).toEqual(3304);
482
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models.length).toEqual(3);
483
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[0].id).toEqual(87279);
484
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[1].id).toEqual(87278);
485
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[2].id).toEqual(84361);
486
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].id).toEqual(17297);
487
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].productVariant.id).toEqual(344);
488
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].productVariant.product.id).toEqual(6);
489
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].productVariant.size.id).toEqual(22);
490
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].productVariant.color.id).toEqual(8);
491
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].productVariant.gender.id).toEqual(3);
492
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].productVariant.productVariantImages.models.length).toEqual(1);
493
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].productVariant.productVariantImages.models[0].id).toEqual(780);
494
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].parcelLineItems.models.length).toEqual(1);
495
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].parcelLineItems.models[0].id).toEqual(2311);
496
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].parcelLineItems.models[0].parcel.id).toEqual(2317);
497
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models.length).toEqual(3);
498
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models[0].id).toEqual(52627);
499
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models[1].id).toEqual(52626);
500
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models[2].id).toEqual(48326);
501
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[4].id).toEqual(13888);
502
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[4].customer.id).toEqual(5390);
503
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[4].physicalAddress.id).toEqual(7608);
504
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[4].lineItems.models.length).toEqual(1);
505
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[4].lineItems.models[0].id).toEqual(16900);
506
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[4].lineItems.models[0].productVariant.id).toEqual(363);
507
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[4].lineItems.models[0].productVariant.product.id).toEqual(5);
508
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[4].lineItems.models[0].productVariant.size.id).toEqual(8);
509
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[4].lineItems.models[0].productVariant.color.id).toEqual(12);
510
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[4].lineItems.models[0].productVariant.gender.id).toEqual(1);
511
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[4].lineItems.models[0].productVariant.productVariantImages.models.length).toEqual(1);
512
+ expect(orders === null || orders === void 0 ? void 0 : orders.models[4].lineItems.models[0].productVariant.productVariantImages.models[0].id).toEqual(829);
513
+ });
514
+ // Issue occcurs in nestClump
515
+ // Problem from early returning not logging bo so parent hierarcy was missing it
516
+ test('11', () => {
517
+ const core = (0, core_1.createCore)({ entities: entities_3.entities });
518
+ let orders;
519
+ try {
520
+ // This failed when the bug was present
521
+ orders = core.createFromDatabase(eleven);
522
+ }
523
+ catch (e) {
524
+ expect(e).not.toBeDefined();
525
+ }
526
+ expect(orders).toBeDefined();
527
+ });
528
+ // Issue occcurs in nestClump
529
+ // Problem when a table references another model twice (two columns)
530
+ test('12', () => {
531
+ const core = (0, core_1.createCore)({ entities: entities_7.entities });
532
+ let prompt;
533
+ try {
534
+ // This failed when the bug was present
535
+ prompt = core.createFromDatabase(twelve);
536
+ }
537
+ catch (e) {
538
+ expect(e).not.toBeDefined();
539
+ }
540
+ expect(prompt).toBeDefined();
541
+ // Ideally the below should work
542
+ // expect(prompt.fromMember.id).toEqual(1);
543
+ });
544
+ // Issue occcurs in nestClump
545
+ // Problem when a table has records that are supposed to nest under root
546
+ // but nest under other stuff below it instead
547
+ // Member
548
+ // Recommendations [1]
549
+ // Brand
550
+ // Recommendations [1]
551
+ // Passion
552
+ // Recommendations [2]
553
+ // -- instead of correct --
554
+ // Member
555
+ // Recommendations[4]
556
+ // Brand
557
+ // Passion
558
+ test('13', () => {
559
+ const core = (0, core_1.createCore)({ entities: entities_8.entities });
560
+ const members = core.createFromDatabase(thirteen);
561
+ const member = members === null || members === void 0 ? void 0 : members.models[0];
562
+ expect(member === null || member === void 0 ? void 0 : member.recommendations.models.length).toEqual(4);
563
+ expect(member === null || member === void 0 ? void 0 : member.recommendations.models[0].brand.id).toEqual(2);
564
+ expect(member === null || member === void 0 ? void 0 : member.recommendations.models[0].product.id).toEqual(7);
565
+ expect(member === null || member === void 0 ? void 0 : member.recommendations.models[0].category.id).toEqual(1);
566
+ expect(member === null || member === void 0 ? void 0 : member.recommendations.models[0].recommendationAudiences.models[0].audience.id).toEqual(1);
567
+ expect(member === null || member === void 0 ? void 0 : member.recommendations.models[1].brand.id).toEqual(2);
568
+ expect(member === null || member === void 0 ? void 0 : member.recommendations.models[1].product.id).toEqual(1);
569
+ expect(member === null || member === void 0 ? void 0 : member.recommendations.models[1].category.id).toEqual(2);
570
+ expect(member === null || member === void 0 ? void 0 : member.recommendations.models[1].recommendationAudiences.models[0].audience.id).toEqual(1);
571
+ expect(member === null || member === void 0 ? void 0 : member.recommendations.models[2].brand.id).toEqual(3);
572
+ expect(member === null || member === void 0 ? void 0 : member.recommendations.models[2].product.id).toEqual(27);
573
+ expect(member === null || member === void 0 ? void 0 : member.recommendations.models[2].category.id).toEqual(3);
574
+ expect(member === null || member === void 0 ? void 0 : member.recommendations.models[2].recommendationAudiences.models[0].audience.id).toEqual(1);
575
+ expect(member === null || member === void 0 ? void 0 : member.recommendations.models[3].brand.id).toEqual(6);
576
+ expect(member === null || member === void 0 ? void 0 : member.recommendations.models[3].product.id).toEqual(75);
577
+ expect(member === null || member === void 0 ? void 0 : member.recommendations.models[3].category.id).toEqual(4);
578
+ expect(member === null || member === void 0 ? void 0 : member.recommendations.models[3].recommendationAudiences.models[0].audience.id).toEqual(1);
579
+ });
580
+ // Issue occcurs in nestClump
581
+ // Problem when a table has two columns which reference the same other table
582
+ test('14', () => {
583
+ var _a;
584
+ const core = (0, core_1.createCore)({ entities: entities_9.entities });
585
+ const persons = core.createFromDatabase(fourteen);
586
+ expect(persons === null || persons === void 0 ? void 0 : persons.models.length).toEqual(1);
587
+ expect(persons.models[0].id).toEqual(67);
588
+ // Known issue: A reference always uses the model's name,
589
+ // instead of some version of the column's name
590
+ expect((_a = persons.models[0].customers) === null || _a === void 0 ? void 0 : _a.models.length).toEqual(1);
591
+ expect(persons.models[0].customers.models[0].id).toEqual(4);
592
+ });
380
593
  });
381
- // Issue occcurs in nestClump
382
- // Problem is when oldest parent is an empty join record and is not included
383
- // which results in the oldest parent search returning -1 and parent heirarchy
384
- // is thus messed up.
385
- test('createFromDatabase 10', () => {
386
- const core = (0, core_1.createCore)({ entities: entities_3.entities });
387
- let orders;
388
- try {
389
- // This failed when the bug was present
390
- orders = core.createFromDatabase(ten);
391
- }
392
- catch (e) {
393
- expect(e).not.toBeDefined();
394
- }
395
- expect(orders).toBeDefined();
396
- // Lots of other assertions that are unrelated and shouldn't be here except
397
- // I'm insecure about the lack of tests so just going at it cause I can.
398
- expect(orders === null || orders === void 0 ? void 0 : orders.models.length).toEqual(5);
399
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].id).toEqual(24591);
400
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].customer.id).toEqual(5390);
401
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].physicalAddress.id).toEqual(48982);
402
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models.length).toEqual(1);
403
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].id).toEqual(29883);
404
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].productVariant.id).toEqual(158);
405
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].productVariant.product.id).toEqual(1);
406
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].productVariant.size.id).toEqual(9);
407
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].productVariant.color.id).toEqual(3);
408
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].productVariant.gender.id).toEqual(1);
409
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].productVariant.productVariantImages.models.length).toEqual(1);
410
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].productVariant.productVariantImages.models[0].id).toEqual(17);
411
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models.length).toEqual(1);
412
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].id).toEqual(6100);
413
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.id).toEqual(5942);
414
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models.length).toEqual(14);
415
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[0].id).toEqual(193775);
416
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[1].id).toEqual(193774);
417
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[2].id).toEqual(193773);
418
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[3].id).toEqual(193425);
419
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[4].id).toEqual(193424);
420
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[5].id).toEqual(193423);
421
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[6].id).toEqual(192713);
422
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[7].id).toEqual(192712);
423
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[8].id).toEqual(192711);
424
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[9].id).toEqual(192709);
425
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[10].id).toEqual(192171);
426
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[11].id).toEqual(192170);
427
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[12].id).toEqual(192169);
428
- expect(orders === null || orders === void 0 ? void 0 : orders.models[0].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[13].id).toEqual(191790);
429
- expect(orders === null || orders === void 0 ? void 0 : orders.models[1].id).toEqual(24589);
430
- expect(orders === null || orders === void 0 ? void 0 : orders.models[1].customer.id).toEqual(5390);
431
- expect(orders === null || orders === void 0 ? void 0 : orders.models[1].physicalAddress.id).toEqual(48982);
432
- expect(orders === null || orders === void 0 ? void 0 : orders.models[1].lineItems.models.length).toEqual(1);
433
- expect(orders === null || orders === void 0 ? void 0 : orders.models[1].lineItems.models[0].id).toEqual(29880);
434
- expect(orders === null || orders === void 0 ? void 0 : orders.models[1].lineItems.models[0].productVariant.id).toEqual(158);
435
- expect(orders === null || orders === void 0 ? void 0 : orders.models[1].lineItems.models[0].productVariant.product.id).toEqual(1);
436
- expect(orders === null || orders === void 0 ? void 0 : orders.models[1].lineItems.models[0].productVariant.size.id).toEqual(9);
437
- expect(orders === null || orders === void 0 ? void 0 : orders.models[1].lineItems.models[0].productVariant.color.id).toEqual(3);
438
- expect(orders === null || orders === void 0 ? void 0 : orders.models[1].lineItems.models[0].productVariant.gender.id).toEqual(1);
439
- expect(orders === null || orders === void 0 ? void 0 : orders.models[1].lineItems.models[0].productVariant.productVariantImages.models.length).toEqual(1);
440
- expect(orders === null || orders === void 0 ? void 0 : orders.models[1].lineItems.models[0].productVariant.productVariantImages.models[0].id).toEqual(17);
441
- expect(orders === null || orders === void 0 ? void 0 : orders.models[2].id).toEqual(24587);
442
- expect(orders === null || orders === void 0 ? void 0 : orders.models[2].customer.id).toEqual(5390);
443
- expect(orders === null || orders === void 0 ? void 0 : orders.models[2].physicalAddress.id).toEqual(28145);
444
- expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models.length).toEqual(1);
445
- expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].id).toEqual(29877);
446
- expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].productVariant.id).toEqual(158);
447
- expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].productVariant.product.id).toEqual(1);
448
- expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].productVariant.size.id).toEqual(9);
449
- expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].productVariant.color.id).toEqual(3);
450
- expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].productVariant.gender.id).toEqual(1);
451
- expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].productVariant.productVariantImages.models.length).toEqual(1);
452
- expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].productVariant.productVariantImages.models[0].id).toEqual(17);
453
- expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].parcelLineItems.models.length).toEqual(1);
454
- expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].parcelLineItems.models[0].id).toEqual(6070);
455
- expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].parcelLineItems.models[0].parcel.id).toEqual(5914);
456
- expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models.length).toEqual(1);
457
- expect(orders === null || orders === void 0 ? void 0 : orders.models[2].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[0].id).toEqual(189194);
458
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].id).toEqual(14219);
459
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].customer.id).toEqual(5390);
460
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].physicalAddress.id).toEqual(28145);
461
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models.length).toEqual(2);
462
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].id).toEqual(17298);
463
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].productVariant.id).toEqual(353);
464
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].productVariant.product.id).toEqual(8);
465
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].productVariant.size.id).toEqual(20);
466
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].productVariant.color.id).toEqual(10);
467
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].productVariant.gender.id).toEqual(3);
468
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].productVariant.productVariantImages.models.length).toEqual(1);
469
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].productVariant.productVariantImages.models[0].id).toEqual(789);
470
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].parcelLineItems.models.length).toEqual(1);
471
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].parcelLineItems.models[0].id).toEqual(3338);
472
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].parcelLineItems.models[0].parcel.id).toEqual(3304);
473
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models.length).toEqual(3);
474
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[0].id).toEqual(87279);
475
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[1].id).toEqual(87278);
476
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[0].parcelLineItems.models[0].parcel.parcelEvents.models[2].id).toEqual(84361);
477
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].id).toEqual(17297);
478
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].productVariant.id).toEqual(344);
479
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].productVariant.product.id).toEqual(6);
480
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].productVariant.size.id).toEqual(22);
481
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].productVariant.color.id).toEqual(8);
482
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].productVariant.gender.id).toEqual(3);
483
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].productVariant.productVariantImages.models.length).toEqual(1);
484
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].productVariant.productVariantImages.models[0].id).toEqual(780);
485
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].parcelLineItems.models.length).toEqual(1);
486
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].parcelLineItems.models[0].id).toEqual(2311);
487
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].parcelLineItems.models[0].parcel.id).toEqual(2317);
488
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models.length).toEqual(3);
489
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models[0].id).toEqual(52627);
490
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models[1].id).toEqual(52626);
491
- expect(orders === null || orders === void 0 ? void 0 : orders.models[3].lineItems.models[1].parcelLineItems.models[0].parcel.parcelEvents.models[2].id).toEqual(48326);
492
- expect(orders === null || orders === void 0 ? void 0 : orders.models[4].id).toEqual(13888);
493
- expect(orders === null || orders === void 0 ? void 0 : orders.models[4].customer.id).toEqual(5390);
494
- expect(orders === null || orders === void 0 ? void 0 : orders.models[4].physicalAddress.id).toEqual(7608);
495
- expect(orders === null || orders === void 0 ? void 0 : orders.models[4].lineItems.models.length).toEqual(1);
496
- expect(orders === null || orders === void 0 ? void 0 : orders.models[4].lineItems.models[0].id).toEqual(16900);
497
- expect(orders === null || orders === void 0 ? void 0 : orders.models[4].lineItems.models[0].productVariant.id).toEqual(363);
498
- expect(orders === null || orders === void 0 ? void 0 : orders.models[4].lineItems.models[0].productVariant.product.id).toEqual(5);
499
- expect(orders === null || orders === void 0 ? void 0 : orders.models[4].lineItems.models[0].productVariant.size.id).toEqual(8);
500
- expect(orders === null || orders === void 0 ? void 0 : orders.models[4].lineItems.models[0].productVariant.color.id).toEqual(12);
501
- expect(orders === null || orders === void 0 ? void 0 : orders.models[4].lineItems.models[0].productVariant.gender.id).toEqual(1);
502
- expect(orders === null || orders === void 0 ? void 0 : orders.models[4].lineItems.models[0].productVariant.productVariantImages.models.length).toEqual(1);
503
- expect(orders === null || orders === void 0 ? void 0 : orders.models[4].lineItems.models[0].productVariant.productVariantImages.models[0].id).toEqual(829);
594
+ describe('createOneFromDatabase', () => {
595
+ test('reduces to one', () => {
596
+ const core = (0, core_1.createCore)({ entities: entities_1.entities });
597
+ const order = core.createOneFromDatabase(one);
598
+ expect(order instanceof entities_1.entities[0].Model).toBe(true);
599
+ });
600
+ test('throws when less than one', () => {
601
+ const core = (0, core_1.createCore)({ entities: entities_2.entities });
602
+ expect(() => core.createOneFromDatabase([])).toThrow();
603
+ });
604
+ test('throws when more than one', () => {
605
+ const core = (0, core_1.createCore)({ entities: entities_2.entities });
606
+ expect(() => core.createOneFromDatabase(three)).toThrow();
607
+ });
504
608
  });
505
- // Issue occcurs in nestClump
506
- // Problem from early returning not logging bo so parent hierarcy was missing it
507
- test('createFromDatabase 11', () => {
508
- const core = (0, core_1.createCore)({ entities: entities_3.entities });
509
- let orders;
510
- try {
511
- // This failed when the bug was present
512
- orders = core.createFromDatabase(eleven);
513
- }
514
- catch (e) {
515
- expect(e).not.toBeDefined();
516
- }
517
- expect(orders).toBeDefined();
609
+ describe('createOneOrNoneFromDatabase', () => {
610
+ test('reduces to one', () => {
611
+ const core = (0, core_1.createCore)({ entities: entities_1.entities });
612
+ const order = core.createOneOrNoneFromDatabase(one);
613
+ expect(order instanceof entities_1.entities[0].Model).toBe(true);
614
+ });
615
+ test('returns undefined when less than one', () => {
616
+ const core = (0, core_1.createCore)({ entities: entities_2.entities });
617
+ expect(core.createOneOrNoneFromDatabase([])).toEqual(void 0);
618
+ });
619
+ test('throws when more than one', () => {
620
+ const core = (0, core_1.createCore)({ entities: entities_2.entities });
621
+ expect(() => core.createOneOrNoneFromDatabase(three)).toThrow();
622
+ });
518
623
  });
519
- // Issue occcurs in nestClump
520
- // Problem when a table references another model twice (two columns)
521
- test('createFromDatabase 12', () => {
522
- const core = (0, core_1.createCore)({ entities: entities_7.entities });
523
- let prompt;
524
- try {
525
- // This failed when the bug was present
526
- prompt = core.createFromDatabase(twelve);
527
- }
528
- catch (e) {
529
- expect(e).not.toBeDefined();
530
- }
531
- expect(prompt).toBeDefined();
532
- // Ideally the below should work
533
- // expect(prompt.fromMember.id).toEqual(1);
624
+ describe('createManyFromDatabase', () => {
625
+ test('one result', () => {
626
+ const core = (0, core_1.createCore)({ entities: entities_1.entities });
627
+ const orders = core.createManyFromDatabase(one);
628
+ expect(orders instanceof entities_1.entities[0].Collection).toBe(true);
629
+ expect(Array.isArray(orders.models)).toBe(true);
630
+ expect(orders.models.length).toEqual(1);
631
+ });
632
+ test('throws when less than one', () => {
633
+ const core = (0, core_1.createCore)({ entities: entities_2.entities });
634
+ expect(() => core.createManyFromDatabase([])).toThrow();
635
+ });
636
+ test('more than one', () => {
637
+ const core = (0, core_1.createCore)({ entities: entities_2.entities });
638
+ const articles = core.createManyFromDatabase(three);
639
+ expect(articles instanceof entities_2.entities[0].Collection).toBe(true);
640
+ expect(Array.isArray(articles.models)).toBe(true);
641
+ expect(articles.models.length).toEqual(2);
642
+ });
534
643
  });
535
- // Issue occcurs in nestClump
536
- // Problem when a table has records that are supposed to nest under root
537
- // but nest under other stuff below it instead
538
- // Member
539
- // Recommendations [1]
540
- // Brand
541
- // Recommendations [1]
542
- // Passion
543
- // Recommendations [2]
544
- // -- instead of correct --
545
- // Member
546
- // Recommendations[4]
547
- // Brand
548
- // Passion
549
- test('createFromDatabase 13', () => {
550
- const core = (0, core_1.createCore)({ entities: entities_8.entities });
551
- const members = core.createFromDatabase(thirteen);
552
- const member = members === null || members === void 0 ? void 0 : members.models[0];
553
- expect(member === null || member === void 0 ? void 0 : member.recommendations.models.length).toEqual(4);
554
- expect(member === null || member === void 0 ? void 0 : member.recommendations.models[0].brand.id).toEqual(2);
555
- expect(member === null || member === void 0 ? void 0 : member.recommendations.models[0].product.id).toEqual(7);
556
- expect(member === null || member === void 0 ? void 0 : member.recommendations.models[0].category.id).toEqual(1);
557
- expect(member === null || member === void 0 ? void 0 : member.recommendations.models[0].recommendationAudiences.models[0].audience.id).toEqual(1);
558
- expect(member === null || member === void 0 ? void 0 : member.recommendations.models[1].brand.id).toEqual(2);
559
- expect(member === null || member === void 0 ? void 0 : member.recommendations.models[1].product.id).toEqual(1);
560
- expect(member === null || member === void 0 ? void 0 : member.recommendations.models[1].category.id).toEqual(2);
561
- expect(member === null || member === void 0 ? void 0 : member.recommendations.models[1].recommendationAudiences.models[0].audience.id).toEqual(1);
562
- expect(member === null || member === void 0 ? void 0 : member.recommendations.models[2].brand.id).toEqual(3);
563
- expect(member === null || member === void 0 ? void 0 : member.recommendations.models[2].product.id).toEqual(27);
564
- expect(member === null || member === void 0 ? void 0 : member.recommendations.models[2].category.id).toEqual(3);
565
- expect(member === null || member === void 0 ? void 0 : member.recommendations.models[2].recommendationAudiences.models[0].audience.id).toEqual(1);
566
- expect(member === null || member === void 0 ? void 0 : member.recommendations.models[3].brand.id).toEqual(6);
567
- expect(member === null || member === void 0 ? void 0 : member.recommendations.models[3].product.id).toEqual(75);
568
- expect(member === null || member === void 0 ? void 0 : member.recommendations.models[3].category.id).toEqual(4);
569
- expect(member === null || member === void 0 ? void 0 : member.recommendations.models[3].recommendationAudiences.models[0].audience.id).toEqual(1);
644
+ describe('createAnyFromDatabase', () => {
645
+ test('one result', () => {
646
+ const core = (0, core_1.createCore)({ entities: entities_1.entities });
647
+ const orders = core.createAnyFromDatabase(one, entities_1.entities[0].Model);
648
+ expect(orders instanceof entities_1.entities[0].Collection).toBe(true);
649
+ expect(Array.isArray(orders.models)).toBe(true);
650
+ expect(orders.models.length).toEqual(1);
651
+ });
652
+ test('less than one using table name', () => {
653
+ const core = (0, core_1.createCore)({ entities: entities_2.entities });
654
+ const articles = core.createAnyFromDatabase([], entities_2.entities[0].tableName);
655
+ expect(articles instanceof entities_2.entities[0].Collection).toBe(true);
656
+ expect(Array.isArray(articles.models)).toBe(true);
657
+ expect(articles.models.length).toEqual(0);
658
+ });
659
+ test('less than one using model class', () => {
660
+ const core = (0, core_1.createCore)({ entities: entities_2.entities });
661
+ const articles = core.createAnyFromDatabase([], entities_2.entities[0].Model);
662
+ expect(articles instanceof entities_2.entities[0].Collection).toBe(true);
663
+ expect(Array.isArray(articles.models)).toBe(true);
664
+ expect(articles.models.length).toEqual(0);
665
+ });
666
+ test('more than one', () => {
667
+ const core = (0, core_1.createCore)({ entities: entities_2.entities });
668
+ const articles = core.createAnyFromDatabase(three, entities_2.entities[0].Model);
669
+ expect(articles instanceof entities_2.entities[0].Collection).toBe(true);
670
+ expect(Array.isArray(articles.models)).toBe(true);
671
+ expect(articles.models.length).toEqual(2);
672
+ });
570
673
  });
571
- test('orm.tables', () => {
674
+ test('tables', () => {
572
675
  const core = (0, core_1.createCore)({ entities: entities_1.entities });
573
676
  expect(Object.keys(core.tables).length).toEqual(5);
574
677
  expect(core.tables.utmSource.columns).toEqual('"utm_source".id as "utm_source#id", "utm_source".value as "utm_source#value", "utm_source".label as "utm_source#label", "utm_source".internal as "utm_source#internal"');