@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,86 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { Validator } from '#core/validator.js';
|
|
4
|
-
import { IdCustomer } from '#customer/model.ts';
|
|
5
|
-
import { SepaData, SepaModel } from '#sepa/model.js';
|
|
6
|
-
import { SetterGetter, randomPastDate, randomString } from '#test/test-helper.js';
|
|
7
|
-
|
|
8
|
-
import { bicDataProvider, ibanDataProvider } from './sepa-helper';
|
|
9
|
-
|
|
10
|
-
describe('sepa Class', () => {
|
|
11
|
-
const sepa = new SepaModel((() => true) as unknown as Validator<SepaData>);
|
|
12
|
-
|
|
13
|
-
describe('Setter & Getter', () => {
|
|
14
|
-
it.each((bicDataProvider(false) as string[]).map((n) => [n]))('bic', (bic) => {
|
|
15
|
-
sepa._data.bic = null;
|
|
16
|
-
SetterGetter(
|
|
17
|
-
(value: string) => sepa.setBic(value),
|
|
18
|
-
() => sepa.bic,
|
|
19
|
-
bic,
|
|
20
|
-
);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('deleted (unsettable)', () => {
|
|
24
|
-
SetterGetter(
|
|
25
|
-
(value: boolean) => (sepa._data.deleted = value),
|
|
26
|
-
() => sepa.deleted,
|
|
27
|
-
true,
|
|
28
|
-
);
|
|
29
|
-
sepa._data.deleted = null;
|
|
30
|
-
SetterGetter(
|
|
31
|
-
(value: boolean) => (sepa._data.deleted = value),
|
|
32
|
-
() => sepa.deleted,
|
|
33
|
-
false,
|
|
34
|
-
);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('customer', () => {
|
|
38
|
-
SetterGetter(
|
|
39
|
-
(value: IdCustomer) => sepa.setCustomer(value),
|
|
40
|
-
() => sepa.customer,
|
|
41
|
-
``,
|
|
42
|
-
);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('dateMandate', () => {
|
|
46
|
-
SetterGetter(
|
|
47
|
-
(value: string) => sepa.setDateMandate(value),
|
|
48
|
-
() => sepa.dateMandate,
|
|
49
|
-
randomPastDate(),
|
|
50
|
-
);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('last4', () => {
|
|
54
|
-
SetterGetter(
|
|
55
|
-
(value: string) => (sepa._data.last4 = value),
|
|
56
|
-
() => sepa.last4,
|
|
57
|
-
randomString(4),
|
|
58
|
-
);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('mandate', () => {
|
|
62
|
-
SetterGetter(
|
|
63
|
-
(value: string) => sepa.setMandate(value),
|
|
64
|
-
() => sepa.mandate,
|
|
65
|
-
randomString(0, 35),
|
|
66
|
-
);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('name', () => {
|
|
70
|
-
SetterGetter(
|
|
71
|
-
(value: string) => sepa.setName(value),
|
|
72
|
-
() => sepa.name,
|
|
73
|
-
randomString(0, 64),
|
|
74
|
-
);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it.each((ibanDataProvider() as string[]).map((value) => [value]))('iban %s', (value) => {
|
|
78
|
-
sepa._data.iban = null;
|
|
79
|
-
SetterGetter(
|
|
80
|
-
(value: string) => sepa.setIban(value),
|
|
81
|
-
() => sepa._data.iban,
|
|
82
|
-
value,
|
|
83
|
-
);
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
});
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { AbstractRepository } from '#core/abstract-repository.js';
|
|
4
|
-
import { StancerError } from '#error/base-error.js';
|
|
5
|
-
import { StancerRouteInaccessibleError } from '#error/endpoint/route-inaccessible-error.js';
|
|
6
|
-
import { SepaApiEndpoint } from '#sepa/api-endpoint.js';
|
|
7
|
-
import { IdSepa, SepaModel } from '#sepa/model.js';
|
|
8
|
-
import { SepaRepository } from '#sepa/repository.js';
|
|
9
|
-
import { sepaValidator } from '#sepa/validator.js';
|
|
10
|
-
import { randomString } from '#test/test-helper.js';
|
|
11
|
-
|
|
12
|
-
import { creationResource, endpointResource, listResource } from './fixture';
|
|
13
|
-
|
|
14
|
-
const idPrefix = 'sepa';
|
|
15
|
-
const id = `${idPrefix}_${randomString(24)}` as IdSepa;
|
|
16
|
-
const stancerErrorID = `${idPrefix}_unidentifiedError${randomString(7)}`;
|
|
17
|
-
const stancerRouteInaccessibleId = `${idPrefix}_StancerRouteInnacessible`;
|
|
18
|
-
const dataHasBeenSentId = `${idPrefix}_DataHasBeenSent${randomString(9)}`;
|
|
19
|
-
const dataUnmodified = `${idPrefix}_unmodifiedData${randomString(10)}`;
|
|
20
|
-
class MockApiEndpoint {
|
|
21
|
-
constructor() {}
|
|
22
|
-
|
|
23
|
-
list() {
|
|
24
|
-
async function* listGenerator() {
|
|
25
|
-
yield* listResource;
|
|
26
|
-
}
|
|
27
|
-
return listGenerator();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
delete() {
|
|
31
|
-
return endpointResource;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
send(id: string, data: Record<string, unknown>) {
|
|
35
|
-
if (id) {
|
|
36
|
-
if (id === stancerErrorID) {
|
|
37
|
-
throw new StancerError();
|
|
38
|
-
}
|
|
39
|
-
if (id === stancerRouteInaccessibleId) {
|
|
40
|
-
throw new StancerRouteInaccessibleError('PATCH', 'stub');
|
|
41
|
-
}
|
|
42
|
-
if (id === dataUnmodified) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return { ...data, id: dataHasBeenSentId };
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
get() {
|
|
50
|
-
return endpointResource;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
it('can be instanciated', () => {
|
|
55
|
-
const instance = new SepaRepository();
|
|
56
|
-
expect(instance).toBeInstanceOf(SepaRepository);
|
|
57
|
-
expect(instance).toBeInstanceOf(AbstractRepository);
|
|
58
|
-
//accessing private method & property
|
|
59
|
-
expect(instance.endpoint).toBeInstanceOf(SepaApiEndpoint);
|
|
60
|
-
expect(instance.validator).toBe(sepaValidator);
|
|
61
|
-
expect(instance.staticModel).toBe(SepaModel);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
describe('repository', () => {
|
|
65
|
-
const mockRepo = new MockApiEndpoint() as unknown as SepaApiEndpoint; // I lie, for convenience sake
|
|
66
|
-
const repository = new SepaRepository(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(SepaModel);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('delete', async () => {
|
|
82
|
-
const modelWithoutId = await repository.create();
|
|
83
|
-
await expect(() => repository.delete(modelWithoutId)).rejects.toThrow();
|
|
84
|
-
const model = await repository.create({ id: endpointResource.id, ...creationResource });
|
|
85
|
-
await expect((await repository.delete(model))._data).toStrictEqual(endpointResource);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
describe('send', () => {
|
|
89
|
-
it('should return model', async () => {
|
|
90
|
-
const model = await repository.create(creationResource);
|
|
91
|
-
const sentModel = await repository.send(model);
|
|
92
|
-
expect(sentModel).toStrictEqual(model);
|
|
93
|
-
expect(sentModel._data.id).toEqual(dataHasBeenSentId);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('should throw on inprecise error', async () => {
|
|
97
|
-
const model = await repository.create({ ...creationResource, id: stancerErrorID as IdSepa });
|
|
98
|
-
await expect(() => repository.send(model)).rejects.toThrow(StancerError);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('should return error on StancerRouteInacessibleError', async () => {
|
|
102
|
-
const model = await repository.create({ ...creationResource, id: stancerRouteInaccessibleId as IdSepa });
|
|
103
|
-
await expect(async () => await repository.send(model)).rejects.toThrow(StancerRouteInaccessibleError);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('should return unmodified model when no new Data', async () => {
|
|
107
|
-
const model = await repository.create({ ...creationResource, id: dataUnmodified as IdSepa });
|
|
108
|
-
const sentModel = await repository.send(model);
|
|
109
|
-
expect(model).toStrictEqual(sentModel);
|
|
110
|
-
expect(sentModel._data.id).toEqual(dataUnmodified);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
describe('populate', () => {
|
|
115
|
-
it('should not modify model if no Id', async () => {
|
|
116
|
-
const getEndpoint = vi.spyOn(mockRepo, 'get');
|
|
117
|
-
const model = await repository.create(creationResource);
|
|
118
|
-
expect(model).toBeInstanceOf(SepaModel);
|
|
119
|
-
expect(getEndpoint).toHaveBeenCalledTimes(0);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('should get model if only id', async () => {
|
|
123
|
-
const getEndpoint = vi.spyOn(mockRepo, 'get');
|
|
124
|
-
const model = await repository.create(id);
|
|
125
|
-
expect(model).toBeInstanceOf(SepaModel);
|
|
126
|
-
expect(getEndpoint).toHaveBeenCalledTimes(1);
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
describe('list', async () => {
|
|
131
|
-
it('return correct model one by one', async () => {
|
|
132
|
-
const listStub = repository.list();
|
|
133
|
-
const item1 = await listStub.next();
|
|
134
|
-
expect(item1.done).toBeFalsy();
|
|
135
|
-
expect(item1.value).toHaveProperty('id');
|
|
136
|
-
expect(item1.value).toBeInstanceOf(SepaModel);
|
|
137
|
-
expect(item1.value.name).toBe('item1');
|
|
138
|
-
|
|
139
|
-
const item2 = await listStub.next();
|
|
140
|
-
expect(item2.done).toBeFalsy();
|
|
141
|
-
expect(item2.value).toHaveProperty('id');
|
|
142
|
-
expect(item2.value).toBeInstanceOf(SepaModel);
|
|
143
|
-
expect(item2.value.name).toBe('item2');
|
|
144
|
-
|
|
145
|
-
const item3 = await listStub.next();
|
|
146
|
-
expect(item3.done).toBeTruthy();
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
});
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { randomNumber } from '#test/test-helper.js';
|
|
2
|
-
|
|
3
|
-
export const bicDataProvider = (one: boolean = false) => {
|
|
4
|
-
// Thanks Wikipedia
|
|
5
|
-
const data = [
|
|
6
|
-
'DEUTDEFF',
|
|
7
|
-
'DEUTDEFFXXX',
|
|
8
|
-
'DEUTGBFFA23',
|
|
9
|
-
'DEUTDEFF500',
|
|
10
|
-
'UKCBUau102v',
|
|
11
|
-
'UKIOLT2XXXX',
|
|
12
|
-
'GBMCMRMRXXX',
|
|
13
|
-
'gbtxus31xxx',
|
|
14
|
-
'JUBIGB21XXX',
|
|
15
|
-
];
|
|
16
|
-
if (!one) {
|
|
17
|
-
return data;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return data[randomNumber(0, data.length - 1)];
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export const ibanDataProvider = (one: boolean = false) => {
|
|
24
|
-
// Thanks Wikipedia
|
|
25
|
-
const data = [
|
|
26
|
-
'BE71 0961 2345 6769',
|
|
27
|
-
'FR76 3000 6000 0112 3456 7890 189',
|
|
28
|
-
'DE91 1000 0000 0123 4567 89',
|
|
29
|
-
'GR9608100010000001234567890',
|
|
30
|
-
'RO09 BCYP 0000 0012 3456 7890',
|
|
31
|
-
'SA4420000001234567891234',
|
|
32
|
-
'ES79 2100 0813 6101 2345 6789',
|
|
33
|
-
'CH56 0483 5012 3456 7800 9 ',
|
|
34
|
-
'GB98 MIDL 0700 9312 3456 78',
|
|
35
|
-
'GB82WEST12345698765432',
|
|
36
|
-
];
|
|
37
|
-
|
|
38
|
-
if (!one) {
|
|
39
|
-
return data;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return data[randomNumber(0, data.length - 1)];
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export const validIbanDataProvider = (one: boolean = false) => {
|
|
46
|
-
const data = [
|
|
47
|
-
'AT611904300234573201',
|
|
48
|
-
'BE62510007547061',
|
|
49
|
-
'CH2089144321842946678',
|
|
50
|
-
'DE89370400440532013000',
|
|
51
|
-
'EE382200221020145685',
|
|
52
|
-
'ES0700120345030000067890',
|
|
53
|
-
'FI2112345600000785',
|
|
54
|
-
'FR1420041010050500013M02606',
|
|
55
|
-
'GB33BUKB20201555555555',
|
|
56
|
-
'IE29AIBK93115212345678',
|
|
57
|
-
'LT121000011101001000',
|
|
58
|
-
'LU280019400644750000',
|
|
59
|
-
'IT02A0301926102000000490887',
|
|
60
|
-
'NL39RABO0300065264',
|
|
61
|
-
'NO9386011117947',
|
|
62
|
-
'PT50000201231234567890154',
|
|
63
|
-
'SE3550000000054910000003',
|
|
64
|
-
];
|
|
65
|
-
|
|
66
|
-
if (!one) {
|
|
67
|
-
return data;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return data[randomNumber(0, data.length - 1)];
|
|
71
|
-
};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { Temporal } from 'temporal-polyfill';
|
|
2
|
-
import { describe, expect, it } from 'vitest';
|
|
3
|
-
|
|
4
|
-
import { idCustomer } from '#customer/model.ts';
|
|
5
|
-
import { SepaModel } from '#sepa/model.js';
|
|
6
|
-
import { sepaValidator } from '#sepa/validator.js';
|
|
7
|
-
import { checkType, goldilocks, randomMonth, randomNumber, randomString } from '#test/test-helper.js';
|
|
8
|
-
|
|
9
|
-
import { ibanDataProvider } from './sepa-helper';
|
|
10
|
-
|
|
11
|
-
describe('Goldilocks', () => {
|
|
12
|
-
const sepa = new SepaModel(sepaValidator);
|
|
13
|
-
|
|
14
|
-
it('bic', () => {
|
|
15
|
-
goldilocks((value: string) => sepa.setBic(value), 'string', { min: 8, max: 11 });
|
|
16
|
-
checkType((value: string) => (sepa._data.bic = value), ['string'], randomString(8, 11));
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('customer', () => {
|
|
20
|
-
const falseCustomer = randomString(24);
|
|
21
|
-
const trueCustomer = idCustomer(`cust_${randomString(24)}`);
|
|
22
|
-
expect(() => sepa.setCustomer(falseCustomer)).toThrow();
|
|
23
|
-
sepa.setCustomer(trueCustomer);
|
|
24
|
-
expect(sepa.customer).toBe(trueCustomer);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('dateMandate', () => {
|
|
28
|
-
const falseDateMandate = new Temporal.PlainDate(9999, randomMonth(), randomNumber(1, 28));
|
|
29
|
-
const notInstantDateMandate = new Temporal.PlainDate(1969, randomMonth(), randomNumber(1, 28));
|
|
30
|
-
const dateMandate = new Temporal.PlainDate(
|
|
31
|
-
randomNumber(1971, Temporal.Now.plainDateISO().year),
|
|
32
|
-
randomMonth(),
|
|
33
|
-
randomNumber(1, 28),
|
|
34
|
-
);
|
|
35
|
-
expect(() => sepa.setDateMandate(falseDateMandate)).toThrow();
|
|
36
|
-
expect(() => sepa.setDateMandate(notInstantDateMandate)).toThrow();
|
|
37
|
-
sepa.setDateMandate(dateMandate);
|
|
38
|
-
expect(sepa.dateMandate).toBe(dateMandate);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('iban', () => {
|
|
42
|
-
const falseSepaNumber = randomString(14, 34);
|
|
43
|
-
expect(() => sepa.setIban(falseSepaNumber)).toThrow();
|
|
44
|
-
const trueSepaNumber = ibanDataProvider(true);
|
|
45
|
-
sepa.setIban(trueSepaNumber);
|
|
46
|
-
expect(sepa._data.iban).toBe(trueSepaNumber);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('mandate', () => {
|
|
50
|
-
goldilocks((value: string) => sepa.setMandate(value), 'string', { min: 1, max: 35 });
|
|
51
|
-
checkType((value: string) => sepa.setMandate(value), ['string'], randomString(1, 35));
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('name', () => {
|
|
55
|
-
goldilocks((value: string) => sepa.setName(value), 'string', { min: 3, max: 64 });
|
|
56
|
-
checkType((value: string) => sepa.setName(value), ['string'], randomString(3, 64));
|
|
57
|
-
});
|
|
58
|
-
});
|
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { IdValue } from '#core/common/branded-type.js';
|
|
4
|
-
import { trackObjectMutations } from '#core/common/mutation-tracked-object.js';
|
|
5
|
-
import { StancerRouteInaccessibleError } from '#error/endpoint/route-inaccessible-error.js';
|
|
6
|
-
import { stubDeserialized, stubSerialized } from '#test/fixtures/endpoint.stub.js';
|
|
7
|
-
import { StubEndpoint } from '#test/stub/stub-endpoint.js';
|
|
8
|
-
import { randomString } from '#test/test-helper.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
|
-
...stubSerialized,
|
|
27
|
-
};
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
}),
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe('endpoint object', () => {
|
|
36
|
-
describe('handle resources', () => {
|
|
37
|
-
const endpoint = new StubEndpoint();
|
|
38
|
-
|
|
39
|
-
describe('deserialize resource', async () => {
|
|
40
|
-
const deserializedResources = await endpoint.deserializeResource(stubSerialized);
|
|
41
|
-
|
|
42
|
-
it('id', () => {
|
|
43
|
-
expect(deserializedResources.id).toEqual(stubDeserialized.id);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('default', () => {
|
|
47
|
-
expect(deserializedResources.default).toEqual(stubDeserialized.default);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('defaultNumber', () => {
|
|
51
|
-
expect(deserializedResources.defaultNumber).toEqual(stubDeserialized.defaultNumber);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('untouchable', () => {
|
|
55
|
-
expect(Object.hasOwn(deserializedResources, 'untouchable')).toBeFalsy();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('allAuthorized', () => {
|
|
59
|
-
expect(Object.hasOwn(deserializedResources, 'allAuthorized')).toBeTruthy();
|
|
60
|
-
expect(deserializedResources.allAuthorized).toBeTruthy();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('ungettable', () => {
|
|
64
|
-
expect(Object.hasOwn(deserializedResources, 'ungettable')).toBeFalsy();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('unmodifiable', () => {
|
|
68
|
-
expect(Object.hasOwn(deserializedResources, 'unmodifiable')).toBeTruthy();
|
|
69
|
-
expect(deserializedResources.unmodifiable).toBeFalsy();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
const getResourceviaConfig = await endpoint.config.deserializeResource(stubSerialized);
|
|
73
|
-
expect(getResourceviaConfig).toStrictEqual(stubDeserialized);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
describe('serialize for post', () => {
|
|
77
|
-
const endpoint = new StubEndpoint();
|
|
78
|
-
const postContent = { ...stubDeserialized, ungettable: true };
|
|
79
|
-
const postedResource = endpoint.postObjectSerializer(postContent);
|
|
80
|
-
|
|
81
|
-
it('id', () => {
|
|
82
|
-
expect(postedResource.id).toBeUndefined();
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('default', () => {
|
|
86
|
-
expect(postedResource.default).toEqual(stubSerialized.default);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('defaultNumber', () => {
|
|
90
|
-
expect(postedResource.default_number).toEqual(stubDeserialized.defaultNumber);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('untouchable', () => {
|
|
94
|
-
expect(Object.hasOwn(postedResource, 'untouchable')).toBeFalsy();
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('allAuthorized', () => {
|
|
98
|
-
expect(Object.hasOwn(postedResource, 'all_authorized')).toBeTruthy();
|
|
99
|
-
expect(postedResource.all_authorized).toBeTruthy();
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('ungettable', () => {
|
|
103
|
-
expect(Object.hasOwn(postedResource, 'ungettable')).toBeTruthy();
|
|
104
|
-
expect(postedResource.ungettable).toBeTruthy();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('unmodifiable', () => {
|
|
108
|
-
expect(Object.hasOwn(postedResource, 'unmodifiable')).toBeFalsy();
|
|
109
|
-
});
|
|
110
|
-
const postedResourceviaConfig = endpoint.config.postObjectSerializer(postContent);
|
|
111
|
-
expect(postedResourceviaConfig).toStrictEqual(postedResource);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
describe('serialize for patch', () => {
|
|
115
|
-
const postedResource = endpoint.patchObjectSerializer({ ...stubDeserialized, ungettable: true });
|
|
116
|
-
|
|
117
|
-
it('does not patch id', () => {
|
|
118
|
-
expect(postedResource.id).toBeUndefined();
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('default', () => {
|
|
122
|
-
expect(postedResource.default).toEqual(stubSerialized.default);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('defaultNumber', () => {
|
|
126
|
-
expect(postedResource.defaultNumber).toEqual(stubSerialized.defaultNumber);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('untouchable', () => {
|
|
130
|
-
expect(Object.hasOwn(postedResource, 'untouchable')).toBeFalsy();
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it('allAuthorized', () => {
|
|
134
|
-
expect(Object.hasOwn(postedResource, 'all_authorized')).toBeTruthy();
|
|
135
|
-
expect(postedResource.all_authorized).toBeTruthy();
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('ungettable', () => {
|
|
139
|
-
expect(Object.hasOwn(postedResource, 'ungettable')).toBeTruthy();
|
|
140
|
-
expect(postedResource.ungettable).toBeTruthy();
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('unmodifiable', () => {
|
|
144
|
-
expect(Object.hasOwn(postedResource, 'unmodifiable')).toBeFalsy();
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
const postedResourceviaConfig = endpoint.config.patchObjectSerializer({ ...stubDeserialized, ungettable: true }); // we don't really care for the type
|
|
148
|
-
expect(postedResourceviaConfig).toStrictEqual(postedResource);
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it('have an endpoint url', () => {
|
|
153
|
-
const endpoint = new StubEndpoint();
|
|
154
|
-
const id = IdValue('stub_' + randomString(24, 24));
|
|
155
|
-
expect(endpoint.endpointUrl(id)).toStrictEqual(`https://api.stancer.com/v2/stubs/${id}`);
|
|
156
|
-
expect(endpoint.endpointUrl()).toStrictEqual('https://api.stancer.com/v2/stubs/');
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
describe('Action verbs', async () => {
|
|
160
|
-
it('get', async () => {
|
|
161
|
-
const endpoint = new StubEndpoint();
|
|
162
|
-
const responseWithId = await endpoint.get(IdValue('stub_' + randomString(24)));
|
|
163
|
-
expect(responseWithId).toStrictEqual({
|
|
164
|
-
allAuthorized: true,
|
|
165
|
-
default: stubDeserialized.default,
|
|
166
|
-
defaultNumber: stubDeserialized.defaultNumber,
|
|
167
|
-
id: stubDeserialized.id,
|
|
168
|
-
unmodifiable: stubDeserialized.unmodifiable,
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it('post', async () => {
|
|
173
|
-
const postableEndpoint = new StubEndpoint();
|
|
174
|
-
const response = await postableEndpoint.post(stubSerialized);
|
|
175
|
-
expect(response).toStrictEqual(stubDeserialized);
|
|
176
|
-
const unpostableEndpoint = new StubEndpoint({ postable: false });
|
|
177
|
-
expect(() => unpostableEndpoint.post(stubSerialized)).toThrow('POST is not allowed for stubs resource');
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it('patch', async () => {
|
|
181
|
-
const patchableEndpoint = new StubEndpoint();
|
|
182
|
-
const response = await patchableEndpoint.patch(stubSerialized.id, stubSerialized);
|
|
183
|
-
expect(response).toStrictEqual(stubDeserialized);
|
|
184
|
-
const unpatchableEndpoint = new StubEndpoint({ patchable: false });
|
|
185
|
-
expect(() => unpatchableEndpoint.patch(stubSerialized.id, stubSerialized)).toThrow(
|
|
186
|
-
'PATCH is not allowed for stubs resource',
|
|
187
|
-
);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it('delete', async () => {
|
|
191
|
-
const endpoint = new StubEndpoint();
|
|
192
|
-
const responseWithId = await endpoint.delete(stubSerialized.id);
|
|
193
|
-
expect(responseWithId).toStrictEqual({
|
|
194
|
-
allAuthorized: true,
|
|
195
|
-
default: stubSerialized.default,
|
|
196
|
-
defaultNumber: stubDeserialized.defaultNumber,
|
|
197
|
-
id: stubSerialized.id,
|
|
198
|
-
unmodifiable: stubSerialized.unmodifiable,
|
|
199
|
-
});
|
|
200
|
-
const undeletableEndpoint = new StubEndpoint({ deletable: false });
|
|
201
|
-
expect(() => undeletableEndpoint.delete(stubSerialized.id)).toThrow('DELETE is not allowed for stubs resource');
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
describe('send', () => {
|
|
205
|
-
it("cannot send if it has no id and it isn't postable", async () => {
|
|
206
|
-
const endpoint = new StubEndpoint({ postable: false });
|
|
207
|
-
const mutationsData = trackObjectMutations({}, () => true);
|
|
208
|
-
mutationsData['default'] = 'stub_' + randomString(24);
|
|
209
|
-
expect(() => endpoint.send(undefined, mutationsData)).toThrow(StancerRouteInaccessibleError);
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it('can patch if id', () => {
|
|
213
|
-
const endpoint = new StubEndpoint();
|
|
214
|
-
const spyonPatch = vi.spyOn(endpoint, 'patch');
|
|
215
|
-
const spyonPost = vi.spyOn(endpoint, 'post');
|
|
216
|
-
const mutationsData = trackObjectMutations({}, () => true);
|
|
217
|
-
mutationsData['id'] = 'stub_' + randomString(24);
|
|
218
|
-
mutationsData['defaultNumber'] = 12;
|
|
219
|
-
endpoint.send(mutationsData['id'], mutationsData.getMutations());
|
|
220
|
-
expect(spyonPatch).toHaveBeenCalledOnce();
|
|
221
|
-
expect(spyonPost).toHaveBeenCalledTimes(0);
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it('can post if no id', () => {
|
|
225
|
-
const endpoint = new StubEndpoint();
|
|
226
|
-
const spyonPatch = vi.spyOn(endpoint, 'patch');
|
|
227
|
-
const spyonPost = vi.spyOn(endpoint, 'post');
|
|
228
|
-
const mutationsData = trackObjectMutations({}, () => true);
|
|
229
|
-
mutationsData['default'] = randomString(24);
|
|
230
|
-
endpoint.send(undefined, mutationsData);
|
|
231
|
-
expect(spyonPatch).toHaveBeenCalledTimes(0);
|
|
232
|
-
expect(spyonPost).toHaveBeenCalledTimes(1);
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
});
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { Configuration } from '#api/configuration.js';
|
|
4
|
-
import ListEndpointFixtures from '#test/fixtures/list-endpoint.stub.js';
|
|
5
|
-
import { StubEndpoint } from '#test/stub/stub-endpoint.js';
|
|
6
|
-
import { randomNumber, randomString } from '#test/test-helper.js';
|
|
7
|
-
|
|
8
|
-
vi.mock('../../../src/http/http.js', async (importHTTP) => {
|
|
9
|
-
const original: Record<string, Promise<unknown>> = await importHTTP();
|
|
10
|
-
return {
|
|
11
|
-
...original,
|
|
12
|
-
transformResponseToData: vi.fn((value) => value.json()),
|
|
13
|
-
};
|
|
14
|
-
});
|
|
15
|
-
vi.mock('#api/http/fetch-http-client.js', () => {
|
|
16
|
-
return {
|
|
17
|
-
httpClient: {
|
|
18
|
-
makeRequest: vi.fn(() => {
|
|
19
|
-
return Promise.resolve({
|
|
20
|
-
status: 200,
|
|
21
|
-
json: () => {
|
|
22
|
-
return {
|
|
23
|
-
...ListEndpointFixtures,
|
|
24
|
-
};
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
}),
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe('stub list', () => {
|
|
33
|
-
it('does not start if unlistable', async () => {
|
|
34
|
-
const unListableEndpoint = new StubEndpoint({ listable: false });
|
|
35
|
-
expect(unListableEndpoint.listable).toBeFalsy();
|
|
36
|
-
expect(() => unListableEndpoint.list({})).toThrow('LIST is not allowed for stubs resource');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('list correctly fixtured objects', async () => {
|
|
40
|
-
const endpoint = new StubEndpoint();
|
|
41
|
-
const generator = endpoint.list({ limit: 2 });
|
|
42
|
-
const item1 = await generator.next();
|
|
43
|
-
expect(item1.done).toBe(false);
|
|
44
|
-
expect(item1.value).toHaveProperty('id');
|
|
45
|
-
const item2 = await generator.next();
|
|
46
|
-
expect(item2.done).toBe(false);
|
|
47
|
-
expect(item1.value).toHaveProperty('id');
|
|
48
|
-
const item3 = await generator.next();
|
|
49
|
-
expect(item3.done).toBe(true);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('iterate correctly', async () => {
|
|
53
|
-
const endpoint = new StubEndpoint();
|
|
54
|
-
const generator = endpoint.list({});
|
|
55
|
-
for (const item in generator) {
|
|
56
|
-
expect(item).toHaveProperty('id');
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
describe('create URL', () => {
|
|
62
|
-
it('return simple stubUrl', () => {
|
|
63
|
-
const endpoint = new StubEndpoint();
|
|
64
|
-
const url = endpoint.createListUrl(endpoint._endpointBaseUrl, { start: 0, limit: 100, filters: {} });
|
|
65
|
-
expect(url).toBeTypeOf('object');
|
|
66
|
-
expect(url).toBeInstanceOf(URL);
|
|
67
|
-
expect(url.toString()).toBe('https://api.stancer.com/v2/stubs/?start=0&limit=100');
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('return complex url', () => {
|
|
71
|
-
const endpoint = new StubEndpoint();
|
|
72
|
-
const endpointUrl = randomString(10, 20);
|
|
73
|
-
const limit = randomNumber(1, 100);
|
|
74
|
-
const start = randomNumber(1, 20);
|
|
75
|
-
const filters = {
|
|
76
|
-
filter1: randomString(10, 20),
|
|
77
|
-
filter2: randomString(10, 20),
|
|
78
|
-
};
|
|
79
|
-
const url = endpoint.createListUrl(`${Configuration.baseUrl}/${endpointUrl}`, { limit, start, filters });
|
|
80
|
-
expect(url).toBeTypeOf('object');
|
|
81
|
-
expect(url).toBeInstanceOf(URL);
|
|
82
|
-
expect(url.toString()).toBe(
|
|
83
|
-
`https://api.stancer.com/v2/${endpointUrl}/?start=${start}&limit=${limit}&filter1=${filters.filter1}&filter2=${filters.filter2}`,
|
|
84
|
-
);
|
|
85
|
-
});
|
|
86
|
-
});
|