@stancer/stancer 1.0.2 → 1.1.1
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 +12 -1
- package/dist/api-endpoint/http/fetch-http-client.d.ts.map +1 -1
- package/dist/api-endpoint/http/fetch-http-client.js +7 -1
- package/dist/api-endpoint/http/fetch-http-client.js.map +1 -1
- 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/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/index.d.ts +60 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +57 -0
- package/dist/index.js.map +1 -0
- package/dist/payment-intent/api-endpoint.d.ts +16 -1
- package/dist/payment-intent/api-endpoint.d.ts.map +1 -1
- package/dist/payment-intent/api-endpoint.js +2 -1
- package/dist/payment-intent/api-endpoint.js.map +1 -1
- package/dist/payment-intent/model.d.ts +3 -2
- package/dist/payment-intent/model.d.ts.map +1 -1
- package/dist/payment-intent/model.js +6 -0
- package/dist/payment-intent/model.js.map +1 -1
- package/dist/payment-intent/repository.d.ts +1 -1
- package/dist/payment-intent/repository.d.ts.map +1 -1
- 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 +33 -22
- package/dist/main.d.ts +0 -2
- package/dist/main.d.ts.map +0 -1
- package/dist/main.js +0 -2
- package/dist/main.js.map +0 -1
- package/reports/base.css +0 -362
- package/reports/block-navigation.js +0 -75
- package/reports/cobertura-coverage.xml +0 -18
- package/reports/favicon.png +0 -0
- package/reports/index.html +0 -177
- package/reports/junit.xml +0 -25
- package/reports/prettify.css +0 -101
- package/reports/prettify.js +0 -955
- package/reports/sort-arrow-sprite.png +0 -0
- package/reports/sorter.js +0 -205
- package/src/address/api-endpoint.ts +0 -30
- package/src/address/model.ts +0 -79
- package/src/address/repository.ts +0 -18
- package/src/address/validator.ts +0 -34
- package/src/api-endpoint/abstract-api-endpoint.ts +0 -310
- package/src/api-endpoint/configuration.ts +0 -125
- package/src/api-endpoint/http/fetch-http-client.ts +0 -29
- package/src/api-endpoint/http/http.ts +0 -75
- package/src/api-endpoint/http/index.ts +0 -2
- package/src/api-endpoint/version.ts +0 -4
- package/src/card/api-endpoint.ts +0 -39
- package/src/card/enum/funding.ts +0 -11
- package/src/card/enum/nature.ts +0 -7
- package/src/card/enum/network.ts +0 -16
- package/src/card/model.ts +0 -139
- package/src/card/repository.ts +0 -11
- package/src/card/validator.ts +0 -79
- package/src/core/abstract-model.ts +0 -126
- package/src/core/abstract-repository.ts +0 -201
- package/src/core/common/branded-type.ts +0 -15
- package/src/core/common/handler/date-handler.ts +0 -31
- package/src/core/common/handler/enum-handler.ts +0 -18
- package/src/core/common/handler/handler.ts +0 -64
- package/src/core/common/handler/id-handler.ts +0 -27
- package/src/core/common/id-validator.ts +0 -23
- package/src/core/common/mutation-tracked-object.ts +0 -49
- package/src/core/endpoint-interface.ts +0 -43
- package/src/core/error/base-error.ts +0 -1
- package/src/core/error/endpoint/api/api-conflict-error.ts +0 -7
- package/src/core/error/endpoint/api/api-error.ts +0 -10
- package/src/core/error/endpoint/api/api-not-found-error.ts +0 -7
- package/src/core/error/endpoint/api/api-unauthorized-error.ts +0 -7
- package/src/core/error/endpoint/api/api-unknown-error.ts +0 -7
- package/src/core/error/endpoint/api/api-validation-error.ts +0 -13
- package/src/core/error/endpoint/api/index.ts +0 -6
- package/src/core/error/endpoint/route-inaccessible-error.ts +0 -8
- package/src/core/error/unpopulated-error.ts +0 -3
- package/src/core/error/unsendable-error.ts +0 -3
- package/src/core/error/validation-error.ts +0 -3
- package/src/core/validator.ts +0 -129
- package/src/customer/api-endpoint.ts +0 -29
- package/src/customer/model.ts +0 -113
- package/src/customer/repository.ts +0 -14
- package/src/customer/validator.ts +0 -26
- package/src/payment/api-endpoint.ts +0 -118
- package/src/payment/enum/currency.ts +0 -14
- package/src/payment/enum/method.ts +0 -2
- package/src/payment/enum/status.ts +0 -21
- package/src/payment/model.ts +0 -378
- package/src/payment/repository.ts +0 -73
- package/src/payment/validator.ts +0 -96
- package/src/payment-intent/api-endpoint.ts +0 -123
- package/src/payment-intent/enum/status.ts +0 -21
- package/src/payment-intent/enum/threeds.ts +0 -2
- package/src/payment-intent/model.ts +0 -266
- package/src/payment-intent/repository.ts +0 -85
- package/src/payment-intent/validator.ts +0 -45
- package/src/payout/model.ts +0 -8
- package/src/refund/api-endpoint.ts +0 -33
- package/src/refund/enum/refund-status.ts +0 -11
- package/src/refund/model.ts +0 -90
- package/src/refund/repository.ts +0 -14
- package/src/refund/validator.ts +0 -44
- package/src/sepa/api-endpoint.ts +0 -26
- package/src/sepa/model.ts +0 -80
- package/src/sepa/repository.ts +0 -11
- package/src/sepa/validator.ts +0 -56
- 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
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { PaymentApiEndpoint } from '#payment/api-endpoint.js';
|
|
4
|
-
import { CurrencyEnum } from '#payment/enum/currency.js';
|
|
5
|
-
import type { IdPayment } from '#payment/model.js';
|
|
6
|
-
import { randomNumber, 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('payment api endpoint', () => {
|
|
36
|
-
describe('Serialize/Deserialize resources', () => {
|
|
37
|
-
const endpoint = new PaymentApiEndpoint();
|
|
38
|
-
|
|
39
|
-
it('test deserialize resource', async () => {
|
|
40
|
-
const deserializedResources = await 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
|
-
wallet: {},
|
|
49
|
-
}) as typeof endpointResource;
|
|
50
|
-
|
|
51
|
-
// property not in postObject are API generated or not postable
|
|
52
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
53
|
-
const {
|
|
54
|
-
created,
|
|
55
|
-
date_paym,
|
|
56
|
-
date_bank,
|
|
57
|
-
fee,
|
|
58
|
-
method,
|
|
59
|
-
response,
|
|
60
|
-
response_author,
|
|
61
|
-
status,
|
|
62
|
-
origin,
|
|
63
|
-
payout,
|
|
64
|
-
payment_intent,
|
|
65
|
-
id,
|
|
66
|
-
...postObject
|
|
67
|
-
} = endpointResource;
|
|
68
|
-
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
69
|
-
|
|
70
|
-
//Double match to guaranty exact same shape
|
|
71
|
-
//Auth is really special, what we send is not what we receive
|
|
72
|
-
expect(serializedResources).toMatchObject({ ...postObject, auth: true });
|
|
73
|
-
expect({ ...postObject, auth: true }).toMatchObject(serializedResources);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('test patch serialize resource (not available in repository)', () => {
|
|
77
|
-
const serializedResources = endpoint.patchObjectSerializer({
|
|
78
|
-
...endpointResourceDeserialized,
|
|
79
|
-
wallet: {},
|
|
80
|
-
device: { city: 'city' },
|
|
81
|
-
}) as typeof endpointResource;
|
|
82
|
-
|
|
83
|
-
// property not in patchObject are API generated or not patchable
|
|
84
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
85
|
-
const {
|
|
86
|
-
id,
|
|
87
|
-
unique_id,
|
|
88
|
-
created,
|
|
89
|
-
date_bank,
|
|
90
|
-
date_paym,
|
|
91
|
-
fee,
|
|
92
|
-
method,
|
|
93
|
-
origin,
|
|
94
|
-
payment_intent,
|
|
95
|
-
payout,
|
|
96
|
-
response,
|
|
97
|
-
response_author,
|
|
98
|
-
...patchObject
|
|
99
|
-
} = endpointResource;
|
|
100
|
-
/* eslint-enable */
|
|
101
|
-
|
|
102
|
-
//Double match to guaranty exact same shape
|
|
103
|
-
//Auth is really special, what we send is not what we receive
|
|
104
|
-
expect(serializedResources).toMatchObject({ ...patchObject, auth: true });
|
|
105
|
-
expect({ ...patchObject, auth: true }).toMatchObject(serializedResources);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
describe('endpoint path', () => {
|
|
110
|
-
it('endpoint url', () => {
|
|
111
|
-
const endpoint = new PaymentApiEndpoint();
|
|
112
|
-
const id = ('paym_' + randomString(24)) as IdPayment;
|
|
113
|
-
expect(endpoint._getResourceUri(id)).toStrictEqual(`https://api.stancer.com/v2/payments/${id}`);
|
|
114
|
-
expect(endpoint._getResourceUri()).toStrictEqual('https://api.stancer.com/v2/payments/');
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
describe('verbs', () => {
|
|
119
|
-
const paymentEndpoint = new PaymentApiEndpoint();
|
|
120
|
-
|
|
121
|
-
it('get', async () => {
|
|
122
|
-
const responseWithId = await paymentEndpoint.get(('paym_' + randomString(24)) as IdPayment);
|
|
123
|
-
expect(await responseWithId).toStrictEqual(endpointResourceDeserialized);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('post no deserialization', async () => {
|
|
127
|
-
const responseWithId = await paymentEndpoint.post({
|
|
128
|
-
amount: randomNumber(0, 1000000),
|
|
129
|
-
currency: CurrencyEnum[randomNumber(0, CurrencyEnum.length - 1)],
|
|
130
|
-
});
|
|
131
|
-
expect(responseWithId).toStrictEqual(endpointResourceDeserialized);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('patch', async () => {
|
|
135
|
-
const patchResponse = await paymentEndpoint.patch(('paym_' + randomString(24)) as IdPayment, endpointResource);
|
|
136
|
-
expect(patchResponse).toStrictEqual(endpointResourceDeserialized);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('delete', async () => {
|
|
140
|
-
expect(await paymentEndpoint.delete(('paym_' + randomString(24)) as IdPayment)).toStrictEqual(
|
|
141
|
-
endpointResourceDeserialized,
|
|
142
|
-
);
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
describe('send', () => {
|
|
147
|
-
const { amount, currency } = endpointResourceDeserialized;
|
|
148
|
-
|
|
149
|
-
it('send with required data', async () => {
|
|
150
|
-
const endpoint = new PaymentApiEndpoint();
|
|
151
|
-
|
|
152
|
-
await expect(endpoint.send(undefined, { amount, currency })).resolves.toStrictEqual(endpointResourceDeserialized);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it('does not post with missing amount', async () => {
|
|
156
|
-
const endpoint = new PaymentApiEndpoint();
|
|
157
|
-
|
|
158
|
-
expect(() => endpoint.send(undefined, { currency })).toThrow();
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('does not post with missing currency', async () => {
|
|
162
|
-
const endpoint = new PaymentApiEndpoint();
|
|
163
|
-
expect(() => endpoint.send(undefined, { amount })).toThrow();
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('Patch if id', async () => {
|
|
167
|
-
const endpoint = new PaymentApiEndpoint();
|
|
168
|
-
const spyonPatch = vi.spyOn(endpoint, 'patch');
|
|
169
|
-
const spyonPost = vi.spyOn(endpoint, 'post');
|
|
170
|
-
|
|
171
|
-
await expect(endpoint.send('paym_' + randomString(24), { currency, amount })).resolves.toStrictEqual(
|
|
172
|
-
endpointResourceDeserialized,
|
|
173
|
-
);
|
|
174
|
-
expect(spyonPatch).toHaveBeenCalledTimes(1);
|
|
175
|
-
expect(spyonPost).toHaveBeenCalledTimes(0);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it('post if no id', () => {
|
|
179
|
-
const endpoint = new PaymentApiEndpoint();
|
|
180
|
-
const spyonPatch = vi.spyOn(endpoint, 'patch');
|
|
181
|
-
const spyonPost = vi.spyOn(endpoint, 'post');
|
|
182
|
-
|
|
183
|
-
endpoint.send(undefined, { currency, amount });
|
|
184
|
-
expect(spyonPatch).toHaveBeenCalledTimes(0);
|
|
185
|
-
expect(spyonPost).toHaveBeenCalledTimes(1);
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
});
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { Temporal } from 'temporal-polyfill';
|
|
2
|
-
|
|
3
|
-
import { CurrencyEnum } from '#payment/enum/currency.js';
|
|
4
|
-
import { MethodEnum } from '#payment/enum/method.js';
|
|
5
|
-
import { StatusEnum } from '#payment/enum/status.js';
|
|
6
|
-
import { Device, paymentAmount } from '#payment/model.js';
|
|
7
|
-
import { randomMonth, randomNumber, randomString } from '#test/test-helper.js';
|
|
8
|
-
|
|
9
|
-
import { IdAddress } from '../../../src/address/model';
|
|
10
|
-
import { IdCard } from '../../../src/card/model';
|
|
11
|
-
import { IdCustomer } from '../../../src/customer/model';
|
|
12
|
-
import { IdPaymentIntent } from '../../../src/payment-intent/model';
|
|
13
|
-
import { IdPayout } from '../../../src/payout/model';
|
|
14
|
-
import { IdSepa } from '../../../src/sepa/model';
|
|
15
|
-
|
|
16
|
-
export const id = `paym_${randomString(24)}`; // required post
|
|
17
|
-
const amount = randomNumber(50, 4294967295);
|
|
18
|
-
const billingAddress = `addr_${randomString(24)}`;
|
|
19
|
-
const card = `card_${randomString(24)}`;
|
|
20
|
-
const capture = true;
|
|
21
|
-
const created = randomNumber(786460000, 1790692636);
|
|
22
|
-
const currency = CurrencyEnum[randomNumber(0, CurrencyEnum.length - 1)];
|
|
23
|
-
const customer = `cust_${randomString(24)}`;
|
|
24
|
-
const date_paym = randomNumber(786460000, 1000000000);
|
|
25
|
-
const date_settlement = `${randomNumber(1971, 2025)}-${randomMonth().toString().padStart(2, '0')}-${randomNumber(1, 28).toString().padStart(2, '0')}`;
|
|
26
|
-
const date_bank = `${randomNumber(1971, 2025)}-${randomMonth().toString().padStart(2, '0')}-${randomNumber(1, 28).toString().padStart(2, '0')}`;
|
|
27
|
-
const description = randomString(3, 64);
|
|
28
|
-
const fee = randomNumber(0, 4294967295);
|
|
29
|
-
const method = MethodEnum[randomNumber(0, MethodEnum.length - 1)];
|
|
30
|
-
const methodsAllowed = [MethodEnum[randomNumber(0, MethodEnum.length - 1)]];
|
|
31
|
-
const orderId = randomString(1, 36);
|
|
32
|
-
const origin = 'api';
|
|
33
|
-
const paymentIntent = `pi_${randomString(24)}`;
|
|
34
|
-
const payout = `pout_${randomString(24)}`;
|
|
35
|
-
const response = randomString(2);
|
|
36
|
-
const responseAuthor = randomString(2, 100);
|
|
37
|
-
const returnUrl = randomString(1, 66);
|
|
38
|
-
const sepa = `sepa_${randomString(24)}`;
|
|
39
|
-
const shippingAddress = `addr_${randomString(24)}`;
|
|
40
|
-
const status = StatusEnum[randomNumber(0, StatusEnum.length - 1)];
|
|
41
|
-
const uniqueId = randomString(1, 36);
|
|
42
|
-
export const wallet = {}; // walletObject
|
|
43
|
-
|
|
44
|
-
export const endpointResource = {
|
|
45
|
-
id,
|
|
46
|
-
amount,
|
|
47
|
-
auth: { returnUrl: 'returnUrl' },
|
|
48
|
-
device: { city: 'city' },
|
|
49
|
-
billing_address: billingAddress,
|
|
50
|
-
capture,
|
|
51
|
-
card,
|
|
52
|
-
created,
|
|
53
|
-
currency,
|
|
54
|
-
customer,
|
|
55
|
-
date_paym,
|
|
56
|
-
date_settlement,
|
|
57
|
-
date_bank,
|
|
58
|
-
description,
|
|
59
|
-
fee,
|
|
60
|
-
method,
|
|
61
|
-
methods_allowed: methodsAllowed,
|
|
62
|
-
order_id: orderId,
|
|
63
|
-
unique_id: uniqueId,
|
|
64
|
-
response,
|
|
65
|
-
response_author: responseAuthor,
|
|
66
|
-
return_url: returnUrl,
|
|
67
|
-
sepa,
|
|
68
|
-
shipping_address: shippingAddress,
|
|
69
|
-
status,
|
|
70
|
-
origin,
|
|
71
|
-
payout,
|
|
72
|
-
payment_intent: paymentIntent,
|
|
73
|
-
wallet,
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export const creationResource = {
|
|
77
|
-
amount: paymentAmount(amount),
|
|
78
|
-
auth: true,
|
|
79
|
-
capture,
|
|
80
|
-
createdAt: Temporal.Instant.fromEpochMilliseconds(created * 1000),
|
|
81
|
-
currency,
|
|
82
|
-
customer: customer as IdCustomer,
|
|
83
|
-
datePayment: Temporal.Instant.fromEpochMilliseconds(date_paym * 1000),
|
|
84
|
-
dateSettlement: Temporal.PlainDate.from(date_settlement),
|
|
85
|
-
dateBank: Temporal.PlainDate.from(date_bank),
|
|
86
|
-
description,
|
|
87
|
-
device: true as unknown as Device,
|
|
88
|
-
fee,
|
|
89
|
-
method,
|
|
90
|
-
methodsAllowed,
|
|
91
|
-
orderId,
|
|
92
|
-
uniqueId,
|
|
93
|
-
response,
|
|
94
|
-
responseAuthor,
|
|
95
|
-
returnUrl,
|
|
96
|
-
card: card as IdCard,
|
|
97
|
-
sepa: sepa as IdSepa,
|
|
98
|
-
status,
|
|
99
|
-
origin,
|
|
100
|
-
payout: payout as IdPayout,
|
|
101
|
-
billingAddress: billingAddress as IdAddress,
|
|
102
|
-
shippingAddress: shippingAddress as IdAddress,
|
|
103
|
-
paymentIntent: paymentIntent as IdPaymentIntent,
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
export const endpointResourceDeserialized = {
|
|
107
|
-
id,
|
|
108
|
-
...creationResource,
|
|
109
|
-
device: { city: 'city' },
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
export const listResource = [
|
|
113
|
-
{ ...creationResource, uniqueId: 'firstResource' },
|
|
114
|
-
{ ...creationResource, uniqueId: 'secondResource' },
|
|
115
|
-
{ ...creationResource, uniqueId: 'thirdResource' },
|
|
116
|
-
];
|
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
import { Temporal } from 'temporal-polyfill';
|
|
2
|
-
import { describe, expect, it } from 'vitest';
|
|
3
|
-
|
|
4
|
-
import { Currency, CurrencyEnum } from '#payment/enum/currency.ts';
|
|
5
|
-
import { Method, MethodEnum } from '#payment/enum/method.ts';
|
|
6
|
-
import { PaymentStatus, StatusEnum } from '#payment/enum/status.ts';
|
|
7
|
-
import { Device, IdPayment, PaymentModel } from '#payment/model.js';
|
|
8
|
-
import { SetterGetter, SetterGetterId, randomNumber, randomPastDate, randomString } from '#test/test-helper.js';
|
|
9
|
-
|
|
10
|
-
import { IdAddress } from '../../../src/address/model';
|
|
11
|
-
import { IdPaymentIntent } from '../../../src/payment-intent/model';
|
|
12
|
-
import { IdPayout } from '../../../src/payout/model';
|
|
13
|
-
|
|
14
|
-
describe('Setter & Getter', () => {
|
|
15
|
-
const payment = new PaymentModel({});
|
|
16
|
-
|
|
17
|
-
it('id', () => {
|
|
18
|
-
SetterGetterId((value: IdPayment) => new PaymentModel({}, value), 'paym_' + randomString(24));
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('amount', () => {
|
|
22
|
-
SetterGetter(
|
|
23
|
-
(value: number) => {
|
|
24
|
-
payment.setAmount(value);
|
|
25
|
-
},
|
|
26
|
-
() => payment.amount,
|
|
27
|
-
randomNumber,
|
|
28
|
-
);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('auth', () => {
|
|
32
|
-
SetterGetter(
|
|
33
|
-
(value: boolean) => payment.setAuth(value),
|
|
34
|
-
() => payment.auth,
|
|
35
|
-
true,
|
|
36
|
-
);
|
|
37
|
-
payment._data.auth = null;
|
|
38
|
-
expect(payment.auth).toBeNullable();
|
|
39
|
-
payment.setAuth(false);
|
|
40
|
-
expect(payment.auth).toBeNullable();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('billing address', () => {
|
|
44
|
-
SetterGetter(
|
|
45
|
-
(value: string) => payment.setBillingAddress(value),
|
|
46
|
-
() => payment.billingAddress,
|
|
47
|
-
'addr_' + randomString(24),
|
|
48
|
-
);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('card', () => {
|
|
52
|
-
SetterGetter(
|
|
53
|
-
(value: string) => payment.setCard(value),
|
|
54
|
-
() => payment.card,
|
|
55
|
-
'card_' + randomString(24),
|
|
56
|
-
);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it.each(CurrencyEnum.map((n) => [n]) as string[][])('currency %s', (currency: string) => {
|
|
60
|
-
payment._data.currency = null;
|
|
61
|
-
SetterGetter(
|
|
62
|
-
(value: Currency) => payment.setCurrency(value),
|
|
63
|
-
() => payment.currency,
|
|
64
|
-
currency,
|
|
65
|
-
);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('customer', () => {
|
|
69
|
-
SetterGetter(
|
|
70
|
-
(value: string) => payment.setCustomer(value),
|
|
71
|
-
() => payment.customer,
|
|
72
|
-
'cust_' + randomString(24),
|
|
73
|
-
);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('datePayment', () => {
|
|
77
|
-
SetterGetter(
|
|
78
|
-
(value: Temporal.PlainDate) => (payment._data.datePayment = value),
|
|
79
|
-
() => payment.datePayment,
|
|
80
|
-
randomPastDate(),
|
|
81
|
-
);
|
|
82
|
-
payment._data.datePayment = null;
|
|
83
|
-
SetterGetter(
|
|
84
|
-
(value: Temporal.PlainDate) => (payment._data.datePayment = value),
|
|
85
|
-
() => payment.datePaym,
|
|
86
|
-
randomPastDate(),
|
|
87
|
-
);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('dateSettlement', () => {
|
|
91
|
-
SetterGetter(
|
|
92
|
-
(value: Temporal.PlainDate) => payment.setDateSettlement(value),
|
|
93
|
-
() => payment.dateSettlement,
|
|
94
|
-
randomPastDate(),
|
|
95
|
-
);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('date_bank', () => {
|
|
99
|
-
SetterGetter(
|
|
100
|
-
(value: Temporal.PlainDate) => (payment._data.dateBank = value),
|
|
101
|
-
() => payment.dateBank,
|
|
102
|
-
randomPastDate(),
|
|
103
|
-
);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('description', () => {
|
|
107
|
-
SetterGetter(
|
|
108
|
-
(value: string) => payment.setDescription(value),
|
|
109
|
-
() => payment.description,
|
|
110
|
-
randomString(24),
|
|
111
|
-
);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('device', () => {
|
|
115
|
-
SetterGetter(
|
|
116
|
-
(value: Device) => payment.setDevice(value),
|
|
117
|
-
() => payment.device,
|
|
118
|
-
{},
|
|
119
|
-
);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('fee', () => {
|
|
123
|
-
SetterGetter(
|
|
124
|
-
(value: number) => (payment._data.fee = value),
|
|
125
|
-
() => payment.fee,
|
|
126
|
-
randomNumber(0, 5000),
|
|
127
|
-
);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it.each(MethodEnum.map((n) => [n]) as string[][])('method %s', (method) => {
|
|
131
|
-
payment._data.method = null;
|
|
132
|
-
|
|
133
|
-
SetterGetter(
|
|
134
|
-
(value: string) => (payment._data.method = value),
|
|
135
|
-
() => payment.method,
|
|
136
|
-
method,
|
|
137
|
-
);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it.each(MethodEnum.map((n) => [[n]]) as string[][][])('method %s', (method) => {
|
|
141
|
-
payment._data.methodsAllowed = null;
|
|
142
|
-
SetterGetter(
|
|
143
|
-
(value: Method[]) => payment.setMethodsAllowed(value),
|
|
144
|
-
() => payment.methodsAllowed,
|
|
145
|
-
method,
|
|
146
|
-
);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it('orderId', () => {
|
|
150
|
-
SetterGetter(
|
|
151
|
-
(value: string) => payment.setOrderId(value),
|
|
152
|
-
() => payment.orderId,
|
|
153
|
-
randomString(24),
|
|
154
|
-
);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('origin', () => {
|
|
158
|
-
SetterGetter(
|
|
159
|
-
(value: number) => (payment._data.origin = value),
|
|
160
|
-
() => payment.origin,
|
|
161
|
-
randomNumber(0, 8),
|
|
162
|
-
);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('uniqueId', () => {
|
|
166
|
-
SetterGetter(
|
|
167
|
-
(value: string) => payment.setUniqueId(value),
|
|
168
|
-
() => payment.uniqueId,
|
|
169
|
-
randomString(1, 32),
|
|
170
|
-
);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it('response', () => {
|
|
174
|
-
SetterGetter(
|
|
175
|
-
(value: string) => (payment._data.response = value),
|
|
176
|
-
() => payment.response,
|
|
177
|
-
randomString(1, 32),
|
|
178
|
-
);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it('responseAuthor', () => {
|
|
182
|
-
SetterGetter(
|
|
183
|
-
(value: string) => (payment._data.responseAuthor = value),
|
|
184
|
-
() => payment.responseAuthor,
|
|
185
|
-
randomString(1, 32),
|
|
186
|
-
);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it('returnUrl', () => {
|
|
190
|
-
payment._data.returnUrl = null;
|
|
191
|
-
SetterGetter(
|
|
192
|
-
(value: string) => payment.setReturnUrl(value),
|
|
193
|
-
() => payment.returnUrl,
|
|
194
|
-
randomString(1, 1000),
|
|
195
|
-
);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it('Sepa', () => {
|
|
199
|
-
payment._data.currency = 'eur';
|
|
200
|
-
payment._data.sepa = null;
|
|
201
|
-
SetterGetter(
|
|
202
|
-
(value: string) => payment.setSepa(value),
|
|
203
|
-
() => payment.sepa,
|
|
204
|
-
'sepa_' + randomString(24),
|
|
205
|
-
);
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it('Shippping address', () => {
|
|
209
|
-
SetterGetter(
|
|
210
|
-
(value: IdAddress) => payment.setShippingAddress(value),
|
|
211
|
-
() => payment.shippingAddress,
|
|
212
|
-
'addr_' + randomString(24),
|
|
213
|
-
);
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it.each(StatusEnum.map((n) => [n]))('status %s', (status) => {
|
|
217
|
-
payment._data.status = null;
|
|
218
|
-
SetterGetter(
|
|
219
|
-
(value: PaymentStatus) => payment.setStatus(value),
|
|
220
|
-
() => payment.status,
|
|
221
|
-
status,
|
|
222
|
-
);
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
it('payout', () => {
|
|
226
|
-
SetterGetter(
|
|
227
|
-
(value: IdPayout) => (payment._data.payout = value),
|
|
228
|
-
() => payment.payout,
|
|
229
|
-
'pout_' + randomString(24),
|
|
230
|
-
);
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it('payment intent', () => {
|
|
234
|
-
SetterGetter(
|
|
235
|
-
(value: IdPaymentIntent) => (payment._data.paymentIntent = value),
|
|
236
|
-
() => payment.paymentIntent,
|
|
237
|
-
'pi_' + randomString(24),
|
|
238
|
-
);
|
|
239
|
-
});
|
|
240
|
-
});
|