@kaspernj/api-maker 1.0.446 → 1.0.448

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 (357) hide show
  1. package/{.eslintrc.cjs → .eslintrc.js} +4 -0
  2. package/README.md +35 -0
  3. package/android/build.gradle +43 -0
  4. package/android/src/main/AndroidManifest.xml +2 -0
  5. package/android/src/main/java/expo/modules/api_maker/ApiMakerModule.kt +50 -0
  6. package/android/src/main/java/expo/modules/api_maker/ApiMakerView.kt +30 -0
  7. package/build/api.js +120 -0
  8. package/build/attribute-not-loaded-error.js +2 -0
  9. package/build/base-component.js +5 -0
  10. package/build/base-error.js +33 -0
  11. package/build/base-model/attribute.js +25 -0
  12. package/build/base-model/column.js +11 -0
  13. package/build/base-model/reflection.js +14 -0
  14. package/build/base-model/scope.js +11 -0
  15. package/build/base-model.js +828 -0
  16. package/build/bootstrap/attribute-row/index.js +105 -0
  17. package/build/bootstrap/attribute-rows.js +31 -0
  18. package/build/bootstrap/card.js +138 -0
  19. package/build/bootstrap/checkbox.js +97 -0
  20. package/build/bootstrap/checkboxes.js +183 -0
  21. package/build/bootstrap/index.js +2 -0
  22. package/build/bootstrap/input.js +128 -0
  23. package/build/bootstrap/invalid-feedback.js +27 -0
  24. package/build/bootstrap/paginate.js +150 -0
  25. package/build/bootstrap/radio-buttons.js +72 -0
  26. package/build/bootstrap/select.js +88 -0
  27. package/build/bootstrap/sort-link.js +130 -0
  28. package/build/cable-connection-pool.js +128 -0
  29. package/build/cable-subscription-pool.js +207 -0
  30. package/build/cable-subscription.js +21 -0
  31. package/build/cache-key-generator.js +81 -0
  32. package/build/can-can.js +134 -0
  33. package/build/channels-consumer.js +3 -0
  34. package/build/collection-loader.js +48 -0
  35. package/build/collection.js +279 -0
  36. package/build/command-submit-data.js +81 -0
  37. package/build/commands-pool.js +195 -0
  38. package/build/compose.js +9 -0
  39. package/build/config.js +53 -0
  40. package/build/custom-error.js +5 -0
  41. package/build/data-set-to-attributes.js +10 -0
  42. package/build/deserializer.js +56 -0
  43. package/build/destroy-error.js +5 -0
  44. package/build/devise.js +109 -0
  45. package/build/draggable-sort/controller.js +136 -0
  46. package/build/draggable-sort/index.js +114 -0
  47. package/build/draggable-sort/item.js +188 -0
  48. package/build/error-logger.js +101 -0
  49. package/build/error-messages.js +13 -0
  50. package/build/event-connection.js +32 -0
  51. package/build/event-model-class.js +24 -0
  52. package/build/events.js +5 -0
  53. package/build/form.js +83 -0
  54. package/build/index.js +3 -0
  55. package/build/inputs/attachment.js +121 -0
  56. package/build/inputs/auto-submit.js +36 -0
  57. package/build/inputs/checkbox.js +145 -0
  58. package/build/inputs/checkboxes.js +111 -0
  59. package/build/inputs/id-for-component.js +15 -0
  60. package/build/inputs/input-wrapper.js +18 -0
  61. package/build/inputs/input.js +230 -0
  62. package/build/inputs/money.js +179 -0
  63. package/build/inputs/name-for-component.js +13 -0
  64. package/build/inputs/select.js +92 -0
  65. package/build/instance-of-class-name.js +23 -0
  66. package/build/key-value-store.js +53 -0
  67. package/build/link.js +68 -0
  68. package/build/logger.js +30 -0
  69. package/build/modal.js +37 -0
  70. package/build/model-class-require.js +13 -0
  71. package/build/model-events.js +30 -0
  72. package/build/model-name.js +28 -0
  73. package/build/model-prop-type.js +101 -0
  74. package/build/model-recipes-loader.js +32 -0
  75. package/build/model-recipes-model-loader.js +357 -0
  76. package/build/models-response-reader.js +40 -0
  77. package/build/models.js +8 -0
  78. package/build/money-formatter.js +77 -0
  79. package/build/not-loaded-error.js +2 -0
  80. package/build/params.js +60 -0
  81. package/build/preloaded.js +38 -0
  82. package/build/resize-observer.js +11 -0
  83. package/build/result.js +13 -0
  84. package/build/router/route.js +262 -0
  85. package/build/router/switch.js +72 -0
  86. package/build/router.js +57 -0
  87. package/build/routes-native.js +202 -0
  88. package/build/routes.js +50 -0
  89. package/build/run-last.js +35 -0
  90. package/build/serializer.js +63 -0
  91. package/build/services.js +20 -0
  92. package/build/session-status-updater.js +126 -0
  93. package/build/source-maps-loader.js +171 -0
  94. package/build/super-admin/config-reader.js +84 -0
  95. package/build/super-admin/edit-page/edit-attribute-checkbox.js +85 -0
  96. package/build/super-admin/edit-page/edit-attribute-content.js +54 -0
  97. package/build/super-admin/edit-page/edit-attribute-input.js +79 -0
  98. package/build/super-admin/edit-page/edit-attribute.js +76 -0
  99. package/build/super-admin/edit-page.js +120 -0
  100. package/build/super-admin/has-edit-config.js +12 -0
  101. package/build/super-admin/index-page.js +24 -0
  102. package/build/super-admin/index.js +180 -0
  103. package/build/super-admin/layout/header/index.js +151 -0
  104. package/build/super-admin/layout/index.js +109 -0
  105. package/build/super-admin/layout/menu/index.js +93 -0
  106. package/build/super-admin/layout/menu/menu-content.js +40 -0
  107. package/build/super-admin/layout/menu/menu-item.js +83 -0
  108. package/build/super-admin/layout/no-access.js +25 -0
  109. package/build/super-admin/model-class-table.js +61 -0
  110. package/build/super-admin/models.js +8 -0
  111. package/build/super-admin/show-nav.js +49 -0
  112. package/build/super-admin/show-page/belongs-to-attribute-row.js +28 -0
  113. package/build/super-admin/show-page/index.js +141 -0
  114. package/build/super-admin/show-reflection-actions.js +47 -0
  115. package/build/super-admin/show-reflection-link.js +46 -0
  116. package/build/super-admin/show-reflection-page.js +47 -0
  117. package/build/table/column-content.js +112 -0
  118. package/build/table/column-identifier.js +18 -0
  119. package/build/table/column-visible.js +7 -0
  120. package/build/table/components/column.js +20 -0
  121. package/build/table/components/flat-list.js +20 -0
  122. package/build/table/components/header.js +25 -0
  123. package/build/table/components/row.js +25 -0
  124. package/build/table/filters/attribute-element.js +43 -0
  125. package/build/table/filters/filter-form.js +392 -0
  126. package/build/table/filters/filter.js +89 -0
  127. package/build/table/filters/index.js +182 -0
  128. package/build/table/filters/load-search-modal.js +174 -0
  129. package/build/table/filters/reflection-element.js +36 -0
  130. package/build/table/filters/save-search-modal.js +86 -0
  131. package/build/table/filters/scope-element.js +41 -0
  132. package/build/table/header-column-content.js +67 -0
  133. package/build/table/header-column.js +144 -0
  134. package/build/table/header-select.js +104 -0
  135. package/build/table/model-callback-args.js +10 -0
  136. package/build/table/model-column.js +87 -0
  137. package/build/table/model-row.js +179 -0
  138. package/build/table/select-calculator.js +63 -0
  139. package/build/table/settings/column-row.js +97 -0
  140. package/build/table/settings/download-action.js +78 -0
  141. package/build/table/settings/index.js +92 -0
  142. package/build/table/table-settings.js +219 -0
  143. package/build/table/table.js +972 -0
  144. package/build/table/use-sorting.js +34 -0
  145. package/build/table/widths.js +75 -0
  146. package/build/table/worker-plugins-check-all-checkbox.js +125 -0
  147. package/build/table/worker-plugins-checkbox.js +115 -0
  148. package/build/translated-attributes.js +10 -0
  149. package/build/translated-collections.js +11 -0
  150. package/build/updated-attribute.js +76 -0
  151. package/build/url-encode.js +15 -0
  152. package/build/use-breakpoint.js +44 -0
  153. package/build/use-can-can.js +55 -0
  154. package/build/use-collection.js +225 -0
  155. package/build/use-created-event.js +52 -0
  156. package/build/use-current-user.js +73 -0
  157. package/build/use-destroyed-event.js +60 -0
  158. package/build/use-event-emitter.js +13 -0
  159. package/build/use-event-listener.js +16 -0
  160. package/build/use-input.js +140 -0
  161. package/build/use-model-event.js +60 -0
  162. package/build/use-model.js +169 -0
  163. package/build/use-resize-observer.js +23 -0
  164. package/build/use-router.js +102 -0
  165. package/build/use-screen-layout.js +39 -0
  166. package/build/use-updated-event.js +60 -0
  167. package/build/use-validation-errors.js +30 -0
  168. package/build/utils/card.js +51 -0
  169. package/build/utils/checkbox.js +48 -0
  170. package/build/utils/default-style.js +18 -0
  171. package/build/utils/modal.js +61 -0
  172. package/build/utils/text.js +18 -0
  173. package/build/validation-error.js +28 -0
  174. package/build/validation-errors.js +98 -0
  175. package/build/with-collection.js +13 -0
  176. package/build/with-current-user.js +9 -0
  177. package/build/with-model.js +14 -0
  178. package/build/with-router.js +21 -0
  179. package/expo-module.config.json +17 -0
  180. package/ios/ApiMaker.podspec +29 -0
  181. package/ios/ApiMakerModule.swift +48 -0
  182. package/ios/ApiMakerView.swift +38 -0
  183. package/package.json +35 -16
  184. package/src/{api.mjs → api.js} +5 -5
  185. package/src/{base-error.mjs → base-error.js} +1 -1
  186. package/src/base-model/{attribute.mjs → attribute.js} +1 -1
  187. package/src/base-model/{reflection.mjs → reflection.js} +1 -1
  188. package/src/{base-model.mjs → base-model.js} +14 -14
  189. package/src/bootstrap/attribute-row/index.jsx +2 -2
  190. package/src/bootstrap/attribute-rows.jsx +1 -1
  191. package/src/bootstrap/card.jsx +1 -1
  192. package/src/bootstrap/checkbox.jsx +1 -1
  193. package/src/bootstrap/checkboxes.jsx +1 -1
  194. package/src/bootstrap/input.jsx +1 -1
  195. package/src/bootstrap/paginate.jsx +2 -2
  196. package/src/bootstrap/sort-link.jsx +3 -3
  197. package/src/{cable-connection-pool.mjs → cable-connection-pool.js} +3 -3
  198. package/src/{cable-subscription-pool.mjs → cable-subscription-pool.js} +4 -4
  199. package/src/{cable-subscription.mjs → cable-subscription.js} +1 -1
  200. package/src/{can-can.mjs → can-can.js} +1 -1
  201. package/src/collection-loader.jsx +2 -2
  202. package/src/{collection.mjs → collection.js} +3 -3
  203. package/src/{commands-pool.mjs → commands-pool.js} +11 -11
  204. package/src/{custom-error.mjs → custom-error.js} +1 -1
  205. package/src/{deserializer.mjs → deserializer.js} +2 -2
  206. package/src/{destroy-error.mjs → destroy-error.js} +1 -1
  207. package/src/{devise.mjs → devise.js} +5 -9
  208. package/src/draggable-sort/index.jsx +3 -3
  209. package/src/draggable-sort/item.jsx +2 -2
  210. package/src/{error-logger.mjs → error-logger.js} +1 -1
  211. package/src/event-connection.jsx +1 -1
  212. package/src/event-model-class.jsx +1 -1
  213. package/src/form.jsx +1 -1
  214. package/src/index.js +3 -0
  215. package/src/inputs/attachment.jsx +2 -2
  216. package/src/inputs/checkbox.jsx +7 -6
  217. package/src/inputs/checkboxes.jsx +1 -1
  218. package/src/inputs/input-wrapper.jsx +1 -1
  219. package/src/inputs/input.jsx +8 -7
  220. package/src/inputs/money.jsx +3 -3
  221. package/src/inputs/select.jsx +1 -1
  222. package/src/{key-value-store.mjs → key-value-store.js} +1 -1
  223. package/src/link.jsx +2 -2
  224. package/src/modal.jsx +1 -1
  225. package/src/{model-class-require.mjs → model-class-require.js} +4 -2
  226. package/src/{model-events.mjs → model-events.js} +1 -1
  227. package/src/{model-name.mjs → model-name.js} +1 -1
  228. package/src/{model-recipes-loader.mjs → model-recipes-loader.js} +1 -1
  229. package/src/{model-recipes-model-loader.mjs → model-recipes-model-loader.js} +2 -2
  230. package/src/{models-response-reader.mjs → models-response-reader.js} +2 -2
  231. package/src/models.js +7 -0
  232. package/src/{models.mjs.erb → models.js.erb} +1 -1
  233. package/src/{params.mjs → params.js} +2 -2
  234. package/src/{preloaded.mjs → preloaded.js} +1 -1
  235. package/src/resize-observer.jsx +1 -1
  236. package/src/router/route.jsx +1 -1
  237. package/src/router/switch.jsx +1 -1
  238. package/src/router.jsx +1 -1
  239. package/src/{routes-native.mjs → routes-native.js} +1 -1
  240. package/src/{services.mjs → services.js} +1 -1
  241. package/src/{session-status-updater.mjs → session-status-updater.js} +3 -3
  242. package/src/{source-maps-loader.mjs → source-maps-loader.js} +1 -1
  243. package/src/super-admin/edit-page/edit-attribute-checkbox.jsx +1 -1
  244. package/src/super-admin/edit-page/edit-attribute-content.jsx +1 -1
  245. package/src/super-admin/edit-page/edit-attribute-input.jsx +1 -1
  246. package/src/super-admin/edit-page/edit-attribute.jsx +1 -1
  247. package/src/super-admin/edit-page.jsx +2 -2
  248. package/src/super-admin/has-edit-config.js +1 -1
  249. package/src/super-admin/index-page.jsx +1 -1
  250. package/src/super-admin/index.jsx +7 -7
  251. package/src/super-admin/layout/header/index.jsx +2 -2
  252. package/src/super-admin/layout/index.jsx +3 -3
  253. package/src/super-admin/layout/menu/index.jsx +3 -3
  254. package/src/super-admin/layout/menu/menu-content.jsx +2 -2
  255. package/src/super-admin/layout/menu/{menu-item/index.jsx → menu-item.jsx} +5 -6
  256. package/src/super-admin/layout/no-access.jsx +2 -2
  257. package/src/super-admin/model-class-table.jsx +3 -3
  258. package/src/super-admin/models.js +1 -1
  259. package/src/super-admin/show-nav.jsx +2 -2
  260. package/src/super-admin/show-page/belongs-to-attribute-row.jsx +1 -1
  261. package/src/super-admin/show-page/index.jsx +2 -2
  262. package/src/super-admin/show-reflection-actions.jsx +1 -1
  263. package/src/super-admin/show-reflection-link.jsx +1 -1
  264. package/src/super-admin/show-reflection-page.jsx +1 -1
  265. package/src/table/column-content.jsx +1 -1
  266. package/src/table/filters/filter-form.jsx +1 -1
  267. package/src/table/filters/index.jsx +5 -3
  268. package/src/table/filters/load-search-modal.jsx +6 -4
  269. package/src/table/filters/save-search-modal.jsx +4 -4
  270. package/src/table/header-select.jsx +1 -1
  271. package/src/table/model-column.jsx +1 -1
  272. package/src/table/model-row.jsx +2 -2
  273. package/src/table/{select-calculator.mjs → select-calculator.js} +1 -1
  274. package/src/table/settings/column-row.jsx +2 -2
  275. package/src/table/settings/download-action.jsx +3 -3
  276. package/src/table/settings/index.jsx +3 -3
  277. package/src/table/table-settings.js +5 -4
  278. package/src/table/table.jsx +8 -8
  279. package/src/table/{use-sorting.mjs → use-sorting.js} +1 -1
  280. package/src/table/worker-plugins-check-all-checkbox.jsx +2 -2
  281. package/src/table/worker-plugins-checkbox.jsx +2 -2
  282. package/src/{translated-collections.mjs → translated-collections.js} +1 -1
  283. package/src/updated-attribute.jsx +1 -1
  284. package/src/{use-breakpoint.mjs → use-breakpoint.js} +2 -2
  285. package/src/use-can-can.js +55 -0
  286. package/src/{use-collection.mjs → use-collection.js} +4 -4
  287. package/src/{use-created-event.mjs → use-created-event.js} +2 -2
  288. package/src/{use-current-user.mjs → use-current-user.js} +6 -5
  289. package/src/{use-destroyed-event.mjs → use-destroyed-event.js} +2 -2
  290. package/src/{use-input.mjs → use-input.js} +5 -5
  291. package/src/use-model-event.js +2 -2
  292. package/src/{use-model.mjs → use-model.js} +4 -4
  293. package/src/{use-resize-observer.mjs → use-resize-observer.js} +1 -1
  294. package/src/use-router.jsx +2 -2
  295. package/src/{use-updated-event.mjs → use-updated-event.js} +2 -2
  296. package/src/{use-validation-errors.mjs → use-validation-errors.js} +3 -3
  297. package/src/utils/checkbox.jsx +2 -2
  298. package/src/{validation-error.mjs → validation-error.js} +1 -1
  299. package/src/{validation-errors.mjs → validation-errors.js} +1 -1
  300. package/src/with-current-user.jsx +1 -1
  301. package/src/with-model.jsx +1 -1
  302. package/__tests__/base-model.test.mjs +0 -71
  303. package/__tests__/cable-connection-pool.test.mjs +0 -227
  304. package/__tests__/cable-subscription-pool.test.mjs +0 -27
  305. package/__tests__/can-can.test.mjs +0 -34
  306. package/__tests__/collection.test.mjs +0 -51
  307. package/__tests__/custom-error.test.mjs +0 -13
  308. package/__tests__/model-name.test.mjs +0 -34
  309. package/__tests__/model-prop-type.test.mjs +0 -113
  310. package/__tests__/params.test.mjs +0 -40
  311. package/__tests__/routes-native.test.mjs +0 -104
  312. package/__tests__/routes.test.mjs +0 -47
  313. package/__tests__/serializer.test.mjs +0 -30
  314. package/__tests__/support/task.mjs +0 -27
  315. package/__tests__/support/user.mjs +0 -32
  316. package/index.js +0 -1
  317. package/jest.config.js +0 -9
  318. package/src/event-created.jsx +0 -12
  319. package/src/event-destroyed.jsx +0 -25
  320. package/src/event-emitter-listener.jsx +0 -10
  321. package/src/event-listener.jsx +0 -25
  322. package/src/event-updated.jsx +0 -27
  323. package/src/super-admin/layout/menu/menu-item/style.scss +0 -10
  324. package/src/use-can-can.mjs +0 -48
  325. package/src/with-can-can.jsx +0 -12
  326. package/webpack.config.js +0 -15
  327. /package/src/{attribute-not-loaded-error.mjs → attribute-not-loaded-error.js} +0 -0
  328. /package/src/base-model/{column.mjs → column.js} +0 -0
  329. /package/src/base-model/{scope.mjs → scope.js} +0 -0
  330. /package/src/{cache-key-generator.mjs → cache-key-generator.js} +0 -0
  331. /package/src/{channels-consumer.mjs → channels-consumer.js} +0 -0
  332. /package/src/{command-submit-data.mjs → command-submit-data.js} +0 -0
  333. /package/src/{config.mjs → config.js} +0 -0
  334. /package/src/{data-set-to-attributes.mjs → data-set-to-attributes.js} +0 -0
  335. /package/src/draggable-sort/{controller.mjs → controller.js} +0 -0
  336. /package/src/{error-messages.mjs → error-messages.js} +0 -0
  337. /package/src/{events.mjs → events.js} +0 -0
  338. /package/src/inputs/{auto-submit.mjs → auto-submit.js} +0 -0
  339. /package/src/inputs/{id-for-component.mjs → id-for-component.js} +0 -0
  340. /package/src/inputs/{name-for-component.mjs → name-for-component.js} +0 -0
  341. /package/src/{instance-of-class-name.mjs → instance-of-class-name.js} +0 -0
  342. /package/src/{logger.mjs → logger.js} +0 -0
  343. /package/src/{model-prop-type.mjs → model-prop-type.js} +0 -0
  344. /package/src/{money-formatter.mjs → money-formatter.js} +0 -0
  345. /package/src/{not-loaded-error.mjs → not-loaded-error.js} +0 -0
  346. /package/src/{result.mjs → result.js} +0 -0
  347. /package/src/{routes.mjs → routes.js} +0 -0
  348. /package/src/{run-last.mjs → run-last.js} +0 -0
  349. /package/src/{serializer.mjs → serializer.js} +0 -0
  350. /package/src/table/{column-identifier.mjs → column-identifier.js} +0 -0
  351. /package/src/table/{column-visible.mjs → column-visible.js} +0 -0
  352. /package/src/table/{model-callback-args.mjs → model-callback-args.js} +0 -0
  353. /package/src/{translated-collections-data.mjs.erb → translated-collections-data.js.erb} +0 -0
  354. /package/src/{url-encode.mjs → url-encode.js} +0 -0
  355. /package/src/{use-event-emitter.mjs → use-event-emitter.js} +0 -0
  356. /package/src/{use-event-listener.mjs → use-event-listener.js} +0 -0
  357. /package/src/{use-screen-layout.mjs → use-screen-layout.js} +0 -0
