@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,96 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { FundingCardEnum } from '#card/enum/funding.js';
|
|
4
|
-
import { NatureCardEnum } from '#card/enum/nature.js';
|
|
5
|
-
import { NetworkCardEnum, PreferredNetworkCardEnum } from '#card/enum/network.js';
|
|
6
|
-
import { CardModel } from '#card/model.js';
|
|
7
|
-
import { cardValidator } from '#card/validator.js';
|
|
8
|
-
import { checkType, goldilocks, randomMonth, randomNumber, randomString } from '#test/test-helper.js';
|
|
9
|
-
|
|
10
|
-
import { IdCustomer } from '../../../src/customer/model';
|
|
11
|
-
import { randomCardNumber } from './card-helper';
|
|
12
|
-
|
|
13
|
-
describe('Goldilocks', () => {
|
|
14
|
-
const card = new CardModel(cardValidator);
|
|
15
|
-
|
|
16
|
-
it('country', () => {
|
|
17
|
-
goldilocks((value: string) => (card._data.country = value), 'string', { min: 2, max: 2 });
|
|
18
|
-
checkType((value: string) => (card._data.country = value), ['string'], randomString(2, 2));
|
|
19
|
-
});
|
|
20
|
-
it('customer', () => {
|
|
21
|
-
const falseCustomer = randomString(24);
|
|
22
|
-
const trueCustomer = `cust_${randomString(24)}` as IdCustomer;
|
|
23
|
-
expect(() => card.setCustomer(falseCustomer)).toThrow();
|
|
24
|
-
card.setCustomer(trueCustomer);
|
|
25
|
-
expect(card.customer).toBe(trueCustomer);
|
|
26
|
-
});
|
|
27
|
-
it('cvc', () => {
|
|
28
|
-
const cvc = String(randomNumber(0, 999)).padStart(3, '0');
|
|
29
|
-
expect(() => card.setCvc(cvc.padStart(4, '0'))).toThrow();
|
|
30
|
-
expect(() => card.setCvc(String(randomNumber(0, 99)).padStart(2, '0'))).toThrow();
|
|
31
|
-
expect(() => card.setCvc(randomString(3))).toThrow();
|
|
32
|
-
|
|
33
|
-
checkType((value: string) => card.setCvc(value), ['string'], cvc);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('expMonth', () => {
|
|
37
|
-
checkType((value: number) => card.setExpMonth(value), ['number'], randomMonth());
|
|
38
|
-
goldilocks((value: number) => card.setExpMonth(value), 'number', { min: 1, max: 12 });
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('expYear', () => {
|
|
42
|
-
checkType((value: number) => card.setExpYear(value), ['number'], randomNumber(1000, 9999));
|
|
43
|
-
goldilocks((value: number) => card.setExpYear(value), 'number', { min: 1000, max: 9999 });
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('externalId', () => {
|
|
47
|
-
goldilocks((value: string) => card.setExternalId(value), 'string', { min: 1, max: 36 });
|
|
48
|
-
checkType((value: string) => card.setExternalId(value), ['string'], randomString(1, 36));
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it.each(FundingCardEnum.map((n) => [n]))('funding', (funding) => {
|
|
52
|
-
const falseFunding = randomString(123, 188);
|
|
53
|
-
expect(() => (card._data.funding = falseFunding)).toThrow();
|
|
54
|
-
card._data.funding = funding;
|
|
55
|
-
expect(card.funding).toBe(funding);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('name', () => {
|
|
59
|
-
goldilocks((value: string) => card.setName(value), 'string', { min: 1, max: 64 });
|
|
60
|
-
checkType((value: string) => card.setName(value), ['string'], randomString(1, 64));
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it.each(NatureCardEnum.map((n) => [n]))('nature', (nature) => {
|
|
64
|
-
const falseNature = randomString(123, 188);
|
|
65
|
-
expect(() => (card._data.nature = falseNature)).toThrow();
|
|
66
|
-
card._data.nature = nature;
|
|
67
|
-
expect(card.nature).toBe(nature);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it.each(NetworkCardEnum.map((n) => [n]))('network', (network) => {
|
|
71
|
-
const falseNetwork = randomString(123, 188);
|
|
72
|
-
expect(() => (card._data.network = falseNetwork)).toThrow();
|
|
73
|
-
card._data.network = network;
|
|
74
|
-
expect(card.network).toBe(network);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('number', () => {
|
|
78
|
-
const falseCardNumber = String(Number(randomCardNumber()) + 1);
|
|
79
|
-
expect(() => card.setNumber(falseCardNumber)).toThrow();
|
|
80
|
-
const trueCardNumber = randomCardNumber();
|
|
81
|
-
card.setNumber(trueCardNumber);
|
|
82
|
-
expect(card._data.number).toBe(trueCardNumber);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it.each(PreferredNetworkCardEnum.map((n) => [n]))('preferredNetwork', (network) => {
|
|
86
|
-
const falsePreferredNetwork = randomString(123, 188);
|
|
87
|
-
expect(() => card.setPreferredNetwork(falsePreferredNetwork)).toThrow();
|
|
88
|
-
card.setPreferredNetwork(network);
|
|
89
|
-
expect(card.preferredNetwork).toBe(network);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('zipCode', () => {
|
|
93
|
-
goldilocks((value: string) => card.setZipCode(value), 'string', { min: 0, max: 8 });
|
|
94
|
-
checkType((value: string) => card.setZipCode(value), ['string'], randomString(0, 8));
|
|
95
|
-
});
|
|
96
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'vitest';
|
|
2
|
-
import { expect } from 'vitest';
|
|
3
|
-
|
|
4
|
-
import { trackObjectMutations } from '#core/common/mutation-tracked-object.ts';
|
|
5
|
-
|
|
6
|
-
describe('mutation tracked object', () => {
|
|
7
|
-
it('set new data in mutation', () => {
|
|
8
|
-
const validator = () => true;
|
|
9
|
-
const data = {};
|
|
10
|
-
const tracked = trackObjectMutations(data, validator);
|
|
11
|
-
tracked['test'] = 'test';
|
|
12
|
-
expect(tracked.getMutations()).toStrictEqual({ test: 'test' });
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('modify initialized data ', () => {
|
|
16
|
-
const validator = () => true;
|
|
17
|
-
const data = { truc: '12', machin: 'x' };
|
|
18
|
-
const tracked = trackObjectMutations(data, validator);
|
|
19
|
-
expect(tracked.getMutations()).toStrictEqual({});
|
|
20
|
-
expect(tracked.toRaw()).toStrictEqual(data);
|
|
21
|
-
tracked['truc'] = 'machin';
|
|
22
|
-
expect(tracked.getMutations()).toStrictEqual({ truc: 'machin' });
|
|
23
|
-
});
|
|
24
|
-
});
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { StancerError } from '#core/error/base-error.js';
|
|
4
|
-
import { CustomerApiEndpoint } from '#customer/api-endpoint.js';
|
|
5
|
-
import type { CustomerData, IdCustomer } from '#customer/model.js';
|
|
6
|
-
import { randomString } from '#test/test-helper.js';
|
|
7
|
-
|
|
8
|
-
import { endpointResource, endpointResourceDeserialized } from './fixtures.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
|
-
...endpointResource,
|
|
27
|
-
};
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
}),
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe('customer api endpoint', () => {
|
|
36
|
-
describe('Serialize/Deserialize resources', () => {
|
|
37
|
-
const endpoint = new CustomerApiEndpoint();
|
|
38
|
-
|
|
39
|
-
it('test deserialize resource', () => {
|
|
40
|
-
const deserializedResources = endpoint.deserializeResource(endpointResource);
|
|
41
|
-
//Double match to guaranty exact same shape
|
|
42
|
-
expect(deserializedResources).toMatchObject(endpointResourceDeserialized);
|
|
43
|
-
expect(endpointResourceDeserialized).toMatchObject(deserializedResources);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('test post serialize resource', () => {
|
|
47
|
-
const serializedResources = endpoint.postObjectSerializer(
|
|
48
|
-
endpointResourceDeserialized,
|
|
49
|
-
) as typeof endpointResource;
|
|
50
|
-
// property not in postObject are API generated or not postable
|
|
51
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
52
|
-
const { deleted, created, id, ...postObject } = endpointResource;
|
|
53
|
-
//Double match to guaranty exact same shape
|
|
54
|
-
expect(serializedResources).toMatchObject(postObject);
|
|
55
|
-
expect(postObject).toMatchObject(serializedResources);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('test patch serialize resource (not available in repository)', () => {
|
|
59
|
-
const serializedResources = endpoint.patchObjectSerializer(
|
|
60
|
-
endpointResourceDeserialized,
|
|
61
|
-
) as typeof endpointResource;
|
|
62
|
-
// property not in patchObject are API generated or not patchable
|
|
63
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
64
|
-
const { deleted, created, id, ...patchObject } = endpointResource;
|
|
65
|
-
//Double match to guaranty exact same shape
|
|
66
|
-
expect(serializedResources).toMatchObject(patchObject);
|
|
67
|
-
expect(patchObject).toMatchObject(serializedResources);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
describe('endpoint path', () => {
|
|
72
|
-
it('endpoint url', () => {
|
|
73
|
-
const endpoint = new CustomerApiEndpoint();
|
|
74
|
-
const id = ('cust_' + randomString(24)) as IdCustomer;
|
|
75
|
-
expect(endpoint._getResourceUri(id)).toStrictEqual(`https://api.stancer.com/v2/customers/${id}`);
|
|
76
|
-
expect(endpoint._getResourceUri()).toStrictEqual('https://api.stancer.com/v2/customers/');
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe('verbs', () => {
|
|
81
|
-
const customerEndpoint = new CustomerApiEndpoint();
|
|
82
|
-
|
|
83
|
-
it('get', async () => {
|
|
84
|
-
const responseWithId = await customerEndpoint.get(('cust_' + randomString(24)) as IdCustomer);
|
|
85
|
-
expect(responseWithId).toStrictEqual(endpointResourceDeserialized);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('post', async () => {
|
|
89
|
-
const responseWithId = await customerEndpoint.post(endpointResource);
|
|
90
|
-
expect(responseWithId).toStrictEqual(endpointResourceDeserialized);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('patch', async () => {
|
|
94
|
-
const patchResponse = await customerEndpoint.patch(('cust_' + randomString(24)) as IdCustomer, endpointResource);
|
|
95
|
-
expect(patchResponse).toStrictEqual(endpointResourceDeserialized);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('delete', async () => {
|
|
99
|
-
expect(await customerEndpoint.delete(('cust_' + randomString(24)) as IdCustomer)).toStrictEqual(
|
|
100
|
-
endpointResourceDeserialized,
|
|
101
|
-
);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
describe('send', () => {
|
|
106
|
-
const { mobile, email, country } = endpointResourceDeserialized;
|
|
107
|
-
|
|
108
|
-
it.each([
|
|
109
|
-
['mobile', mobile],
|
|
110
|
-
['email', email],
|
|
111
|
-
])('send with partial required data', async (valueName, requiredValue) => {
|
|
112
|
-
const endpoint = new CustomerApiEndpoint();
|
|
113
|
-
const mutationsData = {} as Partial<CustomerData>;
|
|
114
|
-
mutationsData[valueName] = requiredValue;
|
|
115
|
-
await expect(endpoint.send(undefined, mutationsData)).resolves.toStrictEqual(endpointResourceDeserialized);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('does not post with missing partially required data', async () => {
|
|
119
|
-
const endpoint = new CustomerApiEndpoint();
|
|
120
|
-
expect(() => endpoint.send(undefined, { country })).toThrow(StancerError);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('Patch if id', async () => {
|
|
124
|
-
const endpoint = new CustomerApiEndpoint();
|
|
125
|
-
const spyonPatch = vi.spyOn(endpoint, 'patch');
|
|
126
|
-
const spyonPost = vi.spyOn(endpoint, 'post');
|
|
127
|
-
await expect(endpoint.send('cust_' + randomString(24), { mobile, country })).resolves.toStrictEqual(
|
|
128
|
-
endpointResourceDeserialized,
|
|
129
|
-
);
|
|
130
|
-
expect(spyonPatch).toHaveBeenCalledTimes(1);
|
|
131
|
-
expect(spyonPost).toHaveBeenCalledTimes(0);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('post if no id', () => {
|
|
135
|
-
const endpoint = new CustomerApiEndpoint();
|
|
136
|
-
const spyonPatch = vi.spyOn(endpoint, 'patch');
|
|
137
|
-
const spyonPost = vi.spyOn(endpoint, 'post');
|
|
138
|
-
endpoint.send(undefined, { email });
|
|
139
|
-
expect(spyonPatch).toHaveBeenCalledTimes(0);
|
|
140
|
-
expect(spyonPost).toHaveBeenCalledTimes(1);
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
});
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { Temporal } from 'temporal-polyfill';
|
|
2
|
-
|
|
3
|
-
import { IdCustomer } from '#customer/model.js';
|
|
4
|
-
import { randomMonth, randomNumber, randomString } from '#test/test-helper.js';
|
|
5
|
-
|
|
6
|
-
import { IdAddress } from '../../../src/address/temporary-types';
|
|
7
|
-
|
|
8
|
-
const billing_address = 'addr_' + randomString(24);
|
|
9
|
-
const country = randomString(2);
|
|
10
|
-
const created = randomNumber(1786460000, 2000000000);
|
|
11
|
-
const date_birth = `${randomNumber(1000, 2025)}-${randomMonth().toString().padStart(2, '0')}-${randomNumber(1, 28).toString().padStart(2, '0')}`;
|
|
12
|
-
const deleted = false;
|
|
13
|
-
const email = randomString(1, 64);
|
|
14
|
-
const external_id = randomString(1, 36);
|
|
15
|
-
const id = `cust_${randomString(24)}`;
|
|
16
|
-
const legal_id = randomString(1, 16);
|
|
17
|
-
const mobile = randomString(4, 16);
|
|
18
|
-
const name = randomString(3, 64);
|
|
19
|
-
const shipping_address = 'addr_' + randomString(24);
|
|
20
|
-
|
|
21
|
-
export const endpointResource = {
|
|
22
|
-
billing_address,
|
|
23
|
-
country,
|
|
24
|
-
created,
|
|
25
|
-
date_birth,
|
|
26
|
-
deleted,
|
|
27
|
-
email,
|
|
28
|
-
external_id,
|
|
29
|
-
id,
|
|
30
|
-
legal_id,
|
|
31
|
-
mobile,
|
|
32
|
-
name,
|
|
33
|
-
shipping_address,
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export const endpointResourceDeserialized = {
|
|
37
|
-
createdAt: Temporal.Instant.fromEpochMilliseconds(created * 1000),
|
|
38
|
-
|
|
39
|
-
billingAddress: billing_address as IdAddress,
|
|
40
|
-
country,
|
|
41
|
-
dateBirth: Temporal.PlainDate.from(date_birth),
|
|
42
|
-
deleted,
|
|
43
|
-
email,
|
|
44
|
-
externalId: external_id,
|
|
45
|
-
id: id as IdCustomer,
|
|
46
|
-
legalId: legal_id,
|
|
47
|
-
mobile,
|
|
48
|
-
name,
|
|
49
|
-
shippingAddress: shipping_address as IdAddress,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export const creationResource = {
|
|
53
|
-
billingAddress: billing_address,
|
|
54
|
-
country,
|
|
55
|
-
dateBirth: Temporal.PlainDate.from(date_birth),
|
|
56
|
-
email,
|
|
57
|
-
externalId: external_id,
|
|
58
|
-
id,
|
|
59
|
-
legalId: legal_id,
|
|
60
|
-
mobile,
|
|
61
|
-
name,
|
|
62
|
-
shippingAddress: shipping_address,
|
|
63
|
-
};
|
|
64
|
-
export const listResource = [
|
|
65
|
-
{
|
|
66
|
-
...endpointResource,
|
|
67
|
-
name: 'item1',
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
...endpointResource,
|
|
71
|
-
name: 'item2',
|
|
72
|
-
},
|
|
73
|
-
];
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { IdAddress, idAddress } from '#address/model.ts';
|
|
4
|
-
import { Validator } from '#core/validator.js';
|
|
5
|
-
import { CustomerData, CustomerModel } from '#customer/model.js';
|
|
6
|
-
import { SetterGetter, randomString } from '#test/test-helper.js';
|
|
7
|
-
|
|
8
|
-
describe('Customer Class', () => {
|
|
9
|
-
describe('Setter & Getter', () => {
|
|
10
|
-
const customer = new CustomerModel((() => true) as unknown as Validator<CustomerData>);
|
|
11
|
-
|
|
12
|
-
it('country', () => {
|
|
13
|
-
SetterGetter(
|
|
14
|
-
(value: string) => customer.setCountry(value),
|
|
15
|
-
() => customer.country,
|
|
16
|
-
randomString(2),
|
|
17
|
-
);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('email', () => {
|
|
21
|
-
SetterGetter(
|
|
22
|
-
(value: string) => customer.setEmail(value),
|
|
23
|
-
() => customer.email,
|
|
24
|
-
randomString(30),
|
|
25
|
-
);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('externalId', () => {
|
|
29
|
-
SetterGetter(
|
|
30
|
-
(value: string) => customer.setExternalId(value),
|
|
31
|
-
() => customer.externalId,
|
|
32
|
-
randomString(30),
|
|
33
|
-
);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('legalId', () => {
|
|
37
|
-
SetterGetter(
|
|
38
|
-
(value: string) => customer.setLegalId(value),
|
|
39
|
-
() => customer.legalId,
|
|
40
|
-
randomString(15),
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('mobile', () => {
|
|
45
|
-
SetterGetter(
|
|
46
|
-
(value: string) => customer.setMobile(value),
|
|
47
|
-
() => customer.mobile,
|
|
48
|
-
randomString(12),
|
|
49
|
-
);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('name', () => {
|
|
53
|
-
SetterGetter(
|
|
54
|
-
(value: string) => customer.setName(value),
|
|
55
|
-
() => customer.name,
|
|
56
|
-
randomString(12),
|
|
57
|
-
);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('billing Address', () => {
|
|
61
|
-
SetterGetter(
|
|
62
|
-
(value: IdAddress) => customer.setBillingAddress(value),
|
|
63
|
-
() => customer.billingAddress,
|
|
64
|
-
idAddress(`addr_${randomString(24)}`),
|
|
65
|
-
);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('Shipping Address', () => {
|
|
69
|
-
SetterGetter(
|
|
70
|
-
(value: IdAddress) => customer.setShippingAddress(value),
|
|
71
|
-
() => customer.shippingAddress,
|
|
72
|
-
idAddress(`addr_${randomString(24)}`),
|
|
73
|
-
);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('deleted (unsettable)', () => {
|
|
77
|
-
SetterGetter(
|
|
78
|
-
(value: boolean) => (customer._data.deleted = value),
|
|
79
|
-
() => customer.deleted,
|
|
80
|
-
true,
|
|
81
|
-
);
|
|
82
|
-
customer._data.deleted = null;
|
|
83
|
-
SetterGetter(
|
|
84
|
-
(value: boolean) => (customer._data.deleted = value),
|
|
85
|
-
() => customer.deleted,
|
|
86
|
-
false,
|
|
87
|
-
);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
});
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { AbstractRepository } from '#core/abstract-repository.js';
|
|
4
|
-
import { CustomerApiEndpoint } from '#customer/api-endpoint.js';
|
|
5
|
-
import { CustomerModel, IdCustomer } from '#customer/model.js';
|
|
6
|
-
import { CustomerRepository } from '#customer/repository.js';
|
|
7
|
-
import { customerValidator } from '#customer/validator.js';
|
|
8
|
-
import { StancerError } from '#error/base-error.js';
|
|
9
|
-
import { StancerRouteInaccessibleError } from '#error/endpoint/route-inaccessible-error.js';
|
|
10
|
-
import { randomString } from '#test/test-helper.js';
|
|
11
|
-
|
|
12
|
-
import { creationResource, endpointResource, listResource } from './fixtures.js';
|
|
13
|
-
|
|
14
|
-
const idPrefix = 'cust';
|
|
15
|
-
const id = `${idPrefix}_${randomString(24)}` as IdCustomer;
|
|
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
|
-
list() {
|
|
23
|
-
async function* listGenerator() {
|
|
24
|
-
yield* listResource;
|
|
25
|
-
}
|
|
26
|
-
return listGenerator();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
delete() {
|
|
30
|
-
return endpointResource;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
send(id: string, data: Record<string, unknown>) {
|
|
34
|
-
if (id) {
|
|
35
|
-
if (id === stancerErrorID) {
|
|
36
|
-
throw new StancerError();
|
|
37
|
-
}
|
|
38
|
-
if (id === stancerRouteInaccessibleId) {
|
|
39
|
-
throw new StancerRouteInaccessibleError('PATCH', 'stub');
|
|
40
|
-
}
|
|
41
|
-
if (id === dataUnmodified) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return { ...data, id: dataHasBeenSentId };
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
get() {
|
|
49
|
-
return endpointResource;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
it('can be instanciated', () => {
|
|
54
|
-
const instance = new CustomerRepository();
|
|
55
|
-
expect(instance).toBeInstanceOf(CustomerRepository);
|
|
56
|
-
expect(instance).toBeInstanceOf(AbstractRepository);
|
|
57
|
-
//accessing private method & property
|
|
58
|
-
expect(instance.endpoint).toBeInstanceOf(CustomerApiEndpoint);
|
|
59
|
-
expect(instance.validator).toBe(customerValidator);
|
|
60
|
-
expect(instance.staticModel).toBe(CustomerModel);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe('repository', () => {
|
|
64
|
-
const mockRepo = new MockApiEndpoint() as unknown as CustomerApiEndpoint; // I lie, for convenience sake
|
|
65
|
-
const repository = new CustomerRepository(mockRepo);
|
|
66
|
-
|
|
67
|
-
describe('create', () => {
|
|
68
|
-
it("doesn't accept bad data", async () => {
|
|
69
|
-
const badID = randomString(30, 56);
|
|
70
|
-
// using puposefuly bad ID
|
|
71
|
-
await expect(async () => await repository.create(badID)).rejects.toThrow();
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('accept good data', async () => {
|
|
75
|
-
const model = await repository.create(id);
|
|
76
|
-
expect(model).toBeInstanceOf(CustomerModel);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('delete', async () => {
|
|
81
|
-
const modelWithoutId = await repository.create();
|
|
82
|
-
await expect(() => repository.delete(modelWithoutId)).rejects.toThrow();
|
|
83
|
-
const model = await repository.create({ id: endpointResource.id, ...creationResource });
|
|
84
|
-
await expect((await repository.delete(model))._data).toStrictEqual(endpointResource);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
describe('send', () => {
|
|
88
|
-
it('should return model', async () => {
|
|
89
|
-
const model = await repository.create(creationResource);
|
|
90
|
-
const sentModel = await repository.send(model);
|
|
91
|
-
expect(sentModel).toStrictEqual(model);
|
|
92
|
-
expect(sentModel._data.id).toEqual(dataHasBeenSentId);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('should throw on inprecise error', async () => {
|
|
96
|
-
const model = await repository.create({ ...creationResource, id: stancerErrorID as IdCustomer });
|
|
97
|
-
await expect(() => repository.send(model)).rejects.toThrow(StancerError);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('should return error on StancerRouteInacessibleError', async () => {
|
|
101
|
-
const model = await repository.create({ ...creationResource, id: stancerRouteInaccessibleId as IdCustomer });
|
|
102
|
-
await expect(async () => await repository.send(model)).rejects.toThrow(StancerRouteInaccessibleError);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('should return unmodified model when no new Data', async () => {
|
|
106
|
-
const model = await repository.create({ ...creationResource, id: dataUnmodified as IdCustomer });
|
|
107
|
-
const sentModel = await repository.send(model);
|
|
108
|
-
expect(model).toStrictEqual(sentModel);
|
|
109
|
-
expect(sentModel._data.id).toEqual(dataUnmodified);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
describe('populate', () => {
|
|
114
|
-
it('should not modify model if no Id', async () => {
|
|
115
|
-
const getEndpoint = vi.spyOn(mockRepo, 'get');
|
|
116
|
-
const model = await repository.create(creationResource);
|
|
117
|
-
expect(model).toBeInstanceOf(CustomerModel);
|
|
118
|
-
expect(getEndpoint).toHaveBeenCalledTimes(0);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('should get model if only id', async () => {
|
|
122
|
-
const getEndpoint = vi.spyOn(mockRepo, 'get');
|
|
123
|
-
const model = await repository.create(id);
|
|
124
|
-
expect(model).toBeInstanceOf(CustomerModel);
|
|
125
|
-
expect(getEndpoint).toHaveBeenCalledTimes(1);
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
describe('list', async () => {
|
|
130
|
-
it('return correct model one by one', async () => {
|
|
131
|
-
const listStub = repository.list();
|
|
132
|
-
const item1 = await listStub.next();
|
|
133
|
-
expect(item1.done).toBeFalsy();
|
|
134
|
-
expect(item1.value).toHaveProperty('id');
|
|
135
|
-
expect(item1.value).toBeInstanceOf(CustomerModel);
|
|
136
|
-
expect(item1.value.name).toBe('item1');
|
|
137
|
-
|
|
138
|
-
const item2 = await listStub.next();
|
|
139
|
-
expect(item2.done).toBeFalsy();
|
|
140
|
-
expect(item2.value).toHaveProperty('id');
|
|
141
|
-
expect(item2.value).toBeInstanceOf(CustomerModel);
|
|
142
|
-
expect(item2.value.name).toBe('item2');
|
|
143
|
-
|
|
144
|
-
const item3 = await listStub.next();
|
|
145
|
-
expect(item3.done).toBeTruthy();
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
});
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { Temporal } from 'temporal-polyfill';
|
|
2
|
-
import { describe, expect, it } from 'vitest';
|
|
3
|
-
|
|
4
|
-
import { CustomerModel } from '#customer/model.js';
|
|
5
|
-
import { customerValidator } from '#customer/validator.js';
|
|
6
|
-
import { checkType, goldilocks, randomMonth, randomNumber, randomPastDate, randomString } from '#test/test-helper.js';
|
|
7
|
-
|
|
8
|
-
describe('Goldilocks', () => {
|
|
9
|
-
const customer = new CustomerModel(customerValidator);
|
|
10
|
-
|
|
11
|
-
it('Country', () => {
|
|
12
|
-
goldilocks((value: string) => customer.setCountry(value), 'string', { min: 2, max: 2 });
|
|
13
|
-
checkType((value: string) => customer.setCountry(value), ['string'], randomString(2, 2));
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('Email', () => {
|
|
17
|
-
goldilocks((value: string) => customer.setEmail(value), 'string', { min: 1, max: 64 });
|
|
18
|
-
checkType((value: string) => customer.setEmail(value), ['string'], randomString(1, 64));
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('ExternalId', () => {
|
|
22
|
-
goldilocks((value: string) => customer.setExternalId(value), 'string', { min: 1, max: 36 });
|
|
23
|
-
checkType((value: string) => customer.setExternalId(value), ['string'], randomString(1, 36));
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('LegalId', () => {
|
|
27
|
-
goldilocks((value: string) => customer.setLegalId(value), 'string', { min: 1, max: 16 });
|
|
28
|
-
checkType((value: string) => customer.setLegalId(value), ['string'], randomString(1, 16));
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('Mobile', () => {
|
|
32
|
-
goldilocks((value: string) => customer.setMobile(value), 'string', { min: 1, max: 16 });
|
|
33
|
-
});
|
|
34
|
-
it('Name', () => {
|
|
35
|
-
goldilocks((value: string) => customer.setName(value), 'string', { min: 1, max: 64 });
|
|
36
|
-
checkType((value: string) => customer.setName(value), ['string'], randomString(3, 64));
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('DateBirth', () => {
|
|
40
|
-
const falseDateBirth = new Temporal.PlainDate(9999, randomMonth(), randomNumber(1, 30));
|
|
41
|
-
const DateBirth = randomPastDate();
|
|
42
|
-
expect(() => customer.setDateBirth(falseDateBirth)).toThrow();
|
|
43
|
-
customer.setDateBirth(DateBirth);
|
|
44
|
-
expect(customer.dateBirth).toBe(DateBirth);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('billingAddress', () => {
|
|
48
|
-
const falseAddress = randomString(1, 28);
|
|
49
|
-
const trueAddress = `addr_${randomString(24)}`;
|
|
50
|
-
expect(() => (customer._data.billingAddress = falseAddress)).toThrow();
|
|
51
|
-
customer._data.billingAddress = trueAddress;
|
|
52
|
-
expect(customer.billingAddress).toBe(trueAddress);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('shippingAddress', () => {
|
|
56
|
-
const falseAddress = randomString(1, 28);
|
|
57
|
-
const trueAddress = `addr_${randomString(24)}`;
|
|
58
|
-
expect(() => (customer._data.shippingAddress = falseAddress)).toThrow();
|
|
59
|
-
customer._data.shippingAddress = trueAddress;
|
|
60
|
-
expect(customer.shippingAddress).toBe(trueAddress);
|
|
61
|
-
});
|
|
62
|
-
});
|