@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,134 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { AddressApiEndpoint } from '#address/api-endpoint.js';
|
|
4
|
-
import { IdAddress, idAddress } from '#address/model.js';
|
|
5
|
-
import { StancerRouteInaccessibleError } from '#error/endpoint/route-inaccessible-error.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('address api endpoint', () => {
|
|
36
|
-
describe('Serialize/Deserialize Resources', () => {
|
|
37
|
-
const endpoint = new AddressApiEndpoint();
|
|
38
|
-
|
|
39
|
-
it('test deserialize Resource', () => {
|
|
40
|
-
const deserializedResources = endpoint.deserializeResource(endpointResource);
|
|
41
|
-
expect(deserializedResources).toMatchObject(endpointResourceDeserialized);
|
|
42
|
-
expect(endpointResourceDeserialized).toMatchObject(deserializedResources);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('test post serialize Resource', () => {
|
|
46
|
-
const serializedResources = endpoint.postObjectSerializer(
|
|
47
|
-
endpointResourceDeserialized,
|
|
48
|
-
) as typeof endpointResource;
|
|
49
|
-
// We extract the API generated Data and the non postable data from our endpoint resources.
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
51
|
-
const { deleted, created_at, id, ...postObject } = endpointResource;
|
|
52
|
-
expect(serializedResources).toMatchObject(postObject);
|
|
53
|
-
expect(postObject).toMatchObject(serializedResources);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('test patch serialize Resource', () => {
|
|
57
|
-
const serializedResources = endpoint.patchObjectSerializer(
|
|
58
|
-
endpointResourceDeserialized,
|
|
59
|
-
) as typeof endpointResource;
|
|
60
|
-
// We extract the API generated Data and the non patchable data from our endpoint resources.
|
|
61
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
62
|
-
const { deleted, created_at, id, ...patchObject } = endpointResource;
|
|
63
|
-
expect(serializedResources).toMatchObject(patchObject);
|
|
64
|
-
expect(patchObject).toMatchObject(serializedResources);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
describe('endpoint path', () => {
|
|
69
|
-
it('endpoint url', () => {
|
|
70
|
-
const endpoint = new AddressApiEndpoint();
|
|
71
|
-
const id = ('addr_' + randomString(24)) as IdAddress;
|
|
72
|
-
expect(endpoint.endpointUrl(id)).toStrictEqual(`https://api.stancer.com/v2/addresses/${id}`);
|
|
73
|
-
expect(endpoint.endpointUrl()).toStrictEqual('https://api.stancer.com/v2/addresses/');
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
describe('verbs', () => {
|
|
78
|
-
const addressEndpoint = new AddressApiEndpoint();
|
|
79
|
-
|
|
80
|
-
it('get', async () => {
|
|
81
|
-
const responseWithId = await addressEndpoint.get(('addr_' + randomString(24)) as IdAddress);
|
|
82
|
-
expect(responseWithId).toStrictEqual(endpointResourceDeserialized);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
describe('post', () => {
|
|
86
|
-
it('has all required field', async () => {
|
|
87
|
-
const responseWithId = await addressEndpoint.post({
|
|
88
|
-
zipCode: randomString(2, 16),
|
|
89
|
-
country: randomString(2),
|
|
90
|
-
city: randomString(1, 64),
|
|
91
|
-
});
|
|
92
|
-
expect(responseWithId).toStrictEqual(endpointResourceDeserialized);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('patch', async () => {
|
|
97
|
-
expect(() => addressEndpoint.patch(('addr_' + randomString(24), {}) as IdAddress, endpointResource)).toThrow(
|
|
98
|
-
'PATCH is not allowed for addresses',
|
|
99
|
-
);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('delete', async () => {
|
|
103
|
-
expect(await addressEndpoint.delete(('addr_' + randomString(24)) as IdAddress)).toStrictEqual(
|
|
104
|
-
endpointResourceDeserialized,
|
|
105
|
-
);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
describe('send', () => {
|
|
110
|
-
const { city, country, zipCode } = endpointResourceDeserialized;
|
|
111
|
-
|
|
112
|
-
it('send with required data', async () => {
|
|
113
|
-
const endpoint = new AddressApiEndpoint();
|
|
114
|
-
await expect(endpoint.send(undefined, { city, country, zipCode })).resolves.toStrictEqual(
|
|
115
|
-
endpointResourceDeserialized,
|
|
116
|
-
);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('no patch if id', async () => {
|
|
120
|
-
const endpoint = new AddressApiEndpoint();
|
|
121
|
-
const id = idAddress('addr_' + randomString(24));
|
|
122
|
-
expect(() => endpoint.send(id, { id, city, country, zipCode })).toThrow(StancerRouteInaccessibleError);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('post if no id', () => {
|
|
126
|
-
const endpoint = new AddressApiEndpoint();
|
|
127
|
-
const spyonPatch = vi.spyOn(endpoint, 'patch');
|
|
128
|
-
const spyonPost = vi.spyOn(endpoint, 'post');
|
|
129
|
-
endpoint.send(undefined, { city, country, zipCode });
|
|
130
|
-
expect(spyonPatch).toHaveBeenCalledTimes(0);
|
|
131
|
-
expect(spyonPost).toHaveBeenCalledTimes(1);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
});
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { Temporal } from 'temporal-polyfill';
|
|
2
|
-
|
|
3
|
-
import { idAddress } from '#address/model.js';
|
|
4
|
-
import { randomNumber, randomString } from '#test/test-helper.js';
|
|
5
|
-
|
|
6
|
-
const city = randomString(1, 50);
|
|
7
|
-
const country = randomString(2);
|
|
8
|
-
// arbitrary future timestamp, we don't really care about it except that is is a timestamp
|
|
9
|
-
const created_at = randomNumber(1786460000, 2000000000);
|
|
10
|
-
const deleted = false;
|
|
11
|
-
const id = idAddress('addr_' + randomString(24));
|
|
12
|
-
const line1 = randomString(1, 50);
|
|
13
|
-
const line2 = randomString(1, 50);
|
|
14
|
-
const line3 = randomString(1, 50);
|
|
15
|
-
const state = randomString(1, 3);
|
|
16
|
-
const zip_code = randomString(2, 16);
|
|
17
|
-
|
|
18
|
-
export const endpointResource = {
|
|
19
|
-
city,
|
|
20
|
-
country,
|
|
21
|
-
created_at, // actual API field in snake_case
|
|
22
|
-
deleted,
|
|
23
|
-
id,
|
|
24
|
-
line1,
|
|
25
|
-
line2,
|
|
26
|
-
line3,
|
|
27
|
-
state,
|
|
28
|
-
zip_code, // actual API field in snake_case
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export const endpointResourceDeserialized = {
|
|
32
|
-
city,
|
|
33
|
-
country,
|
|
34
|
-
createdAt: Temporal.Instant.fromEpochMilliseconds(created_at * 1000),
|
|
35
|
-
deleted,
|
|
36
|
-
id,
|
|
37
|
-
line1,
|
|
38
|
-
line2,
|
|
39
|
-
line3,
|
|
40
|
-
state,
|
|
41
|
-
zipCode: zip_code,
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export const creationResource = {
|
|
45
|
-
city,
|
|
46
|
-
country,
|
|
47
|
-
line1,
|
|
48
|
-
line2,
|
|
49
|
-
line3,
|
|
50
|
-
state,
|
|
51
|
-
zip_code,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export const listResource = [
|
|
55
|
-
endpointResource,
|
|
56
|
-
{
|
|
57
|
-
...endpointResource,
|
|
58
|
-
city: randomString(1, 50),
|
|
59
|
-
},
|
|
60
|
-
];
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { AddressData, AddressModel } from '#address/model.js';
|
|
4
|
-
import { Validator } from '#core/validator.js';
|
|
5
|
-
import { SetterGetter, randomNumber, randomString } from '#test/test-helper.js';
|
|
6
|
-
|
|
7
|
-
describe('Address Class', () => {
|
|
8
|
-
describe('Test Setter & Getters', () => {
|
|
9
|
-
const address = new AddressModel((() => true) as unknown as Validator<AddressData>);
|
|
10
|
-
|
|
11
|
-
it('line1', () => {
|
|
12
|
-
SetterGetter(
|
|
13
|
-
(value: string) => address.setLine1(value),
|
|
14
|
-
() => address.line1,
|
|
15
|
-
randomString(1, 64),
|
|
16
|
-
);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('line2', () => {
|
|
20
|
-
SetterGetter(
|
|
21
|
-
(value: string) => address.setLine2(value),
|
|
22
|
-
() => address.line2,
|
|
23
|
-
randomString(1, 64),
|
|
24
|
-
);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('line3', () => {
|
|
28
|
-
SetterGetter(
|
|
29
|
-
(value: string) => address.setLine3(value),
|
|
30
|
-
() => address.line3,
|
|
31
|
-
randomString(1, 64),
|
|
32
|
-
);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('country', () => {
|
|
36
|
-
SetterGetter(
|
|
37
|
-
(value: string) => address.setCountry(value),
|
|
38
|
-
() => address.country,
|
|
39
|
-
randomString(2, 2),
|
|
40
|
-
);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('zipCode', () => {
|
|
44
|
-
SetterGetter(
|
|
45
|
-
(value: string) => address.setZipCode(value),
|
|
46
|
-
() => address.zipCode,
|
|
47
|
-
randomString(1, 16),
|
|
48
|
-
);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('State', () => {
|
|
52
|
-
SetterGetter(
|
|
53
|
-
(value: string) => address.setState(value),
|
|
54
|
-
() => address.state,
|
|
55
|
-
randomString(1, 3),
|
|
56
|
-
);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('City', () => {
|
|
60
|
-
SetterGetter(
|
|
61
|
-
(value: string) => address.setCity(value),
|
|
62
|
-
() => address.city,
|
|
63
|
-
randomString(1, 50),
|
|
64
|
-
);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('deleted', () => {
|
|
68
|
-
SetterGetter(
|
|
69
|
-
(value: boolean) => (address._data.deleted = value),
|
|
70
|
-
() => address.deleted,
|
|
71
|
-
Boolean(randomNumber(0, 1)),
|
|
72
|
-
);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
});
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { AddressApiEndpoint } from '#address/api-endpoint.js';
|
|
4
|
-
import { AddressModel, IdAddress } from '#address/model.js';
|
|
5
|
-
import { AddressRepository } from '#address/repository.js';
|
|
6
|
-
import { addressValidator } from '#address/validator.js';
|
|
7
|
-
import { AbstractRepository } from '#core/abstract-repository.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 = 'addr';
|
|
15
|
-
const id = `${idPrefix}_${randomString(24)}` as IdAddress;
|
|
16
|
-
const stancerErrorID = `${idPrefix}_unidentifiedError${randomString(7)}`;
|
|
17
|
-
const stancerRouteInaccessibleId = `${idPrefix}_StancerRouteInnacessible` as string;
|
|
18
|
-
const dataHasBeenSentId = `${idPrefix}_DataHasBeenSent${randomString(9)}`;
|
|
19
|
-
const dataUnmodified = `${idPrefix}_unmodifiedData${randomString(10)}`;
|
|
20
|
-
class MockApiEndpoint {
|
|
21
|
-
constructor() {}
|
|
22
|
-
|
|
23
|
-
list() {
|
|
24
|
-
async function* listGenerator() {
|
|
25
|
-
yield* listResource;
|
|
26
|
-
}
|
|
27
|
-
return listGenerator();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
delete() {
|
|
31
|
-
return endpointResource;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
send(id: IdAddress, data: Record<string, unknown>) {
|
|
35
|
-
if (id) {
|
|
36
|
-
if (id === stancerErrorID) {
|
|
37
|
-
throw new StancerError();
|
|
38
|
-
}
|
|
39
|
-
if (id === stancerRouteInaccessibleId) {
|
|
40
|
-
throw new StancerRouteInaccessibleError('PATCH', 'stub');
|
|
41
|
-
}
|
|
42
|
-
if (id === dataUnmodified) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return { ...data, id: dataHasBeenSentId };
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
get() {
|
|
50
|
-
return endpointResource;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
it('can be instanciated', () => {
|
|
55
|
-
const instance = new AddressRepository();
|
|
56
|
-
expect(instance).toBeInstanceOf(AddressRepository);
|
|
57
|
-
expect(instance).toBeInstanceOf(AbstractRepository);
|
|
58
|
-
//accessing private method & property
|
|
59
|
-
expect(instance.endpoint).toBeInstanceOf(AddressApiEndpoint);
|
|
60
|
-
expect(instance.validator).toBe(addressValidator);
|
|
61
|
-
expect(instance.staticModel).toBe(AddressModel);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
describe('repository', () => {
|
|
65
|
-
const mockRepo = new MockApiEndpoint() as unknown as AddressApiEndpoint; // I lie, for convenience sake
|
|
66
|
-
const repository = new AddressRepository(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(AddressModel);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('delete', async () => {
|
|
82
|
-
const modelWithoutId = await repository.create();
|
|
83
|
-
await expect(() => repository.delete(modelWithoutId)).rejects.toThrow();
|
|
84
|
-
const zip_code = endpointResource.zip_code;
|
|
85
|
-
const model = await repository.create({ id: endpointResource.id, zip_code });
|
|
86
|
-
await expect((await repository.delete(model))._data).toStrictEqual(endpointResource);
|
|
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 IdAddress });
|
|
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 IdAddress });
|
|
104
|
-
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 IdAddress });
|
|
109
|
-
const sentModel = await repository.send(model);
|
|
110
|
-
expect(model).toStrictEqual(sentModel);
|
|
111
|
-
expect(sentModel._data.id).toEqual(dataUnmodified);
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
describe('populate', () => {
|
|
116
|
-
it('should not modify model if no Id', async () => {
|
|
117
|
-
const getEndpoint = vi.spyOn(mockRepo, 'get');
|
|
118
|
-
const model = await repository.create(creationResource);
|
|
119
|
-
expect(model).toBeInstanceOf(AddressModel);
|
|
120
|
-
expect(getEndpoint).toHaveBeenCalledTimes(0);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('should get model if only id', async () => {
|
|
124
|
-
const getEndpoint = vi.spyOn(mockRepo, 'get');
|
|
125
|
-
const model = await repository.create(id);
|
|
126
|
-
expect(model).toBeInstanceOf(AddressModel);
|
|
127
|
-
expect(getEndpoint).toHaveBeenCalledTimes(1);
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
describe('list', async () => {
|
|
132
|
-
it('return correct model one by one', async () => {
|
|
133
|
-
const listStub = repository.list();
|
|
134
|
-
const item1 = await listStub.next();
|
|
135
|
-
expect(item1.done).toBeFalsy();
|
|
136
|
-
expect(item1.value).toHaveProperty('id');
|
|
137
|
-
expect(item1.value).toBeInstanceOf(AddressModel);
|
|
138
|
-
|
|
139
|
-
const item2 = await listStub.next();
|
|
140
|
-
expect(item2.done).toBeFalsy();
|
|
141
|
-
expect(item2.value).toHaveProperty('id');
|
|
142
|
-
expect(item2.value).toBeInstanceOf(AddressModel);
|
|
143
|
-
|
|
144
|
-
const item3 = await listStub.next();
|
|
145
|
-
expect(item3.done).toBeTruthy();
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { addressValidator } from '#address/validator.js';
|
|
4
|
-
import { processValidator } from '#core/validator.js';
|
|
5
|
-
import { checkType, goldilocks, randomString } from '#test/test-helper.js';
|
|
6
|
-
|
|
7
|
-
const validator = processValidator(addressValidator);
|
|
8
|
-
|
|
9
|
-
describe('Test boundaries', () => {
|
|
10
|
-
const goldilocksLine = (line: CallableFunction) => goldilocks(line, 'string', { min: 1, max: 50 });
|
|
11
|
-
|
|
12
|
-
it('line1', () => {
|
|
13
|
-
goldilocksLine((value: string) => validator('line1', value));
|
|
14
|
-
checkType((value: string) => validator('line1', value), ['string'], randomString(1, 50));
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('line2', () => {
|
|
18
|
-
goldilocksLine((value: string) => validator('line2', value));
|
|
19
|
-
|
|
20
|
-
checkType((value: string) => validator('line2', value), ['string'], randomString(1, 50));
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('line3', () => {
|
|
24
|
-
goldilocksLine((value: string) => validator('line3', value));
|
|
25
|
-
|
|
26
|
-
checkType((value: string) => validator('line3', value), ['string'], randomString(1, 50));
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('ZipCode', () => {
|
|
30
|
-
goldilocks((value: string) => validator('zipCode', value), 'string', { min: 2, max: 16 });
|
|
31
|
-
checkType((value: string) => validator('zipCode', value), ['string'], randomString(2, 16));
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('state', () => {
|
|
35
|
-
goldilocks((value: string) => validator('state', value), 'string', { min: 1, max: 3 });
|
|
36
|
-
|
|
37
|
-
checkType((value: string) => validator('state', value), ['string'], randomString(1, 3));
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('country', () => {
|
|
41
|
-
goldilocks((value: string) => validator('country', value), 'string', { min: 2, max: 2 });
|
|
42
|
-
checkType((value: string) => validator('country', value), ['string'], randomString(2, 2));
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('city', () => {
|
|
46
|
-
goldilocks((value: string) => validator('city', value), 'string', { min: 1, max: 50 });
|
|
47
|
-
checkType((value: string) => validator('city', value), ['string'], randomString(1, 50));
|
|
48
|
-
});
|
|
49
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { httpClient } from '#api/http/fetch-http-client.js';
|
|
4
|
-
import { Http } from '#api/http/index.js';
|
|
5
|
-
import { mockFetch, randomString } from '#test/test-helper.js';
|
|
6
|
-
|
|
7
|
-
describe('test fetch client', () => {
|
|
8
|
-
it('uses base user agent', async () => {
|
|
9
|
-
// as we only touch headers in this function we will just look for headers in the response
|
|
10
|
-
const resolver = (url: string, req: Http.Request) => req.headers;
|
|
11
|
-
|
|
12
|
-
const cleaner = mockFetch(resolver);
|
|
13
|
-
const request: Http.Request = {
|
|
14
|
-
url: randomString(1, 24),
|
|
15
|
-
method: 'DELETE',
|
|
16
|
-
_tag: 'HttpClientRequest',
|
|
17
|
-
headers: {},
|
|
18
|
-
};
|
|
19
|
-
const response = await httpClient.makeRequest(request);
|
|
20
|
-
expect(response).haveOwnProperty('status');
|
|
21
|
-
expect(response).haveOwnProperty('json');
|
|
22
|
-
const json: typeof request.headers = await response.json();
|
|
23
|
-
expect(json).toEqual({ 'user-agent': 'Stancer fetch' });
|
|
24
|
-
cleaner();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('uses custom user agent', async () => {
|
|
28
|
-
const userAgent = randomString(12, 24);
|
|
29
|
-
// as we only touch headers in this function we will just look for headers in the response
|
|
30
|
-
const resolver = (url: string, req: Http.Request) => req.headers;
|
|
31
|
-
const cleaner = mockFetch(resolver);
|
|
32
|
-
const request: Http.Request = {
|
|
33
|
-
url: randomString(1, 12),
|
|
34
|
-
method: 'DELETE',
|
|
35
|
-
headers: { 'user-agent': userAgent },
|
|
36
|
-
};
|
|
37
|
-
const response = await httpClient.makeRequest(request);
|
|
38
|
-
expect(response).haveOwnProperty('status');
|
|
39
|
-
expect(response).haveOwnProperty('json');
|
|
40
|
-
const json: typeof request.headers = await response.json();
|
|
41
|
-
expect(json).toEqual({ 'user-agent': `${userAgent}` });
|
|
42
|
-
cleaner();
|
|
43
|
-
});
|
|
44
|
-
});
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { Request, Response, createRequest, handleHttpResponseErrors, transformResponseToData } from '#api/http/http.js';
|
|
4
|
-
import {
|
|
5
|
-
StancerApiConflictError,
|
|
6
|
-
StancerApiError,
|
|
7
|
-
StancerApiNotFoundError,
|
|
8
|
-
StancerApiUnauthorizedError,
|
|
9
|
-
StancerApiValidationError,
|
|
10
|
-
} from '#error/endpoint/api/index.js';
|
|
11
|
-
import { randomString } from '#test/test-helper.js';
|
|
12
|
-
|
|
13
|
-
describe('Test http', () => {
|
|
14
|
-
describe('createRequest', () => {
|
|
15
|
-
it('Create request authenticate, with a body', () => {
|
|
16
|
-
const url = randomString(1, 45);
|
|
17
|
-
const body = randomString(1, 25);
|
|
18
|
-
const method = 'GET';
|
|
19
|
-
const req: Omit<Request, '_tag'> & { authenticated?: boolean } = {
|
|
20
|
-
authenticated: true,
|
|
21
|
-
headers: {
|
|
22
|
-
one: randomString(10, 24),
|
|
23
|
-
two: randomString(11, 45),
|
|
24
|
-
},
|
|
25
|
-
url,
|
|
26
|
-
method,
|
|
27
|
-
body,
|
|
28
|
-
};
|
|
29
|
-
const request = createRequest(req);
|
|
30
|
-
expect(request).toHaveProperty('url');
|
|
31
|
-
expect(request.url).toBe(url);
|
|
32
|
-
expect(request).toHaveProperty('method');
|
|
33
|
-
expect(request.method).toBe(method);
|
|
34
|
-
expect(request).toHaveProperty('body');
|
|
35
|
-
expect(request.body).toBe(body);
|
|
36
|
-
expect(request).toHaveProperty('authenticated');
|
|
37
|
-
expect(request.authenticated).toBe(true);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('Create request unauthenticated, with a body', () => {
|
|
41
|
-
const url = randomString(1, 45);
|
|
42
|
-
const body = randomString(1, 25);
|
|
43
|
-
const method = 'GET';
|
|
44
|
-
const req: Omit<Request, '_tag'> & { authenticated?: boolean } = {
|
|
45
|
-
authenticated: false,
|
|
46
|
-
headers: {
|
|
47
|
-
one: randomString(10, 24),
|
|
48
|
-
two: randomString(11, 45),
|
|
49
|
-
},
|
|
50
|
-
url,
|
|
51
|
-
method,
|
|
52
|
-
body,
|
|
53
|
-
};
|
|
54
|
-
const request = createRequest(req);
|
|
55
|
-
expect(request).toHaveProperty('url');
|
|
56
|
-
expect(request.url).toBe(url);
|
|
57
|
-
expect(request).toHaveProperty('method');
|
|
58
|
-
expect(request.method).toBe(method);
|
|
59
|
-
expect(request).toHaveProperty('body');
|
|
60
|
-
expect(request.body).toBe(body);
|
|
61
|
-
expect(request).toHaveProperty('authenticated');
|
|
62
|
-
expect(request.authenticated).toBe(false);
|
|
63
|
-
});
|
|
64
|
-
it('Create request authenticated, with nobody', () => {
|
|
65
|
-
const url = randomString(1, 45);
|
|
66
|
-
const body = undefined;
|
|
67
|
-
const method = 'GET';
|
|
68
|
-
const req: Omit<Request, '_tag'> & { authenticated?: boolean } = {
|
|
69
|
-
authenticated: true,
|
|
70
|
-
headers: {
|
|
71
|
-
one: randomString(10, 24),
|
|
72
|
-
two: randomString(11, 45),
|
|
73
|
-
},
|
|
74
|
-
url,
|
|
75
|
-
method,
|
|
76
|
-
body,
|
|
77
|
-
};
|
|
78
|
-
const request = createRequest(req);
|
|
79
|
-
expect(request).toHaveProperty('url');
|
|
80
|
-
expect(request.url).toBe(url);
|
|
81
|
-
expect(request).toHaveProperty('method');
|
|
82
|
-
expect(request.method).toBe(method);
|
|
83
|
-
expect(request).toHaveProperty('body');
|
|
84
|
-
expect(request.body).toBeUndefined();
|
|
85
|
-
expect(request).toHaveProperty('authenticated');
|
|
86
|
-
expect(request.authenticated).toBe(true);
|
|
87
|
-
});
|
|
88
|
-
it('Create request unauthenticated, with nobody', () => {
|
|
89
|
-
const url = randomString(1, 45);
|
|
90
|
-
const body = undefined;
|
|
91
|
-
const method = 'GET';
|
|
92
|
-
const req: Omit<Request, '_tag'> & { authenticated?: boolean } = {
|
|
93
|
-
authenticated: false,
|
|
94
|
-
headers: {
|
|
95
|
-
one: randomString(10, 24),
|
|
96
|
-
two: randomString(11, 45),
|
|
97
|
-
},
|
|
98
|
-
url,
|
|
99
|
-
method,
|
|
100
|
-
body,
|
|
101
|
-
};
|
|
102
|
-
const request = createRequest(req);
|
|
103
|
-
expect(request).toHaveProperty('url');
|
|
104
|
-
expect(request.url).toBe(url);
|
|
105
|
-
expect(request).toHaveProperty('method');
|
|
106
|
-
expect(request.method).toBe(method);
|
|
107
|
-
expect(request).toHaveProperty('body');
|
|
108
|
-
expect(request.body).toBeUndefined();
|
|
109
|
-
expect(request).toHaveProperty('authenticated');
|
|
110
|
-
expect(request.authenticated).toBe(false);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
describe('handleHttpResponseErrors', () => {
|
|
115
|
-
it.each([
|
|
116
|
-
[401, StancerApiUnauthorizedError],
|
|
117
|
-
[422, StancerApiValidationError],
|
|
118
|
-
[404, StancerApiNotFoundError],
|
|
119
|
-
[409, StancerApiConflictError],
|
|
120
|
-
[400, StancerApiError],
|
|
121
|
-
[500, StancerApiError],
|
|
122
|
-
])('%d throw appropriate error', async (status, expectedError) => {
|
|
123
|
-
const response: Response = {
|
|
124
|
-
status,
|
|
125
|
-
json: async <T>() => {
|
|
126
|
-
return Promise.resolve({ error: randomString(1, 24) }) as T;
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
await expect(handleHttpResponseErrors(response)).rejects.toThrow(expectedError);
|
|
131
|
-
});
|
|
132
|
-
it('is successful(200)', async () => {
|
|
133
|
-
const response: Response = {
|
|
134
|
-
status: Number(200), //we start at 23 to avoid triggering known exceptions
|
|
135
|
-
json: async <T>() => {
|
|
136
|
-
return { error: randomString(1, 24) } as T;
|
|
137
|
-
},
|
|
138
|
-
};
|
|
139
|
-
await expect(handleHttpResponseErrors(response)).resolves.toStrictEqual(response);
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
describe('transform response to data', () => {
|
|
143
|
-
it('return response.json', async () => {
|
|
144
|
-
const information = randomString(1, 24);
|
|
145
|
-
const response: Response = {
|
|
146
|
-
status: 200,
|
|
147
|
-
json: async <T>() => (await Promise.resolve(information)) as T,
|
|
148
|
-
};
|
|
149
|
-
expect(await transformResponseToData<string>(response)).toStrictEqual(information);
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
});
|