@@ -1,71 +0,0 @@
1
- import BaseModel from "../src/base-model.mjs"
2
- import CustomError from "../src/custom-error.mjs"
3
- import {jest} from "@jest/globals"
4
- import {JSDOM} from "jsdom"
5
- import ValidationError from "../src/validation-error.mjs"
6
- import User from "./support/user.mjs"
7
-
8
- jest.mock("@rails/actioncable", () => ({
9
- createConsumer: () => ({})
10
- }))
11
-
12
- const {window} = new JSDOM()
13
- const document = window.document
14
-
15
- describe("BaseModel", () => {
16
- describe("identifierKey", () => {
17
- it("returns the id when persisted", () => {
18
- const user = new User({a: {id: 5}})
19
-
20
- expect(user.identifierKey()).toEqual(5)
21
- })
22
-
23
- it("returns the unique key when new record", () => {
24
- const user = new User({isNewRecord: true})
25
-
26
- user.uniqueKey = () => 45
27
-
28
- expect(user.identifierKey()).toEqual(45)
29
- })
30
- })
31
-
32
- describe("update", () => {
33
- it("aborts if no changes", async () => {
34
- const model = new BaseModel()
35
-
36
- // This will fail because of missing setup if it doesn't abort.
37
- const response = await model.update({})
38
-
39
- // There will be extra objects in the hash if it actually calls the backend.
40
- expect(response).toEqual({model})
41
- })
42
- })
43
-
44
- describe("parseValidationErrors", () => {
45
- const error = new CustomError("Some validation error", {
46
- response: {
47
- validation_errors: []
48
- }
49
- })
50
- const form = document.createElement("form")
51
- const model = new BaseModel()
52
- const dispatchEventSpy = jest.spyOn(form, "dispatchEvent").mockImplementation(() => "asd")
53
- const newCustomEventSpy = jest.spyOn(BaseModel, "newCustomEvent").mockImplementation(() => "asd")
54
-
55
- it("throws the validation errors if no options are given", () => {
56
- expect(() => BaseModel.parseValidationErrors({error, model})).toThrow(ValidationError)
57
- })
58
-
59
- it("throws the validation errors and dispatches an event to the form", () => {
60
- expect(() => BaseModel.parseValidationErrors({error, model, options: {form}})).toThrow(ValidationError)
61
- expect(dispatchEventSpy).toHaveBeenCalled()
62
- expect(newCustomEventSpy).toHaveBeenCalled()
63
- })
64
-
65
- it("doesnt throw validation errors if disabled", () => {
66
- BaseModel.parseValidationErrors({error, model, options: {throwValidationError: false}})
67
- expect(dispatchEventSpy).toHaveBeenCalled()
68
- expect(newCustomEventSpy).toHaveBeenCalled()
69
- })
70
- })
71
- })
@@ -1,227 +0,0 @@
1
- import CableConnectionPool from "../src/cable-connection-pool.mjs"
2
- import CableSubscriptionPool from "../src/cable-subscription-pool.mjs"
3
- import {digg} from "diggerize"
4
- import {jest} from "@jest/globals"
5
-
6
- jest.mock("@rails/actioncable", () => ({
7
- createConsumer: () => ({})
8
- }))
9
-
10
- describe("CableConnectionPool", () => {
11
- describe("connectCreated", () => {
12
- it("creates a new create event and connects", () => {
13
- const cableConnectionPool = new CableConnectionPool()
14
-
15
- cableConnectionPool.scheduleConnectUpcoming = function () {
16
- const subscriptionData = this.upcomingSubscriptionData
17
- const subscriptions = this.upcomingSubscriptions
18
-
19
- this.upcomingSubscriptionData = {}
20
- this.upcomingSubscriptions = {}
21
-
22
- const cableSubscriptionPool = {subscriptionData, subscriptions}
23
-
24
- this.cableSubscriptionPools.push(cableSubscriptionPool)
25
- }
26
- cableConnectionPool.cableSubscriptionPools = []
27
- cableConnectionPool.connectCreated("Contact", () => console.log("Callback"))
28
-
29
- expect(cableConnectionPool.cableSubscriptionPools.length).toEqual(1)
30
-
31
- const newCableSubscriptionPool = digg(cableConnectionPool, "cableSubscriptionPools", 0)
32
- const subscriptions = digg(newCableSubscriptionPool, "subscriptions", "Contact", "creates")
33
-
34
- expect(subscriptions.length).toEqual(1)
35
- })
36
- })
37
-
38
- describe("connectDestroyed", () => {
39
- it("creates a new destroy event and connects", () => {
40
- const cableConnectionPool = new CableConnectionPool()
41
- const cableSubscriptionPool = new CableSubscriptionPool()
42
-
43
- cableSubscriptionPool.subscriptions = {
44
- Contact: {
45
- updates: {
46
- modelId: []
47
- }
48
- }
49
- }
50
-
51
- cableConnectionPool.scheduleConnectUpcoming = function () {
52
- const subscriptionData = this.upcomingSubscriptionData
53
- const subscriptions = this.upcomingSubscriptions
54
-
55
- this.upcomingSubscriptionData = {}
56
- this.upcomingSubscriptions = {}
57
-
58
- const cableSubscriptionPool = {subscriptionData, subscriptions}
59
-
60
- this.cableSubscriptionPools.push(cableSubscriptionPool)
61
- }
62
- cableConnectionPool.cableSubscriptionPools = [cableSubscriptionPool]
63
- cableConnectionPool.connectDestroyed("Contact", "modelId", () => { })
64
-
65
- expect(cableConnectionPool.cableSubscriptionPools.length).toEqual(2)
66
-
67
- const newCableSubscriptionPool = cableConnectionPool.cableSubscriptionPools[1]
68
- const subscriptions = digg(newCableSubscriptionPool, "subscriptions", "Contact", "destroys", "modelId")
69
-
70
- expect(subscriptions.length).toEqual(1)
71
- })
72
-
73
- it("connects to an existing destroy event", () => {
74
- let connectedUnsubscribeEvent = false
75
-
76
- const cableConnectionPool = new CableConnectionPool()
77
- const cableSubscriptionPool = new CableSubscriptionPool()
78
-
79
- cableSubscriptionPool.connected = true
80
- cableSubscriptionPool.connectUnsubscriptionForSubscription = function () {
81
- connectedUnsubscribeEvent = true
82
- }
83
- cableSubscriptionPool.subscriptions = {
84
- Contact: {
85
- destroys: {
86
- modelId: []
87
- }
88
- }
89
- }
90
-
91
- cableConnectionPool.connectUpcoming = () => console.log("connectUpcoming")
92
- cableConnectionPool.cableSubscriptionPools = [cableSubscriptionPool]
93
- cableConnectionPool.connectDestroyed("Contact", "modelId", () => { })
94
-
95
- const subscriptions = digg(cableSubscriptionPool, "subscriptions", "Contact", "destroys", "modelId")
96
-
97
- expect(subscriptions.length).toEqual(1)
98
- expect(connectedUnsubscribeEvent).toEqual(true)
99
- })
100
-
101
- it("doesnt connect to an existing destroy event that is disconnected", () => {
102
- const cableConnectionPool = new CableConnectionPool()
103
- const cableSubscriptionPool = new CableSubscriptionPool()
104
-
105
- cableSubscriptionPool.subscriptions = {
106
- Contact: {
107
- destroys: {
108
- modelId: []
109
- }
110
- }
111
- }
112
-
113
- cableConnectionPool.connected = false
114
- cableConnectionPool.connectUpcoming = function () {
115
- const subscriptionData = this.upcomingSubscriptionData
116
- const subscriptions = this.upcomingSubscriptions
117
-
118
- this.upcomingSubscriptionData = {}
119
- this.upcomingSubscriptions = {}
120
-
121
- const cableSubscriptionPool = {subscriptionData, subscriptions}
122
-
123
- this.cableSubscriptionPools.push(cableSubscriptionPool)
124
- }
125
- cableConnectionPool.cableSubscriptionPools = [cableSubscriptionPool]
126
- cableConnectionPool.scheduleConnectUpcoming = () => cableConnectionPool.connectUpcoming()
127
- cableConnectionPool.connectDestroyed("Contact", "modelId", () => { })
128
-
129
- const subscriptions = digg(cableSubscriptionPool, "subscriptions", "Contact", "destroys", "modelId")
130
-
131
- expect(subscriptions.length).toEqual(0)
132
- expect(cableConnectionPool.cableSubscriptionPools.length).toEqual(2)
133
- })
134
- })
135
-
136
- describe("connectUpdate", () => {
137
- it("creates a new update event and connects", () => {
138
- const cableConnectionPool = new CableConnectionPool()
139
- const cableSubscriptionPool = new CableSubscriptionPool()
140
-
141
- cableSubscriptionPool.subscriptions = {
142
- Contact: {
143
- destroys: {
144
- modelId: []
145
- }
146
- }
147
- }
148
-
149
- cableConnectionPool.scheduleConnectUpcoming = function () {
150
- const subscriptionData = this.upcomingSubscriptionData
151
- const subscriptions = this.upcomingSubscriptions
152
-
153
- this.upcomingSubscriptionData = {}
154
- this.upcomingSubscriptions = {}
155
-
156
- const cableSubscriptionPool = {subscriptionData, subscriptions}
157
-
158
- this.cableSubscriptionPools.push(cableSubscriptionPool)
159
- }
160
- cableConnectionPool.cableSubscriptionPools = [cableSubscriptionPool]
161
- cableConnectionPool.connectUpdate("Contact", "modelId", () => console.log("Update callback"))
162
-
163
- expect(cableConnectionPool.cableSubscriptionPools.length).toEqual(2)
164
-
165
- const newCableSubscriptionPool = cableConnectionPool.cableSubscriptionPools[1]
166
- const subscriptions = digg(newCableSubscriptionPool, "subscriptions", "Contact", "updates", "modelId")
167
-
168
- expect(subscriptions.length).toEqual(1)
169
- })
170
-
171
- it("connects to an existing update event", () => {
172
- let connectedUnsubscribeEvent = false
173
-
174
- const cableConnectionPool = new CableConnectionPool()
175
- const cableSubscriptionPool = new CableSubscriptionPool()
176
-
177
- cableSubscriptionPool.connected = true
178
- cableSubscriptionPool.connectUnsubscriptionForSubscription = function () {
179
- connectedUnsubscribeEvent = true
180
- }
181
- cableSubscriptionPool.subscriptions = {
182
- Contact: {
183
- updates: {
184
- modelId: []
185
- }
186
- }
187
- }
188
-
189
- cableConnectionPool.connectUpcoming = () => console.log("connectUpcoming")
190
- cableConnectionPool.cableSubscriptionPools = [cableSubscriptionPool]
191
- cableConnectionPool.connectUpdate("Contact", "modelId", () => { })
192
-
193
- const subscriptions = digg(cableSubscriptionPool, "subscriptions", "Contact", "updates", "modelId")
194
-
195
- expect(subscriptions.length).toEqual(1)
196
- expect(connectedUnsubscribeEvent).toEqual(true)
197
- })
198
-
199
- it("connects to an existing update event if the model ID is truthy like 1 is", () => {
200
- let connectedUnsubscribeEvent = false
201
-
202
- const cableConnectionPool = new CableConnectionPool()
203
- const cableSubscriptionPool = new CableSubscriptionPool()
204
-
205
- cableSubscriptionPool.connected = true
206
- cableSubscriptionPool.connectUnsubscriptionForSubscription = function () {
207
- connectedUnsubscribeEvent = true
208
- }
209
- cableSubscriptionPool.subscriptions = {
210
- Contact: {
211
- updates: {
212
- 1: []
213
- }
214
- }
215
- }
216
-
217
- cableConnectionPool.connectUpcoming = () => console.log("connectUpcoming")
218
- cableConnectionPool.cableSubscriptionPools = [cableSubscriptionPool]
219
- cableConnectionPool.connectUpdate("Contact", 1, () => console.log("Update callback called"))
220
-
221
- const subscriptions = digg(cableSubscriptionPool, "subscriptions", "Contact", "updates", 1)
222
-
223
- expect(subscriptions.length).toEqual(1)
224
- expect(connectedUnsubscribeEvent).toEqual(true)
225
- })
226
- })
227
- })
@@ -1,27 +0,0 @@
1
- import CableSubscriptionPool from "../src/cable-subscription-pool.mjs"
2
-
3
- jest.mock("@rails/actioncable", () => ({
4
- createConsumer: () => ({})
5
- }))
6
-
7
- describe("CableSubscriptionPool", () => {
8
- describe("onUnsubscribe", () => {
9
- it("unsubscribes from ActionCable", () => {
10
- const cableSubscriptionPool = new CableSubscriptionPool()
11
-
12
- let unsubscribeCalled = false
13
-
14
- cableSubscriptionPool.activeSubscriptions = 1
15
- cableSubscriptionPool.subscription = {
16
- unsubscribe: () => {
17
- unsubscribeCalled = true
18
- }
19
- }
20
- cableSubscriptionPool.onUnsubscribe()
21
-
22
- expect(unsubscribeCalled).toEqual(true)
23
- expect(cableSubscriptionPool.activeSubscriptions).toEqual(0)
24
- expect(cableSubscriptionPool.isConnected()).toEqual(false)
25
- })
26
- })
27
- })
@@ -1,34 +0,0 @@
1
- import CanCan from "../src/can-can.mjs"
2
- import {jest} from "@jest/globals"
3
- import Services from "../src/services.mjs"
4
-
5
- jest.mock("../src/services.mjs")
6
-
7
- describe("CanCan", () => {
8
- const canCan = CanCan.current()
9
-
10
- describe("resetAbilities", () => {
11
- test("that reset abilities and load abilities not have concurrency issues", async () => {
12
- const mockedCurrent = jest.fn().mockReturnValue({
13
- sendRequest: async () => ({abilities: ["loaded"]})
14
- })
15
- Services.current = mockedCurrent
16
-
17
- const loadAbilitiesPromise = canCan.loadAbilities([["user", ["read"]]])
18
- const resetPromise = canCan.resetAbilities()
19
-
20
- await Promise.all([loadAbilitiesPromise, resetPromise])
21
-
22
- expect(canCan.abilities).toEqual([])
23
- })
24
-
25
- it("dispatches an event", async () => {
26
- const eventListener = jest.fn()
27
- canCan.events.addListener("onResetAbilities", eventListener)
28
-
29
- await canCan.resetAbilities()
30
-
31
- expect(eventListener).toHaveBeenCalled()
32
- })
33
- })
34
- })
@@ -1,51 +0,0 @@
1
- import Collection from "../src/collection.mjs"
2
-
3
- describe("Collection", () => {
4
- describe("count", () => {
5
- it("is able to clone the collection and merge count into it without manipulating the original given query", () => {
6
- let collection = new Collection({}, {})
7
-
8
- collection.ransack({name_cont: "Kasper"})
9
-
10
- let countCollection = collection.clone()._merge({count: true})
11
-
12
- expect(collection.queryArgs).toEqual({ransack: {name_cont: "Kasper"}})
13
- expect(countCollection.queryArgs).toEqual({count: true, ransack: {name_cont: "Kasper"}})
14
- })
15
- })
16
-
17
- describe("ransack", () => {
18
- it("handles undefined arguments", () => {
19
- // This can happen if someone does something like this and users_q isn't set:
20
- // query.ransack(params.users_q)
21
-
22
- let collection = new Collection({}, {ransack: {id_eq: 5}})
23
-
24
- collection.ransack(undefined)
25
-
26
- expect(collection.queryArgs).toEqual({ransack: {id_eq: 5}})
27
- })
28
-
29
- it("handles sorts of different types", () => {
30
- let collection = new Collection({}, {})
31
-
32
- collection = collection.ransack({s: "created_at"})
33
- expect(collection.queryArgs.ransack.s).toEqual("created_at")
34
-
35
- collection = collection.ransack({s: ["id", "name"]})
36
- expect(collection.queryArgs.ransack.s).toEqual(["created_at", "id", "name"])
37
- })
38
- })
39
-
40
- describe("selectColumns", () => {
41
- it("adds selected columns to the query", () => {
42
- let collection = new Collection({}, {})
43
-
44
- collection = collection.selectColumns({User: ["id"]})
45
- expect(collection.queryArgs.selectColumns).toEqual({user: ["id"]})
46
-
47
- collection = collection.selectColumns({User: ["email"]})
48
- expect(collection.queryArgs.selectColumns).toEqual({user: ["id", "email"]})
49
- })
50
- })
51
- })
@@ -1,13 +0,0 @@
1
- import CustomError from "../src/custom-error.mjs"
2
-
3
- describe("CustomError", () => {
4
- it("handles when response is a string", () => {
5
- const xhr = {status: 401}
6
- const response = "An error happened"
7
- const customError = new CustomError(`Request failed with code: ${xhr.status}`, {response, xhr})
8
-
9
- expect(customError.message).toEqual("Request failed with code: 401")
10
- expect(customError.errorMessages()).toEqual(undefined)
11
- expect(customError.errorTypes()).toEqual(undefined)
12
- })
13
- })
@@ -1,34 +0,0 @@
1
- import I18nOnSteroids from "i18n-on-steroids"
2
- import ModelName from "../src/model-name.mjs"
3
-
4
- const i18n = new I18nOnSteroids()
5
-
6
- const initializeI18n = () => {
7
- i18n.scanObject({
8
- da: {
9
- activerecord: {
10
- models: {
11
- user: {
12
- one: "Bruger",
13
- other: "Brugere"
14
- }
15
- }
16
- }
17
- }
18
- })
19
- i18n.setLocale("da")
20
- }
21
-
22
- describe("ModelName", () => {
23
- beforeEach(() => {
24
- initializeI18n()
25
- })
26
-
27
- test("human", () => {
28
- const modelClassData = {i18nKey: "user"}
29
- const modelName = new ModelName({i18n, modelClassData})
30
-
31
- expect(modelName.human()).toEqual("Bruger")
32
- expect(modelName.human({count: 2})).toEqual("Brugere")
33
- })
34
- })
@@ -1,113 +0,0 @@
1
- import ModelPropType from "../src/model-prop-type.mjs"
2
- import Task from "./support/task.mjs"
3
- import User from "./support/user.mjs"
4
-
5
- describe("ModelPropType", () => {
6
- describe("ofModel", () => {
7
- it("validates model class successfully", () => {
8
- const user = new User({})
9
- const validator = ModelPropType.ofModel(User).isRequired
10
- const validation = validator({user}, "user")
11
-
12
- expect(validation).toBeUndefined()
13
- })
14
-
15
- it("validates model class unsuccessfully", () => {
16
- const task = new Task()
17
- const validator = ModelPropType.ofModel(User).isRequired
18
- const validation = validator({user: task}, "user")
19
-
20
- expect(validation).toEqual(new Error("Expected user to be of type User but it wasn't: Task"))
21
- })
22
- })
23
-
24
- describe("withLoadedAbilities", () => {
25
- it("validates required attributes successfully", () => {
26
- const user = new User({a: {id: 5}, b: {destroy: false, edit: true}})
27
- const validator = ModelPropType.ofModel(User).withLoadedAbilities(["destroy", "edit"]).isRequired
28
- const validation = validator({user}, "user")
29
-
30
- expect(validation).toBeUndefined()
31
- })
32
-
33
- it("validates required attributes unsuccessfully", () => {
34
- const user = new User({a: {id: 5}, b: {edit: true}})
35
- const validator = ModelPropType.ofModel(User).withLoadedAbilities(["destroy", "edit"]).isRequired
36
- const validation = validator({user}, "user")
37
-
38
- expect(validation).toEqual(new Error("The ability destroy was required to be loaded in user of the User type but it wasn't"))
39
- })
40
- })
41
-
42
- describe("withLoadedAssociation", () => {
43
- it("validates association is loaded overall successfully", () => {
44
- const task = new Task()
45
- const user = new User({r: {tasks: [task]}})
46
-
47
- const validator = ModelPropType
48
- .ofModel(User)
49
- .withLoadedAssociation("tasks")
50
- .previous()
51
- .isRequired
52
-
53
- const validation = validator({user}, "user")
54
-
55
- expect(validation).toBeUndefined()
56
- })
57
-
58
- it("validates association is loaded overall unsuccessfully", () => {
59
- const user = new User({r: {}})
60
-
61
- const validator = ModelPropType
62
- .ofModel(User)
63
- .withLoadedAssociation("tasks")
64
- .previous()
65
- .isRequired
66
-
67
- const validation = validator({user}, "user")
68
-
69
- expect(validation).toEqual(new Error("The association tasks was required to be loaded in user of the User type but it wasn't"))
70
- })
71
-
72
- it("validates attributes on nested associations", () => {
73
- const task = new Task({a: {id: 4, name: "Test task"}})
74
- const user = new User({r: {tasks: [task]}})
75
-
76
- const validator = ModelPropType.ofModel(User)
77
- .withLoadedAssociation("tasks")
78
- .withLoadedAttributes(["id", "name", "updatedAt"])
79
- .previous()
80
- .isRequired
81
-
82
- const validation = validator({user}, "user")
83
-
84
- expect(validation).toEqual(new Error("The attribute updatedAt was required to be loaded in user.tasks of the Task type but it wasn't"))
85
- })
86
- })
87
-
88
- describe("withLoadedAttributes", () => {
89
- it("validates required attributes successfully", () => {
90
- const user = new User({a: {id: 5, name: "Donald Duck"}})
91
- const validator = ModelPropType.ofModel(User).withLoadedAttributes(["id", "name"]).isRequired
92
- const validation = validator({user}, "user")
93
-
94
- expect(validation).toBeUndefined()
95
- })
96
-
97
- it("validates required attributes unsuccessfully", () => {
98
- const user = new User({a: {id: 5}})
99
- const validator = ModelPropType.ofModel(User).withLoadedAttributes(["id", "name"]).isRequired
100
- const validation = validator({user}, "user")
101
-
102
- expect(validation).toEqual(new Error("The attribute name was required to be loaded in user of the User type but it wasn't"))
103
- })
104
-
105
- it("ignores if the model is a new record", () => {
106
- const user = new User({isNewRecord: true})
107
- const validator = ModelPropType.ofModel(User).withLoadedAttributes(["id", "name"]).isRequired
108
- const validation = validator({user}, "user")
109
-
110
- expect(validation).toBeUndefined()
111
- })
112
- })
113
- })
@@ -1,40 +0,0 @@
1
- import Params from "../src/params.mjs"
2
-
3
- describe("Params", () => {
4
- describe("change", () => {
5
- it("changes the params", () => {
6
- delete global.location
7
-
8
- global.location = {
9
- search: "?q[name_cont]=kasper"
10
- }
11
-
12
- const result = Params.change({q: {s: "name asc"}})
13
-
14
- expect(result).toEqual({
15
- q: {
16
- name_cont: "kasper",
17
- s: "name asc"
18
- }
19
- })
20
- })
21
- })
22
-
23
- describe("parse", () => {
24
- it("parses the current path", () => {
25
- delete global.location
26
-
27
- global.location = {
28
- search: "?q[name_cont]=kasper"
29
- }
30
-
31
- const result = Params.parse()
32
-
33
- expect(result).toEqual({
34
- q: {
35
- name_cont: "kasper"
36
- }
37
- })
38
- })
39
- })
40
- })