@stancer/stancer 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (371) hide show
  1. package/CHANGELOG.md +23 -2
  2. package/dist/address/api-endpoint.d.ts +20 -0
  3. package/dist/address/api-endpoint.d.ts.map +1 -0
  4. package/dist/address/api-endpoint.js +28 -0
  5. package/dist/address/api-endpoint.js.map +1 -0
  6. package/dist/address/model.d.ts +35 -0
  7. package/dist/address/model.d.ts.map +1 -0
  8. package/dist/address/model.js +63 -0
  9. package/dist/address/model.js.map +1 -0
  10. package/dist/address/repository.d.ts +7 -0
  11. package/dist/address/repository.d.ts.map +1 -0
  12. package/dist/address/repository.js +14 -0
  13. package/dist/address/repository.js.map +1 -0
  14. package/dist/address/validator.d.ts +4 -0
  15. package/dist/address/validator.d.ts.map +1 -0
  16. package/dist/address/validator.js +32 -0
  17. package/dist/address/validator.js.map +1 -0
  18. package/dist/api-endpoint/abstract-api-endpoint.d.ts +46 -0
  19. package/dist/api-endpoint/abstract-api-endpoint.d.ts.map +1 -0
  20. package/dist/api-endpoint/abstract-api-endpoint.js +220 -0
  21. package/dist/api-endpoint/abstract-api-endpoint.js.map +1 -0
  22. package/dist/api-endpoint/configuration.d.ts +34 -0
  23. package/dist/api-endpoint/configuration.d.ts.map +1 -0
  24. package/dist/api-endpoint/configuration.js +99 -0
  25. package/dist/api-endpoint/configuration.js.map +1 -0
  26. package/dist/api-endpoint/http/fetch-http-client.d.ts +3 -0
  27. package/dist/api-endpoint/http/fetch-http-client.d.ts.map +1 -0
  28. package/dist/api-endpoint/http/fetch-http-client.js +34 -0
  29. package/dist/api-endpoint/http/fetch-http-client.js.map +1 -0
  30. package/dist/api-endpoint/http/http.d.ts +18 -0
  31. package/dist/api-endpoint/http/http.d.ts.map +1 -0
  32. package/dist/api-endpoint/http/http.js +47 -0
  33. package/dist/api-endpoint/http/http.js.map +1 -0
  34. package/dist/api-endpoint/http/index.d.ts +3 -0
  35. package/dist/api-endpoint/http/index.d.ts.map +1 -0
  36. package/dist/api-endpoint/http/index.js +3 -0
  37. package/dist/api-endpoint/http/index.js.map +1 -0
  38. package/dist/api-endpoint/version.d.ts +5 -0
  39. package/dist/api-endpoint/version.d.ts.map +1 -0
  40. package/dist/api-endpoint/version.js +6 -0
  41. package/dist/api-endpoint/version.js.map +1 -0
  42. package/dist/card/api-endpoint.d.ts +28 -0
  43. package/dist/card/api-endpoint.d.ts.map +1 -0
  44. package/dist/card/api-endpoint.js +37 -0
  45. package/dist/card/api-endpoint.js.map +1 -0
  46. package/dist/card/enum/funding.d.ts +3 -0
  47. package/dist/card/enum/funding.d.ts.map +1 -0
  48. package/dist/card/enum/funding.js +10 -0
  49. package/dist/card/enum/funding.js.map +1 -0
  50. package/dist/card/enum/nature.d.ts +3 -0
  51. package/dist/card/enum/nature.d.ts.map +1 -0
  52. package/dist/card/enum/nature.js +6 -0
  53. package/dist/card/enum/nature.js.map +1 -0
  54. package/dist/card/enum/network.d.ts +5 -0
  55. package/dist/card/enum/network.d.ts.map +1 -0
  56. package/dist/card/enum/network.js +12 -0
  57. package/dist/card/enum/network.js.map +1 -0
  58. package/dist/card/model.d.ts +55 -0
  59. package/dist/card/model.d.ts.map +1 -0
  60. package/dist/card/model.js +90 -0
  61. package/dist/card/model.js.map +1 -0
  62. package/dist/card/repository.d.ts +7 -0
  63. package/dist/card/repository.d.ts.map +1 -0
  64. package/dist/card/repository.js +10 -0
  65. package/dist/card/repository.js.map +1 -0
  66. package/dist/card/validator.d.ts +8 -0
  67. package/dist/card/validator.d.ts.map +1 -0
  68. package/dist/card/validator.js +71 -0
  69. package/dist/card/validator.js.map +1 -0
  70. package/dist/core/abstract-model.d.ts +51 -0
  71. package/dist/core/abstract-model.d.ts.map +1 -0
  72. package/dist/core/abstract-model.js +93 -0
  73. package/dist/core/abstract-model.js.map +1 -0
  74. package/dist/core/abstract-repository.d.ts +86 -0
  75. package/dist/core/abstract-repository.d.ts.map +1 -0
  76. package/dist/core/abstract-repository.js +97 -0
  77. package/dist/core/abstract-repository.js.map +1 -0
  78. package/dist/core/common/branded-type.d.ts +6 -0
  79. package/dist/core/common/branded-type.d.ts.map +1 -0
  80. package/dist/core/common/branded-type.js +9 -0
  81. package/dist/core/common/branded-type.js.map +1 -0
  82. package/dist/core/common/handler/date-handler.d.ts +5 -0
  83. package/dist/core/common/handler/date-handler.d.ts.map +1 -0
  84. package/dist/core/common/handler/date-handler.js +23 -0
  85. package/dist/core/common/handler/date-handler.js.map +1 -0
  86. package/dist/core/common/handler/enum-handler.d.ts +3 -0
  87. package/dist/core/common/handler/enum-handler.d.ts.map +1 -0
  88. package/dist/core/common/handler/enum-handler.js +14 -0
  89. package/dist/core/common/handler/enum-handler.js.map +1 -0
  90. package/dist/core/common/handler/handler.d.ts +24 -0
  91. package/dist/core/common/handler/handler.d.ts.map +1 -0
  92. package/dist/core/common/handler/handler.js +33 -0
  93. package/dist/core/common/handler/handler.js.map +1 -0
  94. package/dist/core/common/handler/id-handler.d.ts +4 -0
  95. package/dist/core/common/handler/id-handler.d.ts.map +1 -0
  96. package/dist/core/common/handler/id-handler.js +21 -0
  97. package/dist/core/common/handler/id-handler.js.map +1 -0
  98. package/dist/core/common/handler/metadata-handler.d.ts +18 -0
  99. package/dist/core/common/handler/metadata-handler.d.ts.map +1 -0
  100. package/dist/core/common/handler/metadata-handler.js +19 -0
  101. package/dist/core/common/handler/metadata-handler.js.map +1 -0
  102. package/dist/core/common/id-validator.d.ts +10 -0
  103. package/dist/core/common/id-validator.d.ts.map +1 -0
  104. package/dist/core/common/id-validator.js +17 -0
  105. package/dist/core/common/id-validator.js.map +1 -0
  106. package/dist/core/common/mutation-tracked-object.d.ts +8 -0
  107. package/dist/core/common/mutation-tracked-object.d.ts.map +1 -0
  108. package/dist/core/common/mutation-tracked-object.js +38 -0
  109. package/dist/core/common/mutation-tracked-object.js.map +1 -0
  110. package/dist/core/endpoint-interface.d.ts +38 -0
  111. package/dist/core/endpoint-interface.d.ts.map +1 -0
  112. package/dist/core/endpoint-interface.js +2 -0
  113. package/dist/core/endpoint-interface.js.map +1 -0
  114. package/dist/core/error/base-error.d.ts +3 -0
  115. package/dist/core/error/base-error.d.ts.map +1 -0
  116. package/dist/core/error/base-error.js +3 -0
  117. package/dist/core/error/base-error.js.map +1 -0
  118. package/dist/core/error/endpoint/api/api-conflict-error.d.ts +5 -0
  119. package/dist/core/error/endpoint/api/api-conflict-error.d.ts.map +1 -0
  120. package/dist/core/error/endpoint/api/api-conflict-error.js +7 -0
  121. package/dist/core/error/endpoint/api/api-conflict-error.js.map +1 -0
  122. package/dist/core/error/endpoint/api/api-error.d.ts +6 -0
  123. package/dist/core/error/endpoint/api/api-error.d.ts.map +1 -0
  124. package/dist/core/error/endpoint/api/api-error.js +9 -0
  125. package/dist/core/error/endpoint/api/api-error.js.map +1 -0
  126. package/dist/core/error/endpoint/api/api-not-found-error.d.ts +5 -0
  127. package/dist/core/error/endpoint/api/api-not-found-error.d.ts.map +1 -0
  128. package/dist/core/error/endpoint/api/api-not-found-error.js +7 -0
  129. package/dist/core/error/endpoint/api/api-not-found-error.js.map +1 -0
  130. package/dist/core/error/endpoint/api/api-unauthorized-error.d.ts +5 -0
  131. package/dist/core/error/endpoint/api/api-unauthorized-error.d.ts.map +1 -0
  132. package/dist/core/error/endpoint/api/api-unauthorized-error.js +7 -0
  133. package/dist/core/error/endpoint/api/api-unauthorized-error.js.map +1 -0
  134. package/dist/core/error/endpoint/api/api-unknown-error.d.ts +5 -0
  135. package/dist/core/error/endpoint/api/api-unknown-error.d.ts.map +1 -0
  136. package/dist/core/error/endpoint/api/api-unknown-error.js +7 -0
  137. package/dist/core/error/endpoint/api/api-unknown-error.js.map +1 -0
  138. package/dist/core/error/endpoint/api/api-validation-error.d.ts +11 -0
  139. package/dist/core/error/endpoint/api/api-validation-error.d.ts.map +1 -0
  140. package/dist/core/error/endpoint/api/api-validation-error.js +9 -0
  141. package/dist/core/error/endpoint/api/api-validation-error.js.map +1 -0
  142. package/dist/core/error/endpoint/api/index.d.ts +7 -0
  143. package/dist/core/error/endpoint/api/index.d.ts.map +1 -0
  144. package/dist/core/error/endpoint/api/index.js +7 -0
  145. package/dist/core/error/endpoint/api/index.js.map +1 -0
  146. package/dist/core/error/endpoint/route-inaccessible-error.d.ts +5 -0
  147. package/dist/core/error/endpoint/route-inaccessible-error.d.ts.map +1 -0
  148. package/dist/core/error/endpoint/route-inaccessible-error.js +8 -0
  149. package/dist/core/error/endpoint/route-inaccessible-error.js.map +1 -0
  150. package/dist/core/error/unpopulated-error.d.ts +4 -0
  151. package/dist/core/error/unpopulated-error.d.ts.map +1 -0
  152. package/dist/core/error/unpopulated-error.js +4 -0
  153. package/dist/core/error/unpopulated-error.js.map +1 -0
  154. package/dist/core/error/unsendable-error.d.ts +4 -0
  155. package/dist/core/error/unsendable-error.d.ts.map +1 -0
  156. package/dist/core/error/unsendable-error.js +4 -0
  157. package/dist/core/error/unsendable-error.js.map +1 -0
  158. package/dist/core/error/validation-error.d.ts +4 -0
  159. package/dist/core/error/validation-error.d.ts.map +1 -0
  160. package/dist/core/error/validation-error.js +4 -0
  161. package/dist/core/error/validation-error.js.map +1 -0
  162. package/dist/core/validator.d.ts +63 -0
  163. package/dist/core/validator.d.ts.map +1 -0
  164. package/dist/core/validator.js +73 -0
  165. package/dist/core/validator.js.map +1 -0
  166. package/dist/customer/api-endpoint.d.ts +21 -0
  167. package/dist/customer/api-endpoint.d.ts.map +1 -0
  168. package/dist/customer/api-endpoint.js +27 -0
  169. package/dist/customer/api-endpoint.js.map +1 -0
  170. package/dist/customer/model.d.ts +39 -0
  171. package/dist/customer/model.d.ts.map +1 -0
  172. package/dist/customer/model.js +73 -0
  173. package/dist/customer/model.js.map +1 -0
  174. package/dist/customer/repository.d.ts +7 -0
  175. package/dist/customer/repository.d.ts.map +1 -0
  176. package/dist/customer/repository.js +10 -0
  177. package/dist/customer/repository.js.map +1 -0
  178. package/dist/customer/validator.d.ts +4 -0
  179. package/dist/customer/validator.d.ts.map +1 -0
  180. package/dist/customer/validator.js +23 -0
  181. package/dist/customer/validator.js.map +1 -0
  182. package/dist/event/model.d.ts +20 -0
  183. package/dist/event/model.d.ts.map +1 -0
  184. package/dist/event/model.js +30 -0
  185. package/dist/event/model.js.map +1 -0
  186. package/dist/payment/api-endpoint.d.ts +51 -0
  187. package/dist/payment/api-endpoint.d.ts.map +1 -0
  188. package/dist/payment/api-endpoint.js +110 -0
  189. package/dist/payment/api-endpoint.js.map +1 -0
  190. package/dist/payment/enum/currency.d.ts +3 -0
  191. package/dist/payment/enum/currency.d.ts.map +1 -0
  192. package/dist/payment/enum/currency.js +13 -0
  193. package/dist/payment/enum/currency.js.map +1 -0
  194. package/dist/payment/enum/method.d.ts +3 -0
  195. package/dist/payment/enum/method.d.ts.map +1 -0
  196. package/dist/payment/enum/method.js +2 -0
  197. package/dist/payment/enum/method.js.map +1 -0
  198. package/dist/payment/enum/status.d.ts +4 -0
  199. package/dist/payment/enum/status.d.ts.map +1 -0
  200. package/dist/payment/enum/status.js +19 -0
  201. package/dist/payment/enum/status.js.map +1 -0
  202. package/dist/payment/model.d.ts +135 -0
  203. package/dist/payment/model.d.ts.map +1 -0
  204. package/dist/payment/model.js +232 -0
  205. package/dist/payment/model.js.map +1 -0
  206. package/dist/payment/repository.d.ts +17 -0
  207. package/dist/payment/repository.d.ts.map +1 -0
  208. package/dist/payment/repository.js +56 -0
  209. package/dist/payment/repository.js.map +1 -0
  210. package/dist/payment/validator.d.ts +16 -0
  211. package/dist/payment/validator.d.ts.map +1 -0
  212. package/dist/payment/validator.js +81 -0
  213. package/dist/payment/validator.js.map +1 -0
  214. package/dist/payment-intent/api-endpoint.d.ts +63 -0
  215. package/dist/payment-intent/api-endpoint.d.ts.map +1 -0
  216. package/dist/payment-intent/api-endpoint.js +95 -0
  217. package/dist/payment-intent/api-endpoint.js.map +1 -0
  218. package/dist/payment-intent/enum/status.d.ts +5 -0
  219. package/dist/payment-intent/enum/status.d.ts.map +1 -0
  220. package/dist/payment-intent/enum/status.js +20 -0
  221. package/dist/payment-intent/enum/status.js.map +1 -0
  222. package/dist/payment-intent/enum/threeds.d.ts +3 -0
  223. package/dist/payment-intent/enum/threeds.d.ts.map +1 -0
  224. package/dist/payment-intent/enum/threeds.js +2 -0
  225. package/dist/payment-intent/enum/threeds.js.map +1 -0
  226. package/dist/payment-intent/model.d.ts +91 -0
  227. package/dist/payment-intent/model.d.ts.map +1 -0
  228. package/dist/payment-intent/model.js +183 -0
  229. package/dist/payment-intent/model.js.map +1 -0
  230. package/dist/payment-intent/repository.d.ts +13 -0
  231. package/dist/payment-intent/repository.d.ts.map +1 -0
  232. package/dist/payment-intent/repository.js +65 -0
  233. package/dist/payment-intent/repository.js.map +1 -0
  234. package/dist/payment-intent/validator.d.ts +4 -0
  235. package/dist/payment-intent/validator.d.ts.map +1 -0
  236. package/dist/payment-intent/validator.js +38 -0
  237. package/dist/payment-intent/validator.js.map +1 -0
  238. package/dist/payout/model.d.ts +7 -0
  239. package/dist/payout/model.d.ts.map +1 -0
  240. package/dist/payout/model.js +6 -0
  241. package/dist/payout/model.js.map +1 -0
  242. package/dist/refund/api-endpoint.d.ts +22 -0
  243. package/dist/refund/api-endpoint.d.ts.map +1 -0
  244. package/dist/refund/api-endpoint.js +32 -0
  245. package/dist/refund/api-endpoint.js.map +1 -0
  246. package/dist/refund/enum/refund-status.d.ts +3 -0
  247. package/dist/refund/enum/refund-status.d.ts.map +1 -0
  248. package/dist/refund/enum/refund-status.js +10 -0
  249. package/dist/refund/enum/refund-status.js.map +1 -0
  250. package/dist/refund/model.d.ts +38 -0
  251. package/dist/refund/model.d.ts.map +1 -0
  252. package/dist/refund/model.js +51 -0
  253. package/dist/refund/model.js.map +1 -0
  254. package/dist/refund/repository.d.ts +7 -0
  255. package/dist/refund/repository.d.ts.map +1 -0
  256. package/dist/refund/repository.js +10 -0
  257. package/dist/refund/repository.js.map +1 -0
  258. package/dist/refund/validator.d.ts +4 -0
  259. package/dist/refund/validator.d.ts.map +1 -0
  260. package/dist/refund/validator.js +41 -0
  261. package/dist/refund/validator.js.map +1 -0
  262. package/dist/sepa/api-endpoint.d.ts +19 -0
  263. package/dist/sepa/api-endpoint.d.ts.map +1 -0
  264. package/dist/sepa/api-endpoint.js +25 -0
  265. package/dist/sepa/api-endpoint.js.map +1 -0
  266. package/dist/sepa/model.d.ts +32 -0
  267. package/dist/sepa/model.d.ts.map +1 -0
  268. package/dist/sepa/model.js +53 -0
  269. package/dist/sepa/model.js.map +1 -0
  270. package/dist/sepa/repository.d.ts +7 -0
  271. package/dist/sepa/repository.d.ts.map +1 -0
  272. package/dist/sepa/repository.js +10 -0
  273. package/dist/sepa/repository.js.map +1 -0
  274. package/dist/sepa/validator.d.ts +8 -0
  275. package/dist/sepa/validator.d.ts.map +1 -0
  276. package/dist/sepa/validator.js +47 -0
  277. package/dist/sepa/validator.js.map +1 -0
  278. package/dist/webhook/api-endpoint.d.ts +16 -0
  279. package/dist/webhook/api-endpoint.d.ts.map +1 -0
  280. package/dist/webhook/api-endpoint.js +33 -0
  281. package/dist/webhook/api-endpoint.js.map +1 -0
  282. package/dist/webhook/model.d.ts +35 -0
  283. package/dist/webhook/model.d.ts.map +1 -0
  284. package/dist/webhook/model.js +110 -0
  285. package/dist/webhook/model.js.map +1 -0
  286. package/dist/webhook/repository.d.ts +7 -0
  287. package/dist/webhook/repository.d.ts.map +1 -0
  288. package/dist/webhook/repository.js +10 -0
  289. package/dist/webhook/repository.js.map +1 -0
  290. package/dist/webhook/validator.d.ts +4 -0
  291. package/dist/webhook/validator.d.ts.map +1 -0
  292. package/dist/webhook/validator.js +16 -0
  293. package/dist/webhook/validator.js.map +1 -0
  294. package/package.json +4 -2
  295. package/src/api-endpoint/http/fetch-http-client.ts +8 -1
  296. package/src/core/common/handler/metadata-handler.ts +19 -0
  297. package/src/event/model.ts +42 -0
  298. package/src/payment-intent/api-endpoint.ts +2 -1
  299. package/src/payment-intent/model.ts +8 -3
  300. package/src/webhook/api-endpoint.ts +36 -0
  301. package/src/webhook/model.ts +140 -0
  302. package/src/webhook/repository.ts +14 -0
  303. package/src/webhook/validator.ts +18 -0
  304. package/.editorconfig +0 -14
  305. package/.gitlab-ci.yml +0 -159
  306. package/.prettierignore +0 -3
  307. package/eslint.config.js +0 -14
  308. package/pnpm-workspace.yaml +0 -19
  309. package/prettier.config.js +0 -3
  310. package/test/fixtures/endpoint.stub.ts +0 -22
  311. package/test/fixtures/list-endpoint.stub.ts +0 -33
  312. package/test/fixtures/list-model.stub.ts +0 -24
  313. package/test/fixtures/model.stub.ts +0 -12
  314. package/test/functional/address.test.ts +0 -126
  315. package/test/functional/card.test.ts +0 -175
  316. package/test/functional/customer.test.ts +0 -174
  317. package/test/functional/payment-intent.test.ts +0 -215
  318. package/test/functional/payment.test.ts +0 -206
  319. package/test/functional/refund.test.ts +0 -112
  320. package/test/functional/sepa.test.ts +0 -136
  321. package/test/integration/stub-integration.test.ts +0 -88
  322. package/test/stub/stub-endpoint.ts +0 -42
  323. package/test/stub/stub-model.ts +0 -82
  324. package/test/stub/stub-repository.ts +0 -11
  325. package/test/test-helper.ts +0 -133
  326. package/test/unit/address/api-endpoint.test.ts +0 -134
  327. package/test/unit/address/fixtures.ts +0 -60
  328. package/test/unit/address/model.test.ts +0 -75
  329. package/test/unit/address/repository.test.ts +0 -148
  330. package/test/unit/address/validator.test.ts +0 -49
  331. package/test/unit/api-endpoint/http/fetch-http-client.test.ts +0 -44
  332. package/test/unit/api-endpoint/http/http.test.ts +0 -152
  333. package/test/unit/card/api-endpoint.test.ts +0 -170
  334. package/test/unit/card/card-helper.ts +0 -116
  335. package/test/unit/card/fixtures.ts +0 -87
  336. package/test/unit/card/model.test.ts +0 -167
  337. package/test/unit/card/repository.test.ts +0 -146
  338. package/test/unit/card/validator.test.ts +0 -96
  339. package/test/unit/core/common/mutation-tracked-object.test.ts +0 -24
  340. package/test/unit/customer/api-endpoint.test.ts +0 -143
  341. package/test/unit/customer/fixtures.ts +0 -73
  342. package/test/unit/customer/model.test.ts +0 -90
  343. package/test/unit/customer/repository.test.ts +0 -148
  344. package/test/unit/customer/validator.test.ts +0 -62
  345. package/test/unit/payment/api-endpoint.test.ts +0 -188
  346. package/test/unit/payment/fixtures.ts +0 -116
  347. package/test/unit/payment/model.test.ts +0 -240
  348. package/test/unit/payment/repository.test.ts +0 -270
  349. package/test/unit/payment/validator.test.ts +0 -137
  350. package/test/unit/payment-intent/api-endpoint.test.ts +0 -142
  351. package/test/unit/payment-intent/fixtures.ts +0 -94
  352. package/test/unit/payment-intent/model.test.ts +0 -157
  353. package/test/unit/payment-intent/repository.test.ts +0 -263
  354. package/test/unit/payment-intent/validator.test.ts +0 -136
  355. package/test/unit/refund/api-endpoint.test.ts +0 -129
  356. package/test/unit/refund/fixtures.ts +0 -58
  357. package/test/unit/refund/model.test.ts +0 -89
  358. package/test/unit/refund/repository.test.ts +0 -157
  359. package/test/unit/refund/validator.test.ts +0 -89
  360. package/test/unit/sepa/api-endpoint.test.ts +0 -170
  361. package/test/unit/sepa/fixture.ts +0 -62
  362. package/test/unit/sepa/model.test.ts +0 -86
  363. package/test/unit/sepa/repository.test.ts +0 -149
  364. package/test/unit/sepa/sepa-helper.ts +0 -71
  365. package/test/unit/sepa/validator.test.ts +0 -58
  366. package/test/unit/stub/stub-endpoint.test.ts +0 -236
  367. package/test/unit/stub/stub-list-endpoint.test.ts +0 -86
  368. package/test/unit/stub/stub-model.test.ts +0 -111
  369. package/test/unit/stub/stub-repository.test.ts +0 -144
  370. package/tsconfig.json +0 -50
  371. package/vitest.config.ts +0 -20
