pure-orm 4.0.0 → 4.0.1

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