@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,111 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { StancerValidationError } from '#error/validation-error.js';
|
|
4
|
-
import { IdStub, StubData, StubModel, StubValidator } from '#test/stub/stub-model.js';
|
|
5
|
-
import { randomNumber, randomString } from '#test/test-helper.js';
|
|
6
|
-
|
|
7
|
-
describe('stub model', () => {
|
|
8
|
-
describe('constructor', () => {
|
|
9
|
-
it('should be created without anything', () => {
|
|
10
|
-
const stub = new StubModel(StubValidator);
|
|
11
|
-
expect(stub.id).toBeUndefined();
|
|
12
|
-
expect(stub._data).toEqual({});
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should be created with good ID', () => {
|
|
16
|
-
const id = 'stub_' + randomString(24, 24);
|
|
17
|
-
const stub = new StubModel(StubValidator, id);
|
|
18
|
-
expect(stub.id).toEqual(id);
|
|
19
|
-
expect(stub._data).toEqual({ id: id });
|
|
20
|
-
expect(stub._data.getMutations()).toStrictEqual({ id });
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("shouldn't be created with bad ID", () => {
|
|
24
|
-
const id = randomString(22, 24);
|
|
25
|
-
expect(() => new StubModel(StubValidator, id)).toThrow();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("shouldn't accept custom bad data", () => {
|
|
29
|
-
const data: Partial<StubData> = {
|
|
30
|
-
id: randomString(24, 25) as IdStub,
|
|
31
|
-
default: randomString(12, 25),
|
|
32
|
-
};
|
|
33
|
-
expect(() => new StubModel(StubValidator, data)).toThrow();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should accept custom good data', () => {
|
|
37
|
-
const id = ('stub_' + randomString(24)) as IdStub;
|
|
38
|
-
const defaultValue = randomString(28, 32);
|
|
39
|
-
const data: Partial<StubData> = {
|
|
40
|
-
id,
|
|
41
|
-
default: defaultValue,
|
|
42
|
-
};
|
|
43
|
-
const stub = new StubModel(StubValidator, data);
|
|
44
|
-
expect(stub._data).toEqual(data);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
describe('Id setter', () => {
|
|
49
|
-
it('should accept good Id', () => {
|
|
50
|
-
const id = 'stub_' + randomString(24, 24);
|
|
51
|
-
const stub = new StubModel(StubValidator, id);
|
|
52
|
-
expect(stub._data.id).toStrictEqual(id);
|
|
53
|
-
expect(stub.id).toStrictEqual(id);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should refuse bad ID', () => {
|
|
57
|
-
const falseId = randomString(12, 24);
|
|
58
|
-
expect(() => new StubModel(StubValidator, falseId)).toThrow(StancerValidationError);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe('default setter', () => {
|
|
63
|
-
it('should accept good string length', () => {
|
|
64
|
-
const stub = new StubModel(StubValidator);
|
|
65
|
-
const defaultValue = randomString(1, 63);
|
|
66
|
-
stub.setDefault(defaultValue);
|
|
67
|
-
expect(stub.default).toBe(defaultValue);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it("shouldn't accept bad value", () => {
|
|
71
|
-
const stub = new StubModel(StubValidator);
|
|
72
|
-
//We want to hard prevent bad typing
|
|
73
|
-
expect(() => stub.setDefault(12)).toThrow();
|
|
74
|
-
expect(() => stub.setDefault(randomString(65, 100))).toThrow();
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
describe('DefaultNumber setter', () => {
|
|
79
|
-
it('should accept good number', () => {
|
|
80
|
-
const stub = new StubModel(StubValidator);
|
|
81
|
-
const defaultNumber = randomNumber(1, 263);
|
|
82
|
-
stub.setDefaultNumber(defaultNumber);
|
|
83
|
-
expect(stub.defaultNumber).toBe(defaultNumber);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it("shouldn't accept bad value", () => {
|
|
87
|
-
const stub = new StubModel(StubValidator);
|
|
88
|
-
const defaultNumber = randomNumber(265, 30000);
|
|
89
|
-
expect(() => stub.setDefaultNumber(defaultNumber)).toThrow();
|
|
90
|
-
expect(() => stub.setDefaultNumber('string')).toThrow();
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
describe('boolean property', () => {
|
|
95
|
-
it('should accept boolean', () => {
|
|
96
|
-
const stub = new StubModel(StubValidator);
|
|
97
|
-
const boolValue = true;
|
|
98
|
-
stub.setUngettable(boolValue);
|
|
99
|
-
expect(stub._data.ungettable).toBe(boolValue);
|
|
100
|
-
stub.setAllAuthorized(boolValue);
|
|
101
|
-
expect(stub.allAuthorized).toBe(boolValue);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('should have gettable property', () => {
|
|
105
|
-
const stub = new StubModel(StubValidator);
|
|
106
|
-
// direct accession to _data is not validated
|
|
107
|
-
stub._data.unmodifiable = true;
|
|
108
|
-
expect(stub.unmodifiable).toBe(true);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
});
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { AbstractRepository } from '#core/abstract-repository.js';
|
|
4
|
-
import { IdValue } from '#core/common/branded-type.js';
|
|
5
|
-
import { StancerError } from '#error/base-error.js';
|
|
6
|
-
import { StancerRouteInaccessibleError } from '#error/endpoint/route-inaccessible-error.js';
|
|
7
|
-
import ListModelFixtures from '#test/fixtures/list-model.stub.js';
|
|
8
|
-
import ModelFixtures from '#test/fixtures/model.stub.js';
|
|
9
|
-
import { StubEndpoint } from '#test/stub/stub-endpoint.js';
|
|
10
|
-
import { IdStub, StubModel, StubValidator } from '#test/stub/stub-model.js';
|
|
11
|
-
import { StubRepository } from '#test/stub/stub-repository.js';
|
|
12
|
-
import { randomNumber, randomString } from '#test/test-helper.js';
|
|
13
|
-
|
|
14
|
-
const stancerErrorID = 'stub_unidentifiedError' + randomString(7);
|
|
15
|
-
const stancerRouteInaccessibleId = 'stub_StancerRouteInnacessible';
|
|
16
|
-
const dataHasBeenSentId = 'stub_DataHasBeenSent' + randomString(9);
|
|
17
|
-
const dataUnmodified = 'stub_unmodifiedData' + randomString(10);
|
|
18
|
-
class MockApiEndpoint {
|
|
19
|
-
constructor() {}
|
|
20
|
-
list() {
|
|
21
|
-
async function* listGenerator() {
|
|
22
|
-
yield* ListModelFixtures;
|
|
23
|
-
}
|
|
24
|
-
return listGenerator();
|
|
25
|
-
}
|
|
26
|
-
delete() {
|
|
27
|
-
return ModelFixtures;
|
|
28
|
-
}
|
|
29
|
-
send(id: IdValue, data: Record<string, unknown>) {
|
|
30
|
-
if (id) {
|
|
31
|
-
if (id === stancerErrorID) {
|
|
32
|
-
throw new StancerError();
|
|
33
|
-
}
|
|
34
|
-
if (id === stancerRouteInaccessibleId) {
|
|
35
|
-
throw new StancerRouteInaccessibleError('PATCH', 'stub');
|
|
36
|
-
}
|
|
37
|
-
if (id === dataUnmodified) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return { ...data, id: dataHasBeenSentId };
|
|
42
|
-
}
|
|
43
|
-
get() {
|
|
44
|
-
return ModelFixtures;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
it('can be instanciated', () => {
|
|
48
|
-
const instance = new StubRepository();
|
|
49
|
-
expect(instance).toBeInstanceOf(StubRepository);
|
|
50
|
-
expect(instance).toBeInstanceOf(AbstractRepository);
|
|
51
|
-
expect(instance.endpoint).toBeInstanceOf(StubEndpoint);
|
|
52
|
-
expect(instance.validator).toBe(StubValidator);
|
|
53
|
-
expect(instance.staticModel).toBe(StubModel);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe('repository', () => {
|
|
57
|
-
const mockRepo = new MockApiEndpoint() as unknown as StubEndpoint; // I lie, for convenience sake
|
|
58
|
-
const repository = new StubRepository(mockRepo);
|
|
59
|
-
|
|
60
|
-
describe('create', () => {
|
|
61
|
-
it("doesn't accept bad data", async () => {
|
|
62
|
-
const badID = randomString(30, 56);
|
|
63
|
-
await expect(async () => await repository.create(badID)).rejects.toThrow();
|
|
64
|
-
const badID2 = randomNumber(1, 12);
|
|
65
|
-
await expect(async () => await repository.create(badID2)).rejects.toThrow();
|
|
66
|
-
const badData = { default: randomNumber(1, 12) };
|
|
67
|
-
await expect(async () => await repository.create(badData)).rejects.toThrow();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('accept good data', async () => {
|
|
71
|
-
const id = 'stub_' + randomString(24);
|
|
72
|
-
const model = await repository.create(id);
|
|
73
|
-
expect(model).toBeInstanceOf(StubModel);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('delete', async () => {
|
|
78
|
-
const modelWithoutId = await repository.create(ModelFixtures);
|
|
79
|
-
await expect(() => repository.delete(modelWithoutId)).rejects.toThrow();
|
|
80
|
-
|
|
81
|
-
const model = await repository.create({ ...ModelFixtures, id: ('stub_' + randomString(24)) as IdStub });
|
|
82
|
-
await expect((await repository.delete(model))._data).toStrictEqual(ModelFixtures);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
describe('send', () => {
|
|
86
|
-
it('should return model', async () => {
|
|
87
|
-
const model = await repository.create(ModelFixtures);
|
|
88
|
-
const sentModel = await repository.send(model);
|
|
89
|
-
expect(sentModel).toStrictEqual(model);
|
|
90
|
-
expect(sentModel._data.id).toEqual(dataHasBeenSentId);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('should throw on inprecise error', async () => {
|
|
94
|
-
const model = await repository.create({ ...ModelFixtures, id: stancerErrorID as IdStub });
|
|
95
|
-
await expect(() => repository.send(model)).rejects.toThrow(StancerError);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('should return error on StancerRouteInacessibleError', async () => {
|
|
99
|
-
const model = await repository.create({ ...ModelFixtures, id: stancerRouteInaccessibleId as IdStub });
|
|
100
|
-
await expect(async () => await repository.send(model)).rejects.toThrow(StancerRouteInaccessibleError);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('should return unmodified model when no new Data', async () => {
|
|
104
|
-
const model = await repository.create({ ...ModelFixtures, id: dataUnmodified as IdStub });
|
|
105
|
-
const sentModel = await repository.send(model);
|
|
106
|
-
expect(model).toStrictEqual(sentModel);
|
|
107
|
-
expect(sentModel._data.id).toEqual(dataUnmodified);
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
describe('populate', () => {
|
|
112
|
-
it('should not modify model if no Id', async () => {
|
|
113
|
-
const getEndpoint = vi.spyOn(mockRepo, 'get');
|
|
114
|
-
const model = await repository.create(ModelFixtures);
|
|
115
|
-
expect(model).toBeInstanceOf(StubModel);
|
|
116
|
-
expect(getEndpoint).toHaveBeenCalledTimes(0);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('should get model if only id', async () => {
|
|
120
|
-
const getEndpoint = vi.spyOn(mockRepo, 'get');
|
|
121
|
-
const model = await repository.create(('stub_' + randomString(24)) as IdStub);
|
|
122
|
-
expect(model).toBeInstanceOf(StubModel);
|
|
123
|
-
expect(getEndpoint).toHaveBeenCalledTimes(1);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
describe('list', async () => {
|
|
128
|
-
it('return correct model one by one', async () => {
|
|
129
|
-
const listStub = repository.list();
|
|
130
|
-
const item1 = await listStub.next();
|
|
131
|
-
expect(item1.done).toBeFalsy();
|
|
132
|
-
expect(item1.value).toHaveProperty('id');
|
|
133
|
-
expect(item1.value).toBeInstanceOf(StubModel);
|
|
134
|
-
|
|
135
|
-
const item2 = await listStub.next();
|
|
136
|
-
expect(item2.done).toBeFalsy();
|
|
137
|
-
expect(item2.value).toHaveProperty('id');
|
|
138
|
-
expect(item2.value).toBeInstanceOf(StubModel);
|
|
139
|
-
|
|
140
|
-
const item3 = await listStub.next();
|
|
141
|
-
expect(item3.done).toBeTruthy();
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"declaration": true,
|
|
4
|
-
"declarationMap": true,
|
|
5
|
-
"esModuleInterop": true,
|
|
6
|
-
"exactOptionalPropertyTypes": true,
|
|
7
|
-
"isolatedModules": true,
|
|
8
|
-
"lib": [
|
|
9
|
-
"ESNext"
|
|
10
|
-
],
|
|
11
|
-
"module": "NodeNext",
|
|
12
|
-
"moduleDetection": "force",
|
|
13
|
-
"noFallthroughCasesInSwitch": true,
|
|
14
|
-
"noImplicitOverride": true,
|
|
15
|
-
"noImplicitReturns": true,
|
|
16
|
-
"noPropertyAccessFromIndexSignature": true,
|
|
17
|
-
"noUncheckedIndexedAccess": true,
|
|
18
|
-
"noUncheckedSideEffectImports": true,
|
|
19
|
-
"noUnusedLocals": true,
|
|
20
|
-
"noUnusedParameters": true,
|
|
21
|
-
"outDir": "./dist",
|
|
22
|
-
"paths": {
|
|
23
|
-
"#api/*": [
|
|
24
|
-
"./src/api-endpoint/*"
|
|
25
|
-
],
|
|
26
|
-
"#error/*": [
|
|
27
|
-
"./src/core/error/*"
|
|
28
|
-
],
|
|
29
|
-
"#core/*": [
|
|
30
|
-
"./src/core/*"
|
|
31
|
-
],
|
|
32
|
-
"#test/*": [
|
|
33
|
-
"./test/*"
|
|
34
|
-
]
|
|
35
|
-
},
|
|
36
|
-
"resolveJsonModule": true,
|
|
37
|
-
"rootDir": "./src",
|
|
38
|
-
"skipLibCheck": true,
|
|
39
|
-
"sourceMap": true,
|
|
40
|
-
"strict": true,
|
|
41
|
-
"target": "ESNext",
|
|
42
|
-
"types": [
|
|
43
|
-
"node"
|
|
44
|
-
],
|
|
45
|
-
"verbatimModuleSyntax": true
|
|
46
|
-
},
|
|
47
|
-
"include": [
|
|
48
|
-
"./src/"
|
|
49
|
-
]
|
|
50
|
-
}
|
package/vitest.config.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vitest/config';
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
test: {
|
|
5
|
-
coverage: {
|
|
6
|
-
enabled: true,
|
|
7
|
-
exclude: [
|
|
8
|
-
'**/dist',
|
|
9
|
-
'**/*.config.ts',
|
|
10
|
-
'**/*.ignore.ts',
|
|
11
|
-
'**/*.js',
|
|
12
|
-
],
|
|
13
|
-
provider: 'v8',
|
|
14
|
-
reporter: ['cobertura', 'html', 'text'],
|
|
15
|
-
reportsDirectory: 'reports/',
|
|
16
|
-
},
|
|
17
|
-
outputFile: 'reports/junit.xml',
|
|
18
|
-
reporters: ['default', 'junit'],
|
|
19
|
-
},
|
|
20
|
-
});
|