@@ -1,86 +0,0 @@
1
- import { describe, it } from 'vitest';
2
-
3
- import { Validator } from '#core/validator.js';
4
- import { IdCustomer } from '#customer/model.ts';
5
- import { SepaData, SepaModel } from '#sepa/model.js';
6
- import { SetterGetter, randomPastDate, randomString } from '#test/test-helper.js';
7
-
8
- import { bicDataProvider, ibanDataProvider } from './sepa-helper';
9
-
10
- describe('sepa Class', () => {
11
- const sepa = new SepaModel((() => true) as unknown as Validator<SepaData>);
12
-
13
- describe('Setter & Getter', () => {
14
- it.each((bicDataProvider(false) as string[]).map((n) => [n]))('bic', (bic) => {
15
- sepa._data.bic = null;
16
- SetterGetter(
17
- (value: string) => sepa.setBic(value),
18
- () => sepa.bic,
19
- bic,
20
- );
21
- });
22
-
23
- it('deleted (unsettable)', () => {
24
- SetterGetter(
25
- (value: boolean) => (sepa._data.deleted = value),
26
- () => sepa.deleted,
27
- true,
28
- );
29
- sepa._data.deleted = null;
30
- SetterGetter(
31
- (value: boolean) => (sepa._data.deleted = value),
32
- () => sepa.deleted,
33
- false,
34
- );
35
- });
36
-
37
- it('customer', () => {
38
- SetterGetter(
39
- (value: IdCustomer) => sepa.setCustomer(value),
40
- () => sepa.customer,
41
- ``,
42
- );
43
- });
44
-
45
- it('dateMandate', () => {
46
- SetterGetter(
47
- (value: string) => sepa.setDateMandate(value),
48
- () => sepa.dateMandate,
49
- randomPastDate(),
50
- );
51
- });
52
-
53
- it('last4', () => {
54
- SetterGetter(
55
- (value: string) => (sepa._data.last4 = value),
56
- () => sepa.last4,
57
- randomString(4),
58
- );
59
- });
60
-
61
- it('mandate', () => {
62
- SetterGetter(
63
- (value: string) => sepa.setMandate(value),
64
- () => sepa.mandate,
65
- randomString(0, 35),
66
- );
67
- });
68
-
69
- it('name', () => {
70
- SetterGetter(
71
- (value: string) => sepa.setName(value),
72
- () => sepa.name,
73
- randomString(0, 64),
74
- );
75
- });
76
-
77
- it.each((ibanDataProvider() as string[]).map((value) => [value]))('iban %s', (value) => {
78
- sepa._data.iban = null;
79
- SetterGetter(
80
- (value: string) => sepa.setIban(value),
81
- () => sepa._data.iban,
82
- value,
83
- );
84
- });
85
- });
86
- });
@@ -1,149 +0,0 @@
1
- import { describe, expect, it, vi } from 'vitest';
2
-
3
- import { AbstractRepository } from '#core/abstract-repository.js';
4
- import { StancerError } from '#error/base-error.js';
5
- import { StancerRouteInaccessibleError } from '#error/endpoint/route-inaccessible-error.js';
6
- import { SepaApiEndpoint } from '#sepa/api-endpoint.js';
7
- import { IdSepa, SepaModel } from '#sepa/model.js';
8
- import { SepaRepository } from '#sepa/repository.js';
9
- import { sepaValidator } from '#sepa/validator.js';
10
- import { randomString } from '#test/test-helper.js';
11
-
12
- import { creationResource, endpointResource, listResource } from './fixture';
13
-
14
- const idPrefix = 'sepa';
15
- const id = `${idPrefix}_${randomString(24)}` as IdSepa;
16
- const stancerErrorID = `${idPrefix}_unidentifiedError${randomString(7)}`;
17
- const stancerRouteInaccessibleId = `${idPrefix}_StancerRouteInnacessible`;
18
- const dataHasBeenSentId = `${idPrefix}_DataHasBeenSent${randomString(9)}`;
19
- const dataUnmodified = `${idPrefix}_unmodifiedData${randomString(10)}`;
20
- class MockApiEndpoint {
21
- constructor() {}
22
-
23
- list() {
24
- async function* listGenerator() {
25
- yield* listResource;
26
- }
27
- return listGenerator();
28
- }
29
-
30
- delete() {
31
- return endpointResource;
32
- }
33
-
34
- send(id: string, data: Record<string, unknown>) {
35
- if (id) {
36
- if (id === stancerErrorID) {
37
- throw new StancerError();
38
- }
39
- if (id === stancerRouteInaccessibleId) {
40
- throw new StancerRouteInaccessibleError('PATCH', 'stub');
41
- }
42
- if (id === dataUnmodified) {
43
- return;
44
- }
45
- }
46
- return { ...data, id: dataHasBeenSentId };
47
- }
48
-
49
- get() {
50
- return endpointResource;
51
- }
52
- }
53
-
54
- it('can be instanciated', () => {
55
- const instance = new SepaRepository();
56
- expect(instance).toBeInstanceOf(SepaRepository);
57
- expect(instance).toBeInstanceOf(AbstractRepository);
58
- //accessing private method & property
59
- expect(instance.endpoint).toBeInstanceOf(SepaApiEndpoint);
60
- expect(instance.validator).toBe(sepaValidator);
61
- expect(instance.staticModel).toBe(SepaModel);
62
- });
63
-
64
- describe('repository', () => {
65
- const mockRepo = new MockApiEndpoint() as unknown as SepaApiEndpoint; // I lie, for convenience sake
66
- const repository = new SepaRepository(mockRepo);
67
-
68
- describe('create', () => {
69
- it("doesn't accept bad data", async () => {
70
- const badID = randomString(30, 56);
71
- // using puposefuly bad ID
72
- await expect(async () => await repository.create(badID)).rejects.toThrow();
73
- });
74
-
75
- it('accept good data', async () => {
76
- const model = await repository.create(id);
77
- expect(model).toBeInstanceOf(SepaModel);
78
- });
79
- });
80
-
81
- it('delete', async () => {
82
- const modelWithoutId = await repository.create();
83
- await expect(() => repository.delete(modelWithoutId)).rejects.toThrow();
84
- const model = await repository.create({ id: endpointResource.id, ...creationResource });
85
- await expect((await repository.delete(model))._data).toStrictEqual(endpointResource);
86
- });
87
-
88
- describe('send', () => {
89
- it('should return model', async () => {
90
- const model = await repository.create(creationResource);
91
- const sentModel = await repository.send(model);
92
- expect(sentModel).toStrictEqual(model);
93
- expect(sentModel._data.id).toEqual(dataHasBeenSentId);
94
- });
95
-
96
- it('should throw on inprecise error', async () => {
97
- const model = await repository.create({ ...creationResource, id: stancerErrorID as IdSepa });
98
- await expect(() => repository.send(model)).rejects.toThrow(StancerError);
99
- });
100
-
101
- it('should return error on StancerRouteInacessibleError', async () => {
102
- const model = await repository.create({ ...creationResource, id: stancerRouteInaccessibleId as IdSepa });
103
- await expect(async () => await repository.send(model)).rejects.toThrow(StancerRouteInaccessibleError);
104
- });
105
-
106
- it('should return unmodified model when no new Data', async () => {
107
- const model = await repository.create({ ...creationResource, id: dataUnmodified as IdSepa });
108
- const sentModel = await repository.send(model);
109
- expect(model).toStrictEqual(sentModel);
110
- expect(sentModel._data.id).toEqual(dataUnmodified);
111
- });
112
- });
113
-
114
- describe('populate', () => {
115
- it('should not modify model if no Id', async () => {
116
- const getEndpoint = vi.spyOn(mockRepo, 'get');
117
- const model = await repository.create(creationResource);
118
- expect(model).toBeInstanceOf(SepaModel);
119
- expect(getEndpoint).toHaveBeenCalledTimes(0);
120
- });
121
-
122
- it('should get model if only id', async () => {
123
- const getEndpoint = vi.spyOn(mockRepo, 'get');
124
- const model = await repository.create(id);
125
- expect(model).toBeInstanceOf(SepaModel);
126
- expect(getEndpoint).toHaveBeenCalledTimes(1);
127
- });
128
- });
129
-
130
- describe('list', async () => {
131
- it('return correct model one by one', async () => {
132
- const listStub = repository.list();
133
- const item1 = await listStub.next();
134
- expect(item1.done).toBeFalsy();
135
- expect(item1.value).toHaveProperty('id');
136
- expect(item1.value).toBeInstanceOf(SepaModel);
137
- expect(item1.value.name).toBe('item1');
138
-
139
- const item2 = await listStub.next();
140
- expect(item2.done).toBeFalsy();
141
- expect(item2.value).toHaveProperty('id');
142
- expect(item2.value).toBeInstanceOf(SepaModel);
143
- expect(item2.value.name).toBe('item2');
144
-
145
- const item3 = await listStub.next();
146
- expect(item3.done).toBeTruthy();
147
- });
148
- });
149
- });
@@ -1,71 +0,0 @@
1
- import { randomNumber } from '#test/test-helper.js';
2
-
3
- export const bicDataProvider = (one: boolean = false) => {
4
- // Thanks Wikipedia
5
- const data = [
6
- 'DEUTDEFF',
7
- 'DEUTDEFFXXX',
8
- 'DEUTGBFFA23',
9
- 'DEUTDEFF500',
10
- 'UKCBUau102v',
11
- 'UKIOLT2XXXX',
12
- 'GBMCMRMRXXX',
13
- 'gbtxus31xxx',
14
- 'JUBIGB21XXX',
15
- ];
16
- if (!one) {
17
- return data;
18
- }
19
-
20
- return data[randomNumber(0, data.length - 1)];
21
- };
22
-
23
- export const ibanDataProvider = (one: boolean = false) => {
24
- // Thanks Wikipedia
25
- const data = [
26
- 'BE71 0961 2345 6769',
27
- 'FR76 3000 6000 0112 3456 7890 189',
28
- 'DE91 1000 0000 0123 4567 89',
29
- 'GR9608100010000001234567890',
30
- 'RO09 BCYP 0000 0012 3456 7890',
31
- 'SA4420000001234567891234',
32
- 'ES79 2100 0813 6101 2345 6789',
33
- 'CH56 0483 5012 3456 7800 9 ',
34
- 'GB98 MIDL 0700 9312 3456 78',
35
- 'GB82WEST12345698765432',
36
- ];
37
-
38
- if (!one) {
39
- return data;
40
- }
41
-
42
- return data[randomNumber(0, data.length - 1)];
43
- };
44
-
45
- export const validIbanDataProvider = (one: boolean = false) => {
46
- const data = [
47
- 'AT611904300234573201',
48
- 'BE62510007547061',
49
- 'CH2089144321842946678',
50
- 'DE89370400440532013000',
51
- 'EE382200221020145685',
52
- 'ES0700120345030000067890',
53
- 'FI2112345600000785',
54
- 'FR1420041010050500013M02606',
55
- 'GB33BUKB20201555555555',
56
- 'IE29AIBK93115212345678',
57
- 'LT121000011101001000',
58
- 'LU280019400644750000',
59
- 'IT02A0301926102000000490887',
60
- 'NL39RABO0300065264',
61
- 'NO9386011117947',
62
- 'PT50000201231234567890154',
63
- 'SE3550000000054910000003',
64
- ];
65
-
66
- if (!one) {
67
- return data;
68
- }
69
-
70
- return data[randomNumber(0, data.length - 1)];
71
- };
@@ -1,58 +0,0 @@
1
- import { Temporal } from 'temporal-polyfill';
2
- import { describe, expect, it } from 'vitest';
3
-
4
- import { idCustomer } from '#customer/model.ts';
5
- import { SepaModel } from '#sepa/model.js';
6
- import { sepaValidator } from '#sepa/validator.js';
7
- import { checkType, goldilocks, randomMonth, randomNumber, randomString } from '#test/test-helper.js';
8
-
9
- import { ibanDataProvider } from './sepa-helper';
10
-
11
- describe('Goldilocks', () => {
12
- const sepa = new SepaModel(sepaValidator);
13
-
14
- it('bic', () => {
15
- goldilocks((value: string) => sepa.setBic(value), 'string', { min: 8, max: 11 });
16
- checkType((value: string) => (sepa._data.bic = value), ['string'], randomString(8, 11));
17
- });
18
-
19
- it('customer', () => {
20
- const falseCustomer = randomString(24);
21
- const trueCustomer = idCustomer(`cust_${randomString(24)}`);
22
- expect(() => sepa.setCustomer(falseCustomer)).toThrow();
23
- sepa.setCustomer(trueCustomer);
24
- expect(sepa.customer).toBe(trueCustomer);
25
- });
26
-
27
- it('dateMandate', () => {
28
- const falseDateMandate = new Temporal.PlainDate(9999, randomMonth(), randomNumber(1, 28));
29
- const notInstantDateMandate = new Temporal.PlainDate(1969, randomMonth(), randomNumber(1, 28));
30
- const dateMandate = new Temporal.PlainDate(
31
- randomNumber(1971, Temporal.Now.plainDateISO().year),
32
- randomMonth(),
33
- randomNumber(1, 28),
34
- );
35
- expect(() => sepa.setDateMandate(falseDateMandate)).toThrow();
36
- expect(() => sepa.setDateMandate(notInstantDateMandate)).toThrow();
37
- sepa.setDateMandate(dateMandate);
38
- expect(sepa.dateMandate).toBe(dateMandate);
39
- });
40
-
41
- it('iban', () => {
42
- const falseSepaNumber = randomString(14, 34);
43
- expect(() => sepa.setIban(falseSepaNumber)).toThrow();
44
- const trueSepaNumber = ibanDataProvider(true);
45
- sepa.setIban(trueSepaNumber);
46
- expect(sepa._data.iban).toBe(trueSepaNumber);
47
- });
48
-
49
- it('mandate', () => {
50
- goldilocks((value: string) => sepa.setMandate(value), 'string', { min: 1, max: 35 });
51
- checkType((value: string) => sepa.setMandate(value), ['string'], randomString(1, 35));
52
- });
53
-
54
- it('name', () => {
55
- goldilocks((value: string) => sepa.setName(value), 'string', { min: 3, max: 64 });
56
- checkType((value: string) => sepa.setName(value), ['string'], randomString(3, 64));
57
- });
58
- });
@@ -1,236 +0,0 @@
1
- import { describe, expect, it, vi } from 'vitest';
2
-
3
- import { IdValue } from '#core/common/branded-type.js';
4
- import { trackObjectMutations } from '#core/common/mutation-tracked-object.js';
5
- import { StancerRouteInaccessibleError } from '#error/endpoint/route-inaccessible-error.js';
6
- import { stubDeserialized, stubSerialized } from '#test/fixtures/endpoint.stub.js';
7
- import { StubEndpoint } from '#test/stub/stub-endpoint.js';
8
- import { randomString } from '#test/test-helper.js';
9
-
10
- vi.mock('#api/http/http.js', async (importHTTP) => {
11
- const original: Record<string, Promise<unknown>> = await importHTTP();
12
- return {
13
- ...original,
14
- transformResponseToData: vi.fn((value) => value.json()),
15
- };
16
- });
17
-
18
- vi.mock('#api/http/fetch-http-client.js', () => {
19
- return {
20
- httpClient: {
21
- makeRequest: vi.fn(() => {
22
- return Promise.resolve({
23
- status: 200,
24
- json: () => {
25
- return {
26
- ...stubSerialized,
27
- };
28
- },
29
- });
30
- }),
31
- },
32
- };
33
- });
34
-
35
- describe('endpoint object', () => {
36
- describe('handle resources', () => {
37
- const endpoint = new StubEndpoint();
38
-
39
- describe('deserialize resource', async () => {
40
- const deserializedResources = await endpoint.deserializeResource(stubSerialized);
41
-
42
- it('id', () => {
43
- expect(deserializedResources.id).toEqual(stubDeserialized.id);
44
- });
45
-
46
- it('default', () => {
47
- expect(deserializedResources.default).toEqual(stubDeserialized.default);
48
- });
49
-
50
- it('defaultNumber', () => {
51
- expect(deserializedResources.defaultNumber).toEqual(stubDeserialized.defaultNumber);
52
- });
53
-
54
- it('untouchable', () => {
55
- expect(Object.hasOwn(deserializedResources, 'untouchable')).toBeFalsy();
56
- });
57
-
58
- it('allAuthorized', () => {
59
- expect(Object.hasOwn(deserializedResources, 'allAuthorized')).toBeTruthy();
60
- expect(deserializedResources.allAuthorized).toBeTruthy();
61
- });
62
-
63
- it('ungettable', () => {
64
- expect(Object.hasOwn(deserializedResources, 'ungettable')).toBeFalsy();
65
- });
66
-
67
- it('unmodifiable', () => {
68
- expect(Object.hasOwn(deserializedResources, 'unmodifiable')).toBeTruthy();
69
- expect(deserializedResources.unmodifiable).toBeFalsy();
70
- });
71
-
72
- const getResourceviaConfig = await endpoint.config.deserializeResource(stubSerialized);
73
- expect(getResourceviaConfig).toStrictEqual(stubDeserialized);
74
- });
75
-
76
- describe('serialize for post', () => {
77
- const endpoint = new StubEndpoint();
78
- const postContent = { ...stubDeserialized, ungettable: true };
79
- const postedResource = endpoint.postObjectSerializer(postContent);
80
-
81
- it('id', () => {
82
- expect(postedResource.id).toBeUndefined();
83
- });
84
-
85
- it('default', () => {
86
- expect(postedResource.default).toEqual(stubSerialized.default);
87
- });
88
-
89
- it('defaultNumber', () => {
90
- expect(postedResource.default_number).toEqual(stubDeserialized.defaultNumber);
91
- });
92
-
93
- it('untouchable', () => {
94
- expect(Object.hasOwn(postedResource, 'untouchable')).toBeFalsy();
95
- });
96
-
97
- it('allAuthorized', () => {
98
- expect(Object.hasOwn(postedResource, 'all_authorized')).toBeTruthy();
99
- expect(postedResource.all_authorized).toBeTruthy();
100
- });
101
-
102
- it('ungettable', () => {
103
- expect(Object.hasOwn(postedResource, 'ungettable')).toBeTruthy();
104
- expect(postedResource.ungettable).toBeTruthy();
105
- });
106
-
107
- it('unmodifiable', () => {
108
- expect(Object.hasOwn(postedResource, 'unmodifiable')).toBeFalsy();
109
- });
110
- const postedResourceviaConfig = endpoint.config.postObjectSerializer(postContent);
111
- expect(postedResourceviaConfig).toStrictEqual(postedResource);
112
- });
113
-
114
- describe('serialize for patch', () => {
115
- const postedResource = endpoint.patchObjectSerializer({ ...stubDeserialized, ungettable: true });
116
-
117
- it('does not patch id', () => {
118
- expect(postedResource.id).toBeUndefined();
119
- });
120
-
121
- it('default', () => {
122
- expect(postedResource.default).toEqual(stubSerialized.default);
123
- });
124
-
125
- it('defaultNumber', () => {
126
- expect(postedResource.defaultNumber).toEqual(stubSerialized.defaultNumber);
127
- });
128
-
129
- it('untouchable', () => {
130
- expect(Object.hasOwn(postedResource, 'untouchable')).toBeFalsy();
131
- });
132
-
133
- it('allAuthorized', () => {
134
- expect(Object.hasOwn(postedResource, 'all_authorized')).toBeTruthy();
135
- expect(postedResource.all_authorized).toBeTruthy();
136
- });
137
-
138
- it('ungettable', () => {
139
- expect(Object.hasOwn(postedResource, 'ungettable')).toBeTruthy();
140
- expect(postedResource.ungettable).toBeTruthy();
141
- });
142
-
143
- it('unmodifiable', () => {
144
- expect(Object.hasOwn(postedResource, 'unmodifiable')).toBeFalsy();
145
- });
146
-
147
- const postedResourceviaConfig = endpoint.config.patchObjectSerializer({ ...stubDeserialized, ungettable: true }); // we don't really care for the type
148
- expect(postedResourceviaConfig).toStrictEqual(postedResource);
149
- });
150
- });
151
-
152
- it('have an endpoint url', () => {
153
- const endpoint = new StubEndpoint();
154
- const id = IdValue('stub_' + randomString(24, 24));
155
- expect(endpoint.endpointUrl(id)).toStrictEqual(`https://api.stancer.com/v2/stubs/${id}`);
156
- expect(endpoint.endpointUrl()).toStrictEqual('https://api.stancer.com/v2/stubs/');
157
- });
158
-
159
- describe('Action verbs', async () => {
160
- it('get', async () => {
161
- const endpoint = new StubEndpoint();
162
- const responseWithId = await endpoint.get(IdValue('stub_' + randomString(24)));
163
- expect(responseWithId).toStrictEqual({
164
- allAuthorized: true,
165
- default: stubDeserialized.default,
166
- defaultNumber: stubDeserialized.defaultNumber,
167
- id: stubDeserialized.id,
168
- unmodifiable: stubDeserialized.unmodifiable,
169
- });
170
- });
171
-
172
- it('post', async () => {
173
- const postableEndpoint = new StubEndpoint();
174
- const response = await postableEndpoint.post(stubSerialized);
175
- expect(response).toStrictEqual(stubDeserialized);
176
- const unpostableEndpoint = new StubEndpoint({ postable: false });
177
- expect(() => unpostableEndpoint.post(stubSerialized)).toThrow('POST is not allowed for stubs resource');
178
- });
179
-
180
- it('patch', async () => {
181
- const patchableEndpoint = new StubEndpoint();
182
- const response = await patchableEndpoint.patch(stubSerialized.id, stubSerialized);
183
- expect(response).toStrictEqual(stubDeserialized);
184
- const unpatchableEndpoint = new StubEndpoint({ patchable: false });
185
- expect(() => unpatchableEndpoint.patch(stubSerialized.id, stubSerialized)).toThrow(
186
- 'PATCH is not allowed for stubs resource',
187
- );
188
- });
189
-
190
- it('delete', async () => {
191
- const endpoint = new StubEndpoint();
192
- const responseWithId = await endpoint.delete(stubSerialized.id);
193
- expect(responseWithId).toStrictEqual({
194
- allAuthorized: true,
195
- default: stubSerialized.default,
196
- defaultNumber: stubDeserialized.defaultNumber,
197
- id: stubSerialized.id,
198
- unmodifiable: stubSerialized.unmodifiable,
199
- });
200
- const undeletableEndpoint = new StubEndpoint({ deletable: false });
201
- expect(() => undeletableEndpoint.delete(stubSerialized.id)).toThrow('DELETE is not allowed for stubs resource');
202
- });
203
-
204
- describe('send', () => {
205
- it("cannot send if it has no id and it isn't postable", async () => {
206
- const endpoint = new StubEndpoint({ postable: false });
207
- const mutationsData = trackObjectMutations({}, () => true);
208
- mutationsData['default'] = 'stub_' + randomString(24);
209
- expect(() => endpoint.send(undefined, mutationsData)).toThrow(StancerRouteInaccessibleError);
210
- });
211
-
212
- it('can patch if id', () => {
213
- const endpoint = new StubEndpoint();
214
- const spyonPatch = vi.spyOn(endpoint, 'patch');
215
- const spyonPost = vi.spyOn(endpoint, 'post');
216
- const mutationsData = trackObjectMutations({}, () => true);
217
- mutationsData['id'] = 'stub_' + randomString(24);
218
- mutationsData['defaultNumber'] = 12;
219
- endpoint.send(mutationsData['id'], mutationsData.getMutations());
220
- expect(spyonPatch).toHaveBeenCalledOnce();
221
- expect(spyonPost).toHaveBeenCalledTimes(0);
222
- });
223
-
224
- it('can post if no id', () => {
225
- const endpoint = new StubEndpoint();
226
- const spyonPatch = vi.spyOn(endpoint, 'patch');
227
- const spyonPost = vi.spyOn(endpoint, 'post');
228
- const mutationsData = trackObjectMutations({}, () => true);
229
- mutationsData['default'] = randomString(24);
230
- endpoint.send(undefined, mutationsData);
231
- expect(spyonPatch).toHaveBeenCalledTimes(0);
232
- expect(spyonPost).toHaveBeenCalledTimes(1);
233
- });
234
- });
235
- });
236
- });
@@ -1,86 +0,0 @@
1
- import { describe, expect, it, vi } from 'vitest';
2
-
3
- import { Configuration } from '#api/configuration.js';
4
- import ListEndpointFixtures from '#test/fixtures/list-endpoint.stub.js';
5
- import { StubEndpoint } from '#test/stub/stub-endpoint.js';
6
- import { randomNumber, randomString } from '#test/test-helper.js';
7
-
8
- vi.mock('../../../src/http/http.js', async (importHTTP) => {
9
- const original: Record<string, Promise<unknown>> = await importHTTP();
10
- return {
11
- ...original,
12
- transformResponseToData: vi.fn((value) => value.json()),
13
- };
14
- });
15
- vi.mock('#api/http/fetch-http-client.js', () => {
16
- return {
17
- httpClient: {
18
- makeRequest: vi.fn(() => {
19
- return Promise.resolve({
20
- status: 200,
21
- json: () => {
22
- return {
23
- ...ListEndpointFixtures,
24
- };
25
- },
26
- });
27
- }),
28
- },
29
- };
30
- });
31
-
32
- describe('stub list', () => {
33
- it('does not start if unlistable', async () => {
34
- const unListableEndpoint = new StubEndpoint({ listable: false });
35
- expect(unListableEndpoint.listable).toBeFalsy();
36
- expect(() => unListableEndpoint.list({})).toThrow('LIST is not allowed for stubs resource');
37
- });
38
-
39
- it('list correctly fixtured objects', async () => {
40
- const endpoint = new StubEndpoint();
41
- const generator = endpoint.list({ limit: 2 });
42
- const item1 = await generator.next();
43
- expect(item1.done).toBe(false);
44
- expect(item1.value).toHaveProperty('id');
45
- const item2 = await generator.next();
46
- expect(item2.done).toBe(false);
47
- expect(item1.value).toHaveProperty('id');
48
- const item3 = await generator.next();
49
- expect(item3.done).toBe(true);
50
- });
51
-
52
- it('iterate correctly', async () => {
53
- const endpoint = new StubEndpoint();
54
- const generator = endpoint.list({});
55
- for (const item in generator) {
56
- expect(item).toHaveProperty('id');
57
- }
58
- });
59
- });
60
-
61
- describe('create URL', () => {
62
- it('return simple stubUrl', () => {
63
- const endpoint = new StubEndpoint();
64
- const url = endpoint.createListUrl(endpoint._endpointBaseUrl, { start: 0, limit: 100, filters: {} });
65
- expect(url).toBeTypeOf('object');
66
- expect(url).toBeInstanceOf(URL);
67
- expect(url.toString()).toBe('https://api.stancer.com/v2/stubs/?start=0&limit=100');
68
- });
69
-
70
- it('return complex url', () => {
71
- const endpoint = new StubEndpoint();
72
- const endpointUrl = randomString(10, 20);
73
- const limit = randomNumber(1, 100);
74
- const start = randomNumber(1, 20);
75
- const filters = {
76
- filter1: randomString(10, 20),
77
- filter2: randomString(10, 20),
78
- };
79
- const url = endpoint.createListUrl(`${Configuration.baseUrl}/${endpointUrl}`, { limit, start, filters });
80
- expect(url).toBeTypeOf('object');
81
- expect(url).toBeInstanceOf(URL);
82
- expect(url.toString()).toBe(
83
- `https://api.stancer.com/v2/${endpointUrl}/?start=${start}&limit=${limit}&filter1=${filters.filter1}&filter2=${filters.filter2}`,
84
- );
85
- });
86
- });