@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.
- package/CHANGELOG.md +23 -2
- package/dist/address/api-endpoint.d.ts +20 -0
- package/dist/address/api-endpoint.d.ts.map +1 -0
- package/dist/address/api-endpoint.js +28 -0
- package/dist/address/api-endpoint.js.map +1 -0
- package/dist/address/model.d.ts +35 -0
- package/dist/address/model.d.ts.map +1 -0
- package/dist/address/model.js +63 -0
- package/dist/address/model.js.map +1 -0
- package/dist/address/repository.d.ts +7 -0
- package/dist/address/repository.d.ts.map +1 -0
- package/dist/address/repository.js +14 -0
- package/dist/address/repository.js.map +1 -0
- package/dist/address/validator.d.ts +4 -0
- package/dist/address/validator.d.ts.map +1 -0
- package/dist/address/validator.js +32 -0
- package/dist/address/validator.js.map +1 -0
- package/dist/api-endpoint/abstract-api-endpoint.d.ts +46 -0
- package/dist/api-endpoint/abstract-api-endpoint.d.ts.map +1 -0
- package/dist/api-endpoint/abstract-api-endpoint.js +220 -0
- package/dist/api-endpoint/abstract-api-endpoint.js.map +1 -0
- package/dist/api-endpoint/configuration.d.ts +34 -0
- package/dist/api-endpoint/configuration.d.ts.map +1 -0
- package/dist/api-endpoint/configuration.js +99 -0
- package/dist/api-endpoint/configuration.js.map +1 -0
- package/dist/api-endpoint/http/fetch-http-client.d.ts +3 -0
- package/dist/api-endpoint/http/fetch-http-client.d.ts.map +1 -0
- package/dist/api-endpoint/http/fetch-http-client.js +34 -0
- package/dist/api-endpoint/http/fetch-http-client.js.map +1 -0
- package/dist/api-endpoint/http/http.d.ts +18 -0
- package/dist/api-endpoint/http/http.d.ts.map +1 -0
- package/dist/api-endpoint/http/http.js +47 -0
- package/dist/api-endpoint/http/http.js.map +1 -0
- package/dist/api-endpoint/http/index.d.ts +3 -0
- package/dist/api-endpoint/http/index.d.ts.map +1 -0
- package/dist/api-endpoint/http/index.js +3 -0
- package/dist/api-endpoint/http/index.js.map +1 -0
- package/dist/api-endpoint/version.d.ts +5 -0
- package/dist/api-endpoint/version.d.ts.map +1 -0
- package/dist/api-endpoint/version.js +6 -0
- package/dist/api-endpoint/version.js.map +1 -0
- package/dist/card/api-endpoint.d.ts +28 -0
- package/dist/card/api-endpoint.d.ts.map +1 -0
- package/dist/card/api-endpoint.js +37 -0
- package/dist/card/api-endpoint.js.map +1 -0
- package/dist/card/enum/funding.d.ts +3 -0
- package/dist/card/enum/funding.d.ts.map +1 -0
- package/dist/card/enum/funding.js +10 -0
- package/dist/card/enum/funding.js.map +1 -0
- package/dist/card/enum/nature.d.ts +3 -0
- package/dist/card/enum/nature.d.ts.map +1 -0
- package/dist/card/enum/nature.js +6 -0
- package/dist/card/enum/nature.js.map +1 -0
- package/dist/card/enum/network.d.ts +5 -0
- package/dist/card/enum/network.d.ts.map +1 -0
- package/dist/card/enum/network.js +12 -0
- package/dist/card/enum/network.js.map +1 -0
- package/dist/card/model.d.ts +55 -0
- package/dist/card/model.d.ts.map +1 -0
- package/dist/card/model.js +90 -0
- package/dist/card/model.js.map +1 -0
- package/dist/card/repository.d.ts +7 -0
- package/dist/card/repository.d.ts.map +1 -0
- package/dist/card/repository.js +10 -0
- package/dist/card/repository.js.map +1 -0
- package/dist/card/validator.d.ts +8 -0
- package/dist/card/validator.d.ts.map +1 -0
- package/dist/card/validator.js +71 -0
- package/dist/card/validator.js.map +1 -0
- package/dist/core/abstract-model.d.ts +51 -0
- package/dist/core/abstract-model.d.ts.map +1 -0
- package/dist/core/abstract-model.js +93 -0
- package/dist/core/abstract-model.js.map +1 -0
- package/dist/core/abstract-repository.d.ts +86 -0
- package/dist/core/abstract-repository.d.ts.map +1 -0
- package/dist/core/abstract-repository.js +97 -0
- package/dist/core/abstract-repository.js.map +1 -0
- package/dist/core/common/branded-type.d.ts +6 -0
- package/dist/core/common/branded-type.d.ts.map +1 -0
- package/dist/core/common/branded-type.js +9 -0
- package/dist/core/common/branded-type.js.map +1 -0
- package/dist/core/common/handler/date-handler.d.ts +5 -0
- package/dist/core/common/handler/date-handler.d.ts.map +1 -0
- package/dist/core/common/handler/date-handler.js +23 -0
- package/dist/core/common/handler/date-handler.js.map +1 -0
- package/dist/core/common/handler/enum-handler.d.ts +3 -0
- package/dist/core/common/handler/enum-handler.d.ts.map +1 -0
- package/dist/core/common/handler/enum-handler.js +14 -0
- package/dist/core/common/handler/enum-handler.js.map +1 -0
- package/dist/core/common/handler/handler.d.ts +24 -0
- package/dist/core/common/handler/handler.d.ts.map +1 -0
- package/dist/core/common/handler/handler.js +33 -0
- package/dist/core/common/handler/handler.js.map +1 -0
- package/dist/core/common/handler/id-handler.d.ts +4 -0
- package/dist/core/common/handler/id-handler.d.ts.map +1 -0
- package/dist/core/common/handler/id-handler.js +21 -0
- package/dist/core/common/handler/id-handler.js.map +1 -0
- package/dist/core/common/handler/metadata-handler.d.ts +18 -0
- package/dist/core/common/handler/metadata-handler.d.ts.map +1 -0
- package/dist/core/common/handler/metadata-handler.js +19 -0
- package/dist/core/common/handler/metadata-handler.js.map +1 -0
- package/dist/core/common/id-validator.d.ts +10 -0
- package/dist/core/common/id-validator.d.ts.map +1 -0
- package/dist/core/common/id-validator.js +17 -0
- package/dist/core/common/id-validator.js.map +1 -0
- package/dist/core/common/mutation-tracked-object.d.ts +8 -0
- package/dist/core/common/mutation-tracked-object.d.ts.map +1 -0
- package/dist/core/common/mutation-tracked-object.js +38 -0
- package/dist/core/common/mutation-tracked-object.js.map +1 -0
- package/dist/core/endpoint-interface.d.ts +38 -0
- package/dist/core/endpoint-interface.d.ts.map +1 -0
- package/dist/core/endpoint-interface.js +2 -0
- package/dist/core/endpoint-interface.js.map +1 -0
- package/dist/core/error/base-error.d.ts +3 -0
- package/dist/core/error/base-error.d.ts.map +1 -0
- package/dist/core/error/base-error.js +3 -0
- package/dist/core/error/base-error.js.map +1 -0
- package/dist/core/error/endpoint/api/api-conflict-error.d.ts +5 -0
- package/dist/core/error/endpoint/api/api-conflict-error.d.ts.map +1 -0
- package/dist/core/error/endpoint/api/api-conflict-error.js +7 -0
- package/dist/core/error/endpoint/api/api-conflict-error.js.map +1 -0
- package/dist/core/error/endpoint/api/api-error.d.ts +6 -0
- package/dist/core/error/endpoint/api/api-error.d.ts.map +1 -0
- package/dist/core/error/endpoint/api/api-error.js +9 -0
- package/dist/core/error/endpoint/api/api-error.js.map +1 -0
- package/dist/core/error/endpoint/api/api-not-found-error.d.ts +5 -0
- package/dist/core/error/endpoint/api/api-not-found-error.d.ts.map +1 -0
- package/dist/core/error/endpoint/api/api-not-found-error.js +7 -0
- package/dist/core/error/endpoint/api/api-not-found-error.js.map +1 -0
- package/dist/core/error/endpoint/api/api-unauthorized-error.d.ts +5 -0
- package/dist/core/error/endpoint/api/api-unauthorized-error.d.ts.map +1 -0
- package/dist/core/error/endpoint/api/api-unauthorized-error.js +7 -0
- package/dist/core/error/endpoint/api/api-unauthorized-error.js.map +1 -0
- package/dist/core/error/endpoint/api/api-unknown-error.d.ts +5 -0
- package/dist/core/error/endpoint/api/api-unknown-error.d.ts.map +1 -0
- package/dist/core/error/endpoint/api/api-unknown-error.js +7 -0
- package/dist/core/error/endpoint/api/api-unknown-error.js.map +1 -0
- package/dist/core/error/endpoint/api/api-validation-error.d.ts +11 -0
- package/dist/core/error/endpoint/api/api-validation-error.d.ts.map +1 -0
- package/dist/core/error/endpoint/api/api-validation-error.js +9 -0
- package/dist/core/error/endpoint/api/api-validation-error.js.map +1 -0
- package/dist/core/error/endpoint/api/index.d.ts +7 -0
- package/dist/core/error/endpoint/api/index.d.ts.map +1 -0
- package/dist/core/error/endpoint/api/index.js +7 -0
- package/dist/core/error/endpoint/api/index.js.map +1 -0
- package/dist/core/error/endpoint/route-inaccessible-error.d.ts +5 -0
- package/dist/core/error/endpoint/route-inaccessible-error.d.ts.map +1 -0
- package/dist/core/error/endpoint/route-inaccessible-error.js +8 -0
- package/dist/core/error/endpoint/route-inaccessible-error.js.map +1 -0
- package/dist/core/error/unpopulated-error.d.ts +4 -0
- package/dist/core/error/unpopulated-error.d.ts.map +1 -0
- package/dist/core/error/unpopulated-error.js +4 -0
- package/dist/core/error/unpopulated-error.js.map +1 -0
- package/dist/core/error/unsendable-error.d.ts +4 -0
- package/dist/core/error/unsendable-error.d.ts.map +1 -0
- package/dist/core/error/unsendable-error.js +4 -0
- package/dist/core/error/unsendable-error.js.map +1 -0
- package/dist/core/error/validation-error.d.ts +4 -0
- package/dist/core/error/validation-error.d.ts.map +1 -0
- package/dist/core/error/validation-error.js +4 -0
- package/dist/core/error/validation-error.js.map +1 -0
- package/dist/core/validator.d.ts +63 -0
- package/dist/core/validator.d.ts.map +1 -0
- package/dist/core/validator.js +73 -0
- package/dist/core/validator.js.map +1 -0
- package/dist/customer/api-endpoint.d.ts +21 -0
- package/dist/customer/api-endpoint.d.ts.map +1 -0
- package/dist/customer/api-endpoint.js +27 -0
- package/dist/customer/api-endpoint.js.map +1 -0
- package/dist/customer/model.d.ts +39 -0
- package/dist/customer/model.d.ts.map +1 -0
- package/dist/customer/model.js +73 -0
- package/dist/customer/model.js.map +1 -0
- package/dist/customer/repository.d.ts +7 -0
- package/dist/customer/repository.d.ts.map +1 -0
- package/dist/customer/repository.js +10 -0
- package/dist/customer/repository.js.map +1 -0
- package/dist/customer/validator.d.ts +4 -0
- package/dist/customer/validator.d.ts.map +1 -0
- package/dist/customer/validator.js +23 -0
- package/dist/customer/validator.js.map +1 -0
- package/dist/event/model.d.ts +20 -0
- package/dist/event/model.d.ts.map +1 -0
- package/dist/event/model.js +30 -0
- package/dist/event/model.js.map +1 -0
- package/dist/payment/api-endpoint.d.ts +51 -0
- package/dist/payment/api-endpoint.d.ts.map +1 -0
- package/dist/payment/api-endpoint.js +110 -0
- package/dist/payment/api-endpoint.js.map +1 -0
- package/dist/payment/enum/currency.d.ts +3 -0
- package/dist/payment/enum/currency.d.ts.map +1 -0
- package/dist/payment/enum/currency.js +13 -0
- package/dist/payment/enum/currency.js.map +1 -0
- package/dist/payment/enum/method.d.ts +3 -0
- package/dist/payment/enum/method.d.ts.map +1 -0
- package/dist/payment/enum/method.js +2 -0
- package/dist/payment/enum/method.js.map +1 -0
- package/dist/payment/enum/status.d.ts +4 -0
- package/dist/payment/enum/status.d.ts.map +1 -0
- package/dist/payment/enum/status.js +19 -0
- package/dist/payment/enum/status.js.map +1 -0
- package/dist/payment/model.d.ts +135 -0
- package/dist/payment/model.d.ts.map +1 -0
- package/dist/payment/model.js +232 -0
- package/dist/payment/model.js.map +1 -0
- package/dist/payment/repository.d.ts +17 -0
- package/dist/payment/repository.d.ts.map +1 -0
- package/dist/payment/repository.js +56 -0
- package/dist/payment/repository.js.map +1 -0
- package/dist/payment/validator.d.ts +16 -0
- package/dist/payment/validator.d.ts.map +1 -0
- package/dist/payment/validator.js +81 -0
- package/dist/payment/validator.js.map +1 -0
- package/dist/payment-intent/api-endpoint.d.ts +63 -0
- package/dist/payment-intent/api-endpoint.d.ts.map +1 -0
- package/dist/payment-intent/api-endpoint.js +95 -0
- package/dist/payment-intent/api-endpoint.js.map +1 -0
- package/dist/payment-intent/enum/status.d.ts +5 -0
- package/dist/payment-intent/enum/status.d.ts.map +1 -0
- package/dist/payment-intent/enum/status.js +20 -0
- package/dist/payment-intent/enum/status.js.map +1 -0
- package/dist/payment-intent/enum/threeds.d.ts +3 -0
- package/dist/payment-intent/enum/threeds.d.ts.map +1 -0
- package/dist/payment-intent/enum/threeds.js +2 -0
- package/dist/payment-intent/enum/threeds.js.map +1 -0
- package/dist/payment-intent/model.d.ts +91 -0
- package/dist/payment-intent/model.d.ts.map +1 -0
- package/dist/payment-intent/model.js +183 -0
- package/dist/payment-intent/model.js.map +1 -0
- package/dist/payment-intent/repository.d.ts +13 -0
- package/dist/payment-intent/repository.d.ts.map +1 -0
- package/dist/payment-intent/repository.js +65 -0
- package/dist/payment-intent/repository.js.map +1 -0
- package/dist/payment-intent/validator.d.ts +4 -0
- package/dist/payment-intent/validator.d.ts.map +1 -0
- package/dist/payment-intent/validator.js +38 -0
- package/dist/payment-intent/validator.js.map +1 -0
- package/dist/payout/model.d.ts +7 -0
- package/dist/payout/model.d.ts.map +1 -0
- package/dist/payout/model.js +6 -0
- package/dist/payout/model.js.map +1 -0
- package/dist/refund/api-endpoint.d.ts +22 -0
- package/dist/refund/api-endpoint.d.ts.map +1 -0
- package/dist/refund/api-endpoint.js +32 -0
- package/dist/refund/api-endpoint.js.map +1 -0
- package/dist/refund/enum/refund-status.d.ts +3 -0
- package/dist/refund/enum/refund-status.d.ts.map +1 -0
- package/dist/refund/enum/refund-status.js +10 -0
- package/dist/refund/enum/refund-status.js.map +1 -0
- package/dist/refund/model.d.ts +38 -0
- package/dist/refund/model.d.ts.map +1 -0
- package/dist/refund/model.js +51 -0
- package/dist/refund/model.js.map +1 -0
- package/dist/refund/repository.d.ts +7 -0
- package/dist/refund/repository.d.ts.map +1 -0
- package/dist/refund/repository.js +10 -0
- package/dist/refund/repository.js.map +1 -0
- package/dist/refund/validator.d.ts +4 -0
- package/dist/refund/validator.d.ts.map +1 -0
- package/dist/refund/validator.js +41 -0
- package/dist/refund/validator.js.map +1 -0
- package/dist/sepa/api-endpoint.d.ts +19 -0
- package/dist/sepa/api-endpoint.d.ts.map +1 -0
- package/dist/sepa/api-endpoint.js +25 -0
- package/dist/sepa/api-endpoint.js.map +1 -0
- package/dist/sepa/model.d.ts +32 -0
- package/dist/sepa/model.d.ts.map +1 -0
- package/dist/sepa/model.js +53 -0
- package/dist/sepa/model.js.map +1 -0
- package/dist/sepa/repository.d.ts +7 -0
- package/dist/sepa/repository.d.ts.map +1 -0
- package/dist/sepa/repository.js +10 -0
- package/dist/sepa/repository.js.map +1 -0
- package/dist/sepa/validator.d.ts +8 -0
- package/dist/sepa/validator.d.ts.map +1 -0
- package/dist/sepa/validator.js +47 -0
- package/dist/sepa/validator.js.map +1 -0
- package/dist/webhook/api-endpoint.d.ts +16 -0
- package/dist/webhook/api-endpoint.d.ts.map +1 -0
- package/dist/webhook/api-endpoint.js +33 -0
- package/dist/webhook/api-endpoint.js.map +1 -0
- package/dist/webhook/model.d.ts +35 -0
- package/dist/webhook/model.d.ts.map +1 -0
- package/dist/webhook/model.js +110 -0
- package/dist/webhook/model.js.map +1 -0
- package/dist/webhook/repository.d.ts +7 -0
- package/dist/webhook/repository.d.ts.map +1 -0
- package/dist/webhook/repository.js +10 -0
- package/dist/webhook/repository.js.map +1 -0
- package/dist/webhook/validator.d.ts +4 -0
- package/dist/webhook/validator.d.ts.map +1 -0
- package/dist/webhook/validator.js +16 -0
- package/dist/webhook/validator.js.map +1 -0
- package/package.json +4 -2
- package/src/api-endpoint/http/fetch-http-client.ts +8 -1
- package/src/core/common/handler/metadata-handler.ts +19 -0
- package/src/event/model.ts +42 -0
- package/src/payment-intent/api-endpoint.ts +2 -1
- package/src/payment-intent/model.ts +8 -3
- package/src/webhook/api-endpoint.ts +36 -0
- package/src/webhook/model.ts +140 -0
- package/src/webhook/repository.ts +14 -0
- package/src/webhook/validator.ts +18 -0
- package/.editorconfig +0 -14
- package/.gitlab-ci.yml +0 -159
- package/.prettierignore +0 -3
- package/eslint.config.js +0 -14
- package/pnpm-workspace.yaml +0 -19
- package/prettier.config.js +0 -3
- package/test/fixtures/endpoint.stub.ts +0 -22
- package/test/fixtures/list-endpoint.stub.ts +0 -33
- package/test/fixtures/list-model.stub.ts +0 -24
- package/test/fixtures/model.stub.ts +0 -12
- package/test/functional/address.test.ts +0 -126
- package/test/functional/card.test.ts +0 -175
- package/test/functional/customer.test.ts +0 -174
- package/test/functional/payment-intent.test.ts +0 -215
- package/test/functional/payment.test.ts +0 -206
- package/test/functional/refund.test.ts +0 -112
- package/test/functional/sepa.test.ts +0 -136
- package/test/integration/stub-integration.test.ts +0 -88
- package/test/stub/stub-endpoint.ts +0 -42
- package/test/stub/stub-model.ts +0 -82
- package/test/stub/stub-repository.ts +0 -11
- package/test/test-helper.ts +0 -133
- package/test/unit/address/api-endpoint.test.ts +0 -134
- package/test/unit/address/fixtures.ts +0 -60
- package/test/unit/address/model.test.ts +0 -75
- package/test/unit/address/repository.test.ts +0 -148
- package/test/unit/address/validator.test.ts +0 -49
- package/test/unit/api-endpoint/http/fetch-http-client.test.ts +0 -44
- package/test/unit/api-endpoint/http/http.test.ts +0 -152
- package/test/unit/card/api-endpoint.test.ts +0 -170
- package/test/unit/card/card-helper.ts +0 -116
- package/test/unit/card/fixtures.ts +0 -87
- package/test/unit/card/model.test.ts +0 -167
- package/test/unit/card/repository.test.ts +0 -146
- package/test/unit/card/validator.test.ts +0 -96
- package/test/unit/core/common/mutation-tracked-object.test.ts +0 -24
- package/test/unit/customer/api-endpoint.test.ts +0 -143
- package/test/unit/customer/fixtures.ts +0 -73
- package/test/unit/customer/model.test.ts +0 -90
- package/test/unit/customer/repository.test.ts +0 -148
- package/test/unit/customer/validator.test.ts +0 -62
- package/test/unit/payment/api-endpoint.test.ts +0 -188
- package/test/unit/payment/fixtures.ts +0 -116
- package/test/unit/payment/model.test.ts +0 -240
- package/test/unit/payment/repository.test.ts +0 -270
- package/test/unit/payment/validator.test.ts +0 -137
- package/test/unit/payment-intent/api-endpoint.test.ts +0 -142
- package/test/unit/payment-intent/fixtures.ts +0 -94
- package/test/unit/payment-intent/model.test.ts +0 -157
- package/test/unit/payment-intent/repository.test.ts +0 -263
- package/test/unit/payment-intent/validator.test.ts +0 -136
- package/test/unit/refund/api-endpoint.test.ts +0 -129
- package/test/unit/refund/fixtures.ts +0 -58
- package/test/unit/refund/model.test.ts +0 -89
- package/test/unit/refund/repository.test.ts +0 -157
- package/test/unit/refund/validator.test.ts +0 -89
- package/test/unit/sepa/api-endpoint.test.ts +0 -170
- package/test/unit/sepa/fixture.ts +0 -62
- package/test/unit/sepa/model.test.ts +0 -86
- package/test/unit/sepa/repository.test.ts +0 -149
- package/test/unit/sepa/sepa-helper.ts +0 -71
- package/test/unit/sepa/validator.test.ts +0 -58
- package/test/unit/stub/stub-endpoint.test.ts +0 -236
- package/test/unit/stub/stub-list-endpoint.test.ts +0 -86
- package/test/unit/stub/stub-model.test.ts +0 -111
- package/test/unit/stub/stub-repository.test.ts +0 -144
- package/tsconfig.json +0 -50
- package/vitest.config.ts +0 -20
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { Temporal } from 'temporal-polyfill';
|
|
2
|
-
|
|
3
|
-
import { Currency } from '#payment/enum/currency-enum.js';
|
|
4
|
-
import { IdPayment, PaymentModel } from '#payment/model.js';
|
|
5
|
-
import { refundAmount } from '#refund/model.js';
|
|
6
|
-
import { randomMonth, randomNumber, randomString } from '#test/test-helper.js';
|
|
7
|
-
|
|
8
|
-
import { IdPaymentIntent } from '../../../src/payment-intent/model.js';
|
|
9
|
-
|
|
10
|
-
const id = `refd_${randomString(24)}`;
|
|
11
|
-
const amount = randomNumber(1, 50000);
|
|
12
|
-
const currency: Currency = 'eur';
|
|
13
|
-
const date_bank = `${randomNumber(1971, 2025)}-${randomMonth().toString().padStart(2, '0')}-${randomNumber(1, 28).toString().padStart(2, '0')}`;
|
|
14
|
-
const date_refund = `${randomNumber(1971, 2025)}-${randomMonth().toString().padStart(2, '0')}-${randomNumber(1, 28).toString().padStart(2, '0')}`;
|
|
15
|
-
const payment_intent = `pi_${randomString(24)}`;
|
|
16
|
-
const payment = new PaymentModel({}, `paym_${randomString(24)}`);
|
|
17
|
-
const paymentID = payment.id as IdPayment;
|
|
18
|
-
const created = randomNumber(786460000, 1000000000);
|
|
19
|
-
|
|
20
|
-
const status = 'to_refund';
|
|
21
|
-
const payout = `pout_${randomString(24)}`;
|
|
22
|
-
|
|
23
|
-
export const endpointResource = {
|
|
24
|
-
id,
|
|
25
|
-
amount,
|
|
26
|
-
currency,
|
|
27
|
-
date_bank,
|
|
28
|
-
date_refund,
|
|
29
|
-
payment_intent,
|
|
30
|
-
payment: paymentID,
|
|
31
|
-
created,
|
|
32
|
-
status,
|
|
33
|
-
payout,
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export const creationResource = {
|
|
37
|
-
amount: refundAmount(amount),
|
|
38
|
-
currency,
|
|
39
|
-
createdAt: Temporal.Instant.fromEpochMilliseconds(created * 1000),
|
|
40
|
-
dateBank: Temporal.PlainDate.from(date_bank),
|
|
41
|
-
dateRefund: Temporal.PlainDate.from(date_refund),
|
|
42
|
-
paymentIntent: payment_intent as IdPaymentIntent,
|
|
43
|
-
payment,
|
|
44
|
-
status,
|
|
45
|
-
payout,
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export const endpointResourceDeserialized = {
|
|
49
|
-
id,
|
|
50
|
-
...creationResource,
|
|
51
|
-
payment: paymentID,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export const listResource = [
|
|
55
|
-
{ ...creationResource, id: `refd_${randomString(21)}one`, amount: 50 },
|
|
56
|
-
{ ...creationResource, id: `refd_${randomString(21)}two`, amount: 50 },
|
|
57
|
-
{ ...creationResource, id: `refd_${randomString(19)}three`, amount: 50 },
|
|
58
|
-
];
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { Temporal } from 'temporal-polyfill';
|
|
2
|
-
import { describe, it } from 'vitest';
|
|
3
|
-
|
|
4
|
-
import { Currency, CurrencyEnum } from '#payment/enum/currency.js';
|
|
5
|
-
import { IdPayment, PaymentModel, idPayment } from '#payment/model.js';
|
|
6
|
-
import { RefundStatus, RefundStatusEnum } from '#refund/enum/refund-status.js';
|
|
7
|
-
import { RefundAmount, RefundModel, refundAmount } from '#refund/model.js';
|
|
8
|
-
import { SetterGetter, SetterGetterId, randomNumber, randomString } from '#test/test-helper.js';
|
|
9
|
-
|
|
10
|
-
import { IdPaymentIntent } from '../../../src/payment-intent/model';
|
|
11
|
-
import { IdPayout } from '../../../src/payout/model';
|
|
12
|
-
|
|
13
|
-
describe('Setter & Getter', () => {
|
|
14
|
-
const refund = new RefundModel({});
|
|
15
|
-
|
|
16
|
-
it('id', () => {
|
|
17
|
-
SetterGetterId((value: IdPayment) => new RefundModel({}, value), 'refd_' + randomString(24));
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('amount', () => {
|
|
21
|
-
SetterGetter(
|
|
22
|
-
(value: RefundAmount) => refund.setAmount(value),
|
|
23
|
-
() => refund.amount,
|
|
24
|
-
refundAmount(randomNumber(50, 2000000)),
|
|
25
|
-
);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('payment', () => {
|
|
29
|
-
SetterGetter(
|
|
30
|
-
(value: PaymentModel) => refund.setPayment(value),
|
|
31
|
-
() => refund.payment,
|
|
32
|
-
new PaymentModel({}),
|
|
33
|
-
);
|
|
34
|
-
refund._data.payment = null;
|
|
35
|
-
SetterGetter(
|
|
36
|
-
(value: string) => refund.setPayment(value),
|
|
37
|
-
() => refund.payment,
|
|
38
|
-
idPayment('paym_' + randomString(24)),
|
|
39
|
-
);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('currency', () => {
|
|
43
|
-
SetterGetter(
|
|
44
|
-
(value: Currency) => (refund._data.currency = value),
|
|
45
|
-
() => refund.currency,
|
|
46
|
-
CurrencyEnum[randomNumber(0, CurrencyEnum.length - 1)],
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('dateBank', () => {
|
|
51
|
-
SetterGetter(
|
|
52
|
-
(value: Temporal.PlainDate) => (refund._data.dateBank = value),
|
|
53
|
-
() => refund.dateBank,
|
|
54
|
-
Temporal.Now.plainDateISO(),
|
|
55
|
-
);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('dateRefund', () => {
|
|
59
|
-
SetterGetter(
|
|
60
|
-
(value: Temporal.PlainDate) => (refund._data.dateRefund = value),
|
|
61
|
-
() => refund.dateRefund,
|
|
62
|
-
Temporal.Now.plainDateISO(),
|
|
63
|
-
);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('paymentIntent', () => {
|
|
67
|
-
SetterGetter(
|
|
68
|
-
(value: IdPaymentIntent) => (refund._data.paymentIntent = value),
|
|
69
|
-
() => refund.paymentIntent,
|
|
70
|
-
('pi_' + randomString(24)) as IdPaymentIntent,
|
|
71
|
-
);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('Payout', () => {
|
|
75
|
-
SetterGetter(
|
|
76
|
-
(value: IdPayout) => (refund._data.payout = value),
|
|
77
|
-
() => refund.payout,
|
|
78
|
-
('pout_' + randomString(24)) as IdPayout,
|
|
79
|
-
);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('status', () => {
|
|
83
|
-
SetterGetter(
|
|
84
|
-
(value: RefundStatus) => (refund._data.status = value),
|
|
85
|
-
() => refund.status,
|
|
86
|
-
RefundStatusEnum[randomNumber(0, RefundStatusEnum.length - 1)],
|
|
87
|
-
);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
@@ -1,157 +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 { RefundApiEndpoint } from '#refund/api-endpoint.js';
|
|
7
|
-
import { IdRefund, RefundModel } from '#refund/model.js';
|
|
8
|
-
import { RefundRepository } from '#refund/repository.js';
|
|
9
|
-
import { refundValidator } from '#refund/validator.js';
|
|
10
|
-
import { randomString } from '#test/test-helper.js';
|
|
11
|
-
|
|
12
|
-
import { creationResource, endpointResource, listResource } from './fixtures.js';
|
|
13
|
-
|
|
14
|
-
const idPrefix = 'refd';
|
|
15
|
-
const id = `${idPrefix}_${randomString(24)}` as IdRefund;
|
|
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 creationResource;
|
|
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 creationResource;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
it('can be instanciated', () => {
|
|
55
|
-
const instance = new RefundRepository();
|
|
56
|
-
expect(instance).toBeInstanceOf(RefundRepository);
|
|
57
|
-
expect(instance).toBeInstanceOf(AbstractRepository);
|
|
58
|
-
//accessing private method & property
|
|
59
|
-
expect(instance.endpoint).toBeInstanceOf(RefundApiEndpoint);
|
|
60
|
-
expect(instance.validator).toBe(refundValidator);
|
|
61
|
-
expect(instance.staticModel).toBe(RefundModel);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
describe('repository', () => {
|
|
65
|
-
const mockRepo = new MockApiEndpoint() as unknown as RefundApiEndpoint; // I lie, for convenience sake
|
|
66
|
-
const repository = new RefundRepository(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(RefundModel);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('delete', async () => {
|
|
82
|
-
const modelWithoutId = await repository.create();
|
|
83
|
-
await expect(() => repository.delete(modelWithoutId)).rejects.toThrow();
|
|
84
|
-
|
|
85
|
-
const model = await repository.create({ id: endpointResource.id, ...creationResource });
|
|
86
|
-
await expect((await repository.delete(model))._data).toStrictEqual(creationResource);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe('send', () => {
|
|
90
|
-
it('should return model', async () => {
|
|
91
|
-
const model = await repository.create(creationResource);
|
|
92
|
-
const sentModel = await repository.send(model);
|
|
93
|
-
expect(sentModel).toStrictEqual(model);
|
|
94
|
-
expect(sentModel._data.id).toEqual(dataHasBeenSentId);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('should throw on inprecise error', async () => {
|
|
98
|
-
const model = await repository.create({ ...creationResource, id: stancerErrorID as IdRefund });
|
|
99
|
-
await expect(() => repository.send(model)).rejects.toThrow(StancerError);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('should return error on StancerRouteInacessibleError', async () => {
|
|
103
|
-
const model = await repository.create({ ...creationResource, id: stancerRouteInaccessibleId as IdRefund });
|
|
104
|
-
await expect(async () => await repository.send(model)).rejects.toThrow(StancerRouteInaccessibleError);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('should return unmodified model when no new Data', async () => {
|
|
108
|
-
const model = await repository.create({ ...creationResource, id: dataUnmodified as IdRefund });
|
|
109
|
-
const sentModel = await repository.send(model);
|
|
110
|
-
|
|
111
|
-
expect(model).toStrictEqual(sentModel);
|
|
112
|
-
expect(sentModel._data.id).toEqual(dataUnmodified);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
describe('populate', () => {
|
|
117
|
-
it('should not modify model if no Id', async () => {
|
|
118
|
-
const getEndpoint = vi.spyOn(mockRepo, 'get');
|
|
119
|
-
const model = await repository.create(creationResource);
|
|
120
|
-
expect(model).toBeInstanceOf(RefundModel);
|
|
121
|
-
expect(getEndpoint).toHaveBeenCalledTimes(0);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('should get model if only id', async () => {
|
|
125
|
-
const getEndpoint = vi.spyOn(mockRepo, 'get');
|
|
126
|
-
const model = await repository.create(id);
|
|
127
|
-
expect(model).toBeInstanceOf(RefundModel);
|
|
128
|
-
expect(getEndpoint).toHaveBeenCalledTimes(1);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
describe('list', async () => {
|
|
133
|
-
it('return correct model one by one', async () => {
|
|
134
|
-
const listStub = repository.list();
|
|
135
|
-
const item1 = await listStub.next();
|
|
136
|
-
expect(item1.done).toBeFalsy();
|
|
137
|
-
expect(item1.value).toHaveProperty('id');
|
|
138
|
-
expect(item1.value.id).toContain('one');
|
|
139
|
-
expect(item1.value).toBeInstanceOf(RefundModel);
|
|
140
|
-
|
|
141
|
-
const item2 = await listStub.next();
|
|
142
|
-
expect(item2.done).toBeFalsy();
|
|
143
|
-
expect(item2.value).toHaveProperty('id');
|
|
144
|
-
expect(item2.value.id).toContain('two');
|
|
145
|
-
expect(item2.value).toBeInstanceOf(RefundModel);
|
|
146
|
-
|
|
147
|
-
const item3 = await listStub.next();
|
|
148
|
-
expect(item3.done).toBeFalsy();
|
|
149
|
-
expect(item3.value).toHaveProperty('id');
|
|
150
|
-
expect(item3.value.id).toContain('three');
|
|
151
|
-
expect(item3.value).toBeInstanceOf(RefundModel);
|
|
152
|
-
|
|
153
|
-
const item4 = await listStub.next();
|
|
154
|
-
expect(item4.done).toBeTruthy();
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
});
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { Temporal } from 'temporal-polyfill';
|
|
2
|
-
import { describe, expect, it } from 'vitest';
|
|
3
|
-
|
|
4
|
-
import { Currency, CurrencyEnum } from '#payment/enum/currency.js';
|
|
5
|
-
import { PaymentModel, idPayment } from '#payment/model.js';
|
|
6
|
-
import { paymentValidator } from '#payment/validator.js';
|
|
7
|
-
import { RefundStatus, RefundStatusEnum } from '#refund/enum/refund-status.js';
|
|
8
|
-
import { RefundAmount, RefundModel, refundAmount } from '#refund/model.js';
|
|
9
|
-
import { refundValidator } from '#refund/validator.js';
|
|
10
|
-
import { checkType, goldilocks, goldilocksId, randomMonth, randomNumber, randomString } from '#test/test-helper.js';
|
|
11
|
-
|
|
12
|
-
import { IdPaymentIntent } from '../../../src/payment-intent/model';
|
|
13
|
-
import { IdPayout } from '../../../src/payout/model';
|
|
14
|
-
|
|
15
|
-
describe('Goldilocks & type', () => {
|
|
16
|
-
const refund = new RefundModel(refundValidator);
|
|
17
|
-
|
|
18
|
-
it('amount', () => {
|
|
19
|
-
goldilocks((value: RefundAmount) => refund.setAmount(value), 'number', { min: 0 });
|
|
20
|
-
checkType((value: RefundAmount) => refund.setAmount(value), ['number'], refundAmount(randomNumber(50)));
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('payment', () => {
|
|
24
|
-
checkType(
|
|
25
|
-
(value: PaymentModel) => refund.setPayment(value),
|
|
26
|
-
['string', 'object'],
|
|
27
|
-
new PaymentModel(paymentValidator, `paym_${randomString(24)}`),
|
|
28
|
-
);
|
|
29
|
-
const newRefund = new RefundModel(refundValidator);
|
|
30
|
-
expect(() => newRefund.setPayment(idPayment(`paym_${randomString(24)}`)));
|
|
31
|
-
expect(() => newRefund.setPayment(new PaymentModel(paymentValidator).id)).toThrow();
|
|
32
|
-
const id = `paym_${randomString(24)}`;
|
|
33
|
-
const refundablePayment = new PaymentModel(paymentValidator, id);
|
|
34
|
-
newRefund.setPayment(refundablePayment.id);
|
|
35
|
-
expect(newRefund.payment).toStrictEqual(refundablePayment.id);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it.each(CurrencyEnum.map((n) => [n]))('currency %s', (currency) => {
|
|
39
|
-
const falseCurrency = randomString(3);
|
|
40
|
-
expect(() => (refund._data.currency = falseCurrency)).toThrow();
|
|
41
|
-
refund._data.currency = currency;
|
|
42
|
-
|
|
43
|
-
expect(refund.currency).toBe(currency);
|
|
44
|
-
checkType((value: Currency) => (refund._data.currency = value), [], currency);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('DateRefund', () => {
|
|
48
|
-
const falseDateRefund = new Temporal.PlainDate(9999, randomMonth(), randomNumber(1, 28));
|
|
49
|
-
const DateRefund = new Temporal.PlainDate(
|
|
50
|
-
randomNumber(1971, Temporal.PlainDate.from(Temporal.Now.plainDateISO()).year),
|
|
51
|
-
randomMonth(),
|
|
52
|
-
randomNumber(1, 28),
|
|
53
|
-
);
|
|
54
|
-
expect(() => (refund._data.dateRefund = falseDateRefund)).toThrow();
|
|
55
|
-
refund._data.dateRefund = DateRefund;
|
|
56
|
-
expect(refund._data.dateRefund).toBe(DateRefund);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('DateBank', () => {
|
|
60
|
-
const falseDateBank = new Temporal.PlainDate(9999, randomMonth(), randomNumber(1, 28));
|
|
61
|
-
const DateBank = new Temporal.PlainDate(
|
|
62
|
-
randomNumber(1971, Temporal.PlainDate.from(Temporal.Now.plainDateISO()).year),
|
|
63
|
-
randomMonth(),
|
|
64
|
-
randomNumber(1, 28),
|
|
65
|
-
);
|
|
66
|
-
expect(() => (refund._data.dateBank = falseDateBank)).toThrow();
|
|
67
|
-
refund._data.dateBank = DateBank;
|
|
68
|
-
expect(refund._data.dateBank).toBe(DateBank);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('Payment intent', () => {
|
|
72
|
-
goldilocksId((value: IdPaymentIntent) => (refund._data.paymentIntent = value), 'pi_');
|
|
73
|
-
checkType((value: string) => (refund._data.paymentIntent = value), ['string', 'object'], `pi_${randomString(24)}`);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it.each(RefundStatusEnum.map((n) => [n]) as RefundStatus[][])('refund status %s', (status) => {
|
|
77
|
-
const falseStatus = randomString(3);
|
|
78
|
-
expect(RefundStatusEnum.includes(falseStatus)).toBeFalsy();
|
|
79
|
-
expect(() => (refund._data.status = falseStatus)).toThrow();
|
|
80
|
-
refund._data.status = status;
|
|
81
|
-
expect(refund.status).toBe(status);
|
|
82
|
-
checkType((value: RefundStatus) => (refund._data.status = value), [], status);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('payout', () => {
|
|
86
|
-
goldilocksId((value: IdPayout) => (refund._data.payout = value), 'pout_');
|
|
87
|
-
checkType((value: IdPayout) => (refund._data.payout = value), ['string', 'object'], `pout_${randomString(24)}`);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { trackObjectMutations } from '#core/common/mutation-tracked-object.js';
|
|
4
|
-
import { UnsendableError } from '#core/error/unsendable-error.js';
|
|
5
|
-
import { SepaApiEndpoint } from '#sepa/api-endpoint.js';
|
|
6
|
-
import type { IdSepa } from '#sepa/model.js';
|
|
7
|
-
import { randomString } from '#test/test-helper.js';
|
|
8
|
-
|
|
9
|
-
import { creationResource, endpointResource, endpointResourceDeserialized } from './fixture';
|
|
10
|
-
import { ibanDataProvider } from './sepa-helper';
|
|
11
|
-
|
|
12
|
-
vi.mock('#api/http/http.js', async (importHTTP) => {
|
|
13
|
-
const original: Record<string, Promise<unknown>> = await importHTTP();
|
|
14
|
-
return {
|
|
15
|
-
...original,
|
|
16
|
-
transformResponseToData: vi.fn((value) => value.json()),
|
|
17
|
-
};
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
vi.mock('#api/http/fetch-http-client.js', () => {
|
|
21
|
-
return {
|
|
22
|
-
httpClient: {
|
|
23
|
-
makeRequest: vi.fn(() => {
|
|
24
|
-
return Promise.resolve({
|
|
25
|
-
status: 200,
|
|
26
|
-
json: () => {
|
|
27
|
-
return {
|
|
28
|
-
...endpointResource,
|
|
29
|
-
};
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
}),
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
const iban = creationResource.iban;
|
|
37
|
-
|
|
38
|
-
describe('sepa api endpoint', () => {
|
|
39
|
-
describe('Serialize/Deserialize resources', () => {
|
|
40
|
-
const endpoint = new SepaApiEndpoint();
|
|
41
|
-
|
|
42
|
-
it('test deserialize resource', () => {
|
|
43
|
-
const deserializedResources = endpoint.deserializeResource(endpointResource);
|
|
44
|
-
expect(deserializedResources).toMatchObject(endpointResourceDeserialized);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('test post serialize resource', () => {
|
|
48
|
-
const serializedResources = endpoint.postObjectSerializer({
|
|
49
|
-
...endpointResourceDeserialized,
|
|
50
|
-
iban,
|
|
51
|
-
}) as typeof endpointResource;
|
|
52
|
-
|
|
53
|
-
// We extract the API generated Data and the non postable data from our endpoint resources.
|
|
54
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
55
|
-
const { created, deleted, id, last4, ...matchObject } = endpointResource;
|
|
56
|
-
expect(serializedResources).toMatchObject(matchObject);
|
|
57
|
-
//We check the non gettable properties
|
|
58
|
-
expect(serializedResources.iban).toBe(iban);
|
|
59
|
-
expect(serializedResources).not.toHaveProperty('created');
|
|
60
|
-
expect(serializedResources).not.toHaveProperty('deleted');
|
|
61
|
-
expect(serializedResources).not.toHaveProperty('id');
|
|
62
|
-
expect(serializedResources).not.toHaveProperty('last4');
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('test patch serialize resource (not available in repository)', () => {
|
|
66
|
-
const serializedResources = endpoint.patchObjectSerializer(
|
|
67
|
-
endpointResourceDeserialized,
|
|
68
|
-
) as typeof endpointResource;
|
|
69
|
-
|
|
70
|
-
// We extract the API generated Data and the non patchable data from our endpoint resources.
|
|
71
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
72
|
-
const { deleted, created, last4, bic, customer, id, ...matchObject } = endpointResource;
|
|
73
|
-
expect(serializedResources).toMatchObject(matchObject);
|
|
74
|
-
expect(matchObject).toMatchObject(serializedResources);
|
|
75
|
-
expect(serializedResources).not.toHaveProperty('created');
|
|
76
|
-
expect(serializedResources).not.toHaveProperty('deleted');
|
|
77
|
-
expect(serializedResources).not.toHaveProperty('id');
|
|
78
|
-
expect(serializedResources).not.toHaveProperty('last4');
|
|
79
|
-
expect(serializedResources).not.toHaveProperty('bic');
|
|
80
|
-
expect(serializedResources).not.toHaveProperty('customer');
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
describe('endpoint path', () => {
|
|
85
|
-
it('endpoint url', () => {
|
|
86
|
-
const endpoint = new SepaApiEndpoint();
|
|
87
|
-
const id = ('sepa_' + randomString(24)) as IdSepa;
|
|
88
|
-
expect(endpoint._getResourceUri(id)).toStrictEqual(`https://api.stancer.com/v2/sepa/${id}`);
|
|
89
|
-
expect(endpoint._getResourceUri()).toStrictEqual('https://api.stancer.com/v2/sepa/');
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
describe('verbs', () => {
|
|
94
|
-
const sepaEndpoint = new SepaApiEndpoint();
|
|
95
|
-
|
|
96
|
-
it('get', async () => {
|
|
97
|
-
const responseWithId = await sepaEndpoint.get(('sepa_' + randomString(24)) as IdSepa);
|
|
98
|
-
expect(responseWithId).toStrictEqual(endpointResourceDeserialized);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('post no deserialization', async () => {
|
|
102
|
-
const responseWithId = await sepaEndpoint.post({ name: randomString(3, 64), iban: ibanDataProvider(true) });
|
|
103
|
-
expect(responseWithId).toStrictEqual(endpointResourceDeserialized);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('patch', async () => {
|
|
107
|
-
const patchResponse = await sepaEndpoint.patch(('sepa_' + randomString(24)) as IdSepa, endpointResource);
|
|
108
|
-
expect(patchResponse).toStrictEqual(endpointResourceDeserialized);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('delete', async () => {
|
|
112
|
-
expect(await sepaEndpoint.delete(('sepa_' + randomString(24)) as IdSepa)).toStrictEqual(
|
|
113
|
-
endpointResourceDeserialized,
|
|
114
|
-
);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
describe('send', () => {
|
|
119
|
-
const { name, mandate, dateMandate } = endpointResourceDeserialized;
|
|
120
|
-
|
|
121
|
-
it('send with required data', async () => {
|
|
122
|
-
const endpoint = new SepaApiEndpoint();
|
|
123
|
-
|
|
124
|
-
expect(endpoint.send(undefined, { iban, name })).resolves.toStrictEqual(endpointResourceDeserialized);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('does not post with missing iban', async () => {
|
|
128
|
-
const endpoint = new SepaApiEndpoint();
|
|
129
|
-
|
|
130
|
-
expect(() => endpoint.send(undefined, { name })).toThrow();
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it('does not post with missing name', async () => {
|
|
134
|
-
const endpoint = new SepaApiEndpoint();
|
|
135
|
-
expect(() => endpoint.send(undefined, { iban })).toThrow(UnsendableError);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('Patch if id', async () => {
|
|
139
|
-
const endpoint = new SepaApiEndpoint();
|
|
140
|
-
const spyonPatch = vi.spyOn(endpoint, 'patch');
|
|
141
|
-
const spyonPost = vi.spyOn(endpoint, 'post');
|
|
142
|
-
const mutationsData = trackObjectMutations({}, () => true);
|
|
143
|
-
mutationsData['id'] = 'sepa' + randomString(24);
|
|
144
|
-
mutationsData['mandate'] = mandate;
|
|
145
|
-
mutationsData['name'] = name;
|
|
146
|
-
mutationsData['dateMandate'] = dateMandate;
|
|
147
|
-
|
|
148
|
-
expect(mutationsData['id']).toBeTruthy();
|
|
149
|
-
await expect(endpoint.send(mutationsData, mutationsData['id'])).resolves.toStrictEqual(
|
|
150
|
-
endpointResourceDeserialized,
|
|
151
|
-
);
|
|
152
|
-
expect(spyonPatch).toHaveBeenCalledTimes(1);
|
|
153
|
-
expect(spyonPost).toHaveBeenCalledTimes(0);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it('post if no id', () => {
|
|
157
|
-
const endpoint = new SepaApiEndpoint();
|
|
158
|
-
const spyonPatch = vi.spyOn(endpoint, 'patch');
|
|
159
|
-
const spyonPost = vi.spyOn(endpoint, 'post');
|
|
160
|
-
|
|
161
|
-
const mutationsData = trackObjectMutations({}, () => true);
|
|
162
|
-
mutationsData['iban'] = iban;
|
|
163
|
-
mutationsData['name'] = name;
|
|
164
|
-
|
|
165
|
-
endpoint.send(undefined, mutationsData);
|
|
166
|
-
expect(spyonPatch).toHaveBeenCalledTimes(0);
|
|
167
|
-
expect(spyonPost).toHaveBeenCalledTimes(1);
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
});
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { Temporal } from 'temporal-polyfill';
|
|
2
|
-
|
|
3
|
-
import { randomMonth, randomNumber, randomString } from '#test/test-helper.js';
|
|
4
|
-
|
|
5
|
-
import { IdCustomer } from '../../../src/customer/model';
|
|
6
|
-
import { bicDataProvider, ibanDataProvider } from './sepa-helper';
|
|
7
|
-
|
|
8
|
-
const id = `sepa_${randomString(24)}`;
|
|
9
|
-
|
|
10
|
-
const bic = bicDataProvider(true) as string;
|
|
11
|
-
const created = randomNumber(1786460000, 2000000000);
|
|
12
|
-
const customer = `cust_${randomString(24)}`;
|
|
13
|
-
const deleted = false;
|
|
14
|
-
const date_mandate = `${String(randomNumber(1971, 2020))}-${String(randomMonth()).padStart(2, '0')}-${String(randomNumber(1, 28)).padStart(2, '0')}`;
|
|
15
|
-
const dateMandate = Temporal.PlainDate.from(date_mandate);
|
|
16
|
-
const iban = ibanDataProvider(true) as string;
|
|
17
|
-
const last4 = iban.slice(iban.length - 4);
|
|
18
|
-
const mandate = randomString(1, 35);
|
|
19
|
-
const name = randomString(1, 64);
|
|
20
|
-
|
|
21
|
-
export const endpointResource = {
|
|
22
|
-
bic,
|
|
23
|
-
created,
|
|
24
|
-
customer,
|
|
25
|
-
date_mandate: date_mandate,
|
|
26
|
-
deleted,
|
|
27
|
-
id,
|
|
28
|
-
last4,
|
|
29
|
-
mandate,
|
|
30
|
-
name,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const endpointResourceDeserialized = {
|
|
34
|
-
bic,
|
|
35
|
-
createdAt: Temporal.Instant.fromEpochMilliseconds(created * 1000),
|
|
36
|
-
customer: customer as IdCustomer,
|
|
37
|
-
dateMandate,
|
|
38
|
-
deleted,
|
|
39
|
-
id,
|
|
40
|
-
last4,
|
|
41
|
-
mandate,
|
|
42
|
-
name,
|
|
43
|
-
};
|
|
44
|
-
export const creationResource = {
|
|
45
|
-
mandate,
|
|
46
|
-
name,
|
|
47
|
-
dateMandate,
|
|
48
|
-
iban,
|
|
49
|
-
bic,
|
|
50
|
-
customer,
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export const listResource = [
|
|
54
|
-
{
|
|
55
|
-
...endpointResource,
|
|
56
|
-
name: 'item1',
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
...endpointResource,
|
|
60
|
-
name: 'item2',
|
|
61
|
-
},
|
|
62
|
-
];
|