@stancer/stancer 1.0.2 → 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 +8 -0
- 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/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/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/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/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
|
Binary file
|
package/reports/sorter.js
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
var addSorting = (function () {
|
|
3
|
-
'use strict';
|
|
4
|
-
var cols,
|
|
5
|
-
currentSort = {
|
|
6
|
-
index: 0,
|
|
7
|
-
desc: false,
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
// returns the summary table element
|
|
11
|
-
function getTable() {
|
|
12
|
-
return document.querySelector('.coverage-summary');
|
|
13
|
-
}
|
|
14
|
-
// returns the thead element of the summary table
|
|
15
|
-
function getTableHeader() {
|
|
16
|
-
return getTable().querySelector('thead tr');
|
|
17
|
-
}
|
|
18
|
-
// returns the tbody element of the summary table
|
|
19
|
-
function getTableBody() {
|
|
20
|
-
return getTable().querySelector('tbody');
|
|
21
|
-
}
|
|
22
|
-
// returns the th element for nth column
|
|
23
|
-
function getNthColumn(n) {
|
|
24
|
-
return getTableHeader().querySelectorAll('th')[n];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function onFilterInput() {
|
|
28
|
-
const searchValue = document.getElementById('fileSearch').value;
|
|
29
|
-
const rows = document.getElementsByTagName('tbody')[0].children;
|
|
30
|
-
|
|
31
|
-
// Try to create a RegExp from the searchValue. If it fails (invalid regex),
|
|
32
|
-
// it will be treated as a plain text search
|
|
33
|
-
let searchRegex;
|
|
34
|
-
try {
|
|
35
|
-
searchRegex = new RegExp(searchValue, 'i'); // 'i' for case-insensitive
|
|
36
|
-
} catch (error) {
|
|
37
|
-
searchRegex = null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
for (let i = 0; i < rows.length; i++) {
|
|
41
|
-
const row = rows[i];
|
|
42
|
-
let isMatch = false;
|
|
43
|
-
|
|
44
|
-
if (searchRegex) {
|
|
45
|
-
// If a valid regex was created, use it for matching
|
|
46
|
-
isMatch = searchRegex.test(row.textContent);
|
|
47
|
-
} else {
|
|
48
|
-
// Otherwise, fall back to the original plain text search
|
|
49
|
-
isMatch = row.textContent.toLowerCase().includes(searchValue.toLowerCase());
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
row.style.display = isMatch ? '' : 'none';
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// loads the search box
|
|
57
|
-
function addSearchBox() {
|
|
58
|
-
var template = document.getElementById('filterTemplate');
|
|
59
|
-
var templateClone = template.content.cloneNode(true);
|
|
60
|
-
templateClone.getElementById('fileSearch').oninput = onFilterInput;
|
|
61
|
-
template.parentElement.appendChild(templateClone);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// loads all columns
|
|
65
|
-
function loadColumns() {
|
|
66
|
-
var colNodes = getTableHeader().querySelectorAll('th'),
|
|
67
|
-
colNode,
|
|
68
|
-
cols = [],
|
|
69
|
-
col,
|
|
70
|
-
i;
|
|
71
|
-
|
|
72
|
-
for (i = 0; i < colNodes.length; i += 1) {
|
|
73
|
-
colNode = colNodes[i];
|
|
74
|
-
col = {
|
|
75
|
-
key: colNode.getAttribute('data-col'),
|
|
76
|
-
sortable: !colNode.getAttribute('data-nosort'),
|
|
77
|
-
type: colNode.getAttribute('data-type') || 'string',
|
|
78
|
-
};
|
|
79
|
-
cols.push(col);
|
|
80
|
-
if (col.sortable) {
|
|
81
|
-
col.defaultDescSort = col.type === 'number';
|
|
82
|
-
colNode.innerHTML = colNode.innerHTML + '<span class="sorter"></span>';
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return cols;
|
|
86
|
-
}
|
|
87
|
-
// attaches a data attribute to every tr element with an object
|
|
88
|
-
// of data values keyed by column name
|
|
89
|
-
function loadRowData(tableRow) {
|
|
90
|
-
var tableCols = tableRow.querySelectorAll('td'),
|
|
91
|
-
colNode,
|
|
92
|
-
col,
|
|
93
|
-
data = {},
|
|
94
|
-
i,
|
|
95
|
-
val;
|
|
96
|
-
for (i = 0; i < tableCols.length; i += 1) {
|
|
97
|
-
colNode = tableCols[i];
|
|
98
|
-
col = cols[i];
|
|
99
|
-
val = colNode.getAttribute('data-value');
|
|
100
|
-
if (col.type === 'number') {
|
|
101
|
-
val = Number(val);
|
|
102
|
-
}
|
|
103
|
-
data[col.key] = val;
|
|
104
|
-
}
|
|
105
|
-
return data;
|
|
106
|
-
}
|
|
107
|
-
// loads all row data
|
|
108
|
-
function loadData() {
|
|
109
|
-
var rows = getTableBody().querySelectorAll('tr'),
|
|
110
|
-
i;
|
|
111
|
-
|
|
112
|
-
for (i = 0; i < rows.length; i += 1) {
|
|
113
|
-
rows[i].data = loadRowData(rows[i]);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
// sorts the table using the data for the ith column
|
|
117
|
-
function sortByIndex(index, desc) {
|
|
118
|
-
var key = cols[index].key,
|
|
119
|
-
sorter = function (a, b) {
|
|
120
|
-
a = a.data[key];
|
|
121
|
-
b = b.data[key];
|
|
122
|
-
return a < b ? -1 : a > b ? 1 : 0;
|
|
123
|
-
},
|
|
124
|
-
finalSorter = sorter,
|
|
125
|
-
tableBody = document.querySelector('.coverage-summary tbody'),
|
|
126
|
-
rowNodes = tableBody.querySelectorAll('tr'),
|
|
127
|
-
rows = [],
|
|
128
|
-
i;
|
|
129
|
-
|
|
130
|
-
if (desc) {
|
|
131
|
-
finalSorter = function (a, b) {
|
|
132
|
-
return -1 * sorter(a, b);
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
for (i = 0; i < rowNodes.length; i += 1) {
|
|
137
|
-
rows.push(rowNodes[i]);
|
|
138
|
-
tableBody.removeChild(rowNodes[i]);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
rows.sort(finalSorter);
|
|
142
|
-
|
|
143
|
-
for (i = 0; i < rows.length; i += 1) {
|
|
144
|
-
tableBody.appendChild(rows[i]);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
// removes sort indicators for current column being sorted
|
|
148
|
-
function removeSortIndicators() {
|
|
149
|
-
var col = getNthColumn(currentSort.index),
|
|
150
|
-
cls = col.className;
|
|
151
|
-
|
|
152
|
-
cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
|
|
153
|
-
col.className = cls;
|
|
154
|
-
}
|
|
155
|
-
// adds sort indicators for current column being sorted
|
|
156
|
-
function addSortIndicators() {
|
|
157
|
-
getNthColumn(currentSort.index).className += currentSort.desc ? ' sorted-desc' : ' sorted';
|
|
158
|
-
}
|
|
159
|
-
// adds event listeners for all sorter widgets
|
|
160
|
-
function enableUI() {
|
|
161
|
-
var i,
|
|
162
|
-
el,
|
|
163
|
-
ithSorter = function ithSorter(i) {
|
|
164
|
-
var col = cols[i];
|
|
165
|
-
|
|
166
|
-
return function () {
|
|
167
|
-
var desc = col.defaultDescSort;
|
|
168
|
-
|
|
169
|
-
if (currentSort.index === i) {
|
|
170
|
-
desc = !currentSort.desc;
|
|
171
|
-
}
|
|
172
|
-
sortByIndex(i, desc);
|
|
173
|
-
removeSortIndicators();
|
|
174
|
-
currentSort.index = i;
|
|
175
|
-
currentSort.desc = desc;
|
|
176
|
-
addSortIndicators();
|
|
177
|
-
};
|
|
178
|
-
};
|
|
179
|
-
for (i = 0; i < cols.length; i += 1) {
|
|
180
|
-
if (cols[i].sortable) {
|
|
181
|
-
// add the click event handler on the th so users
|
|
182
|
-
// dont have to click on those tiny arrows
|
|
183
|
-
el = getNthColumn(i).querySelector('.sorter').parentElement;
|
|
184
|
-
if (el.addEventListener) {
|
|
185
|
-
el.addEventListener('click', ithSorter(i));
|
|
186
|
-
} else {
|
|
187
|
-
el.attachEvent('onclick', ithSorter(i));
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
// adds sorting functionality to the UI
|
|
193
|
-
return function () {
|
|
194
|
-
if (!getTable()) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
cols = loadColumns();
|
|
198
|
-
loadData();
|
|
199
|
-
addSearchBox();
|
|
200
|
-
addSortIndicators();
|
|
201
|
-
enableUI();
|
|
202
|
-
};
|
|
203
|
-
})();
|
|
204
|
-
|
|
205
|
-
window.addEventListener('load', addSorting);
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { IdValue } from '#core/common/branded-type.js';
|
|
2
|
-
import { randomNumber, randomString } from '#test/test-helper.js';
|
|
3
|
-
|
|
4
|
-
const id = 'stub_' + randomString(24, 24);
|
|
5
|
-
const defaultValue = randomString(1, 50);
|
|
6
|
-
const defaultNumber = randomNumber(12, 200);
|
|
7
|
-
export const stubSerialized = {
|
|
8
|
-
id,
|
|
9
|
-
default: defaultValue,
|
|
10
|
-
default_number: defaultNumber,
|
|
11
|
-
untouchable: false,
|
|
12
|
-
all_authorized: true,
|
|
13
|
-
ungettable: false,
|
|
14
|
-
unmodifiable: false,
|
|
15
|
-
};
|
|
16
|
-
export const stubDeserialized = {
|
|
17
|
-
id: id as IdValue,
|
|
18
|
-
default: defaultValue,
|
|
19
|
-
defaultNumber: defaultNumber,
|
|
20
|
-
allAuthorized: true,
|
|
21
|
-
unmodifiable: false,
|
|
22
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { randomNumber, randomString } from '#test/test-helper.js';
|
|
2
|
-
|
|
3
|
-
const stub = {
|
|
4
|
-
stubs: [
|
|
5
|
-
{
|
|
6
|
-
id: 'stub_' + randomString(24, 24),
|
|
7
|
-
default: randomString(1, 50),
|
|
8
|
-
defaultNumber: randomNumber(12, 263),
|
|
9
|
-
untouchable: true,
|
|
10
|
-
all_authorized: true,
|
|
11
|
-
ungettable: true,
|
|
12
|
-
unmodifiable: true,
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
id: 'stub_' + randomString(24, 24),
|
|
16
|
-
default: randomString(1, 50),
|
|
17
|
-
defaultNumber: randomNumber(12, 263),
|
|
18
|
-
untouchable: true,
|
|
19
|
-
all_authorized: true,
|
|
20
|
-
ungettable: true,
|
|
21
|
-
unmodifiable: true,
|
|
22
|
-
},
|
|
23
|
-
],
|
|
24
|
-
range: {
|
|
25
|
-
count: 2080,
|
|
26
|
-
end: 9,
|
|
27
|
-
has_more: false,
|
|
28
|
-
limit: 2,
|
|
29
|
-
start: 0,
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export default stub;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { IdStub, StubData } from '#test/stub/stub-model.js';
|
|
2
|
-
import { randomNumber, randomString } from '#test/test-helper.js';
|
|
3
|
-
|
|
4
|
-
const listModel: StubData[] = [
|
|
5
|
-
{
|
|
6
|
-
id: ('stub_' + randomString(24, 24)) as IdStub,
|
|
7
|
-
default: randomString(1, 50),
|
|
8
|
-
defaultNumber: randomNumber(12, 100),
|
|
9
|
-
untouchable: true,
|
|
10
|
-
allAuthorized: true,
|
|
11
|
-
ungettable: true,
|
|
12
|
-
unmodifiable: true,
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
id: ('stub_' + randomString(24, 24)) as IdStub,
|
|
16
|
-
default: randomString(1, 50),
|
|
17
|
-
defaultNumber: randomNumber(12, 100),
|
|
18
|
-
untouchable: true,
|
|
19
|
-
allAuthorized: true,
|
|
20
|
-
ungettable: true,
|
|
21
|
-
unmodifiable: true,
|
|
22
|
-
},
|
|
23
|
-
];
|
|
24
|
-
export default listModel;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { randomNumber, randomString } from '#test/test-helper.js';
|
|
2
|
-
|
|
3
|
-
const model = {
|
|
4
|
-
default: randomString(1, 50),
|
|
5
|
-
defaultNumber: randomNumber(12, 100),
|
|
6
|
-
untouchable: true,
|
|
7
|
-
allAuthorized: true,
|
|
8
|
-
ungettable: true,
|
|
9
|
-
unmodifiable: true,
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export default model;
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { Temporal } from 'temporal-polyfill';
|
|
2
|
-
import 'temporal-polyfill/global';
|
|
3
|
-
import { describe, expect, it } from 'vitest';
|
|
4
|
-
|
|
5
|
-
import { idAddress } from '#address/model.js';
|
|
6
|
-
import { AddressRepository } from '#address/repository.js';
|
|
7
|
-
import { Configuration } from '#api/configuration.js';
|
|
8
|
-
import { StancerRouteInaccessibleError } from '#error/endpoint/route-inaccessible-error.js';
|
|
9
|
-
import { randomString } from '#test/test-helper.js';
|
|
10
|
-
|
|
11
|
-
const config = Configuration;
|
|
12
|
-
config.setKey({
|
|
13
|
-
privateLiveKey: null,
|
|
14
|
-
privateTestKey: process.env['API_KEY'] ?? null,
|
|
15
|
-
});
|
|
16
|
-
config._host = process.env['API_HOST'] ?? 'api.stancer.com';
|
|
17
|
-
|
|
18
|
-
describe('address functional', () => {
|
|
19
|
-
describe('address creation', () => {
|
|
20
|
-
const city = randomString(1, 50);
|
|
21
|
-
const country = randomString(2);
|
|
22
|
-
const zipCode = randomString(2, 16);
|
|
23
|
-
|
|
24
|
-
it('create an address with aliased value', async () => {
|
|
25
|
-
const repository = new AddressRepository();
|
|
26
|
-
const address = await repository.create({ zipCode, city, country });
|
|
27
|
-
await repository.send(address);
|
|
28
|
-
expect(address.id).toBeTruthy();
|
|
29
|
-
expect(address.id).toContain('addr_');
|
|
30
|
-
expect(address.zipCode).toBe(zipCode);
|
|
31
|
-
expect(address.city).toBe(city);
|
|
32
|
-
expect(address.country).toBe(country);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('create an address', async () => {
|
|
36
|
-
const repository = new AddressRepository();
|
|
37
|
-
const address = await repository.create({ zipCode, city, country });
|
|
38
|
-
const newAddress = await repository.send(address);
|
|
39
|
-
expect(address._data).toStrictEqual(newAddress._data);
|
|
40
|
-
expect(newAddress.id).toBeTruthy();
|
|
41
|
-
expect(newAddress.zipCode).toBe(zipCode);
|
|
42
|
-
expect(newAddress._data.zipCode).toBe(newAddress.zipCode);
|
|
43
|
-
expect(newAddress.city).toBe(city);
|
|
44
|
-
expect(newAddress.country).toBe(country);
|
|
45
|
-
});
|
|
46
|
-
it('create a complete address', async () => {
|
|
47
|
-
const repository = new AddressRepository();
|
|
48
|
-
|
|
49
|
-
const zipCode = randomString(2, 16);
|
|
50
|
-
const city = randomString(1, 50);
|
|
51
|
-
const country = randomString(2);
|
|
52
|
-
|
|
53
|
-
const line1 = randomString(1, 50);
|
|
54
|
-
const line2 = randomString(1, 50);
|
|
55
|
-
const line3 = randomString(1, 50);
|
|
56
|
-
const state = randomString(1, 3);
|
|
57
|
-
|
|
58
|
-
const address = await repository.create({ zipCode, city, line1, line2, line3, state, country });
|
|
59
|
-
await repository.send(address);
|
|
60
|
-
expect(address.id).toBeTruthy();
|
|
61
|
-
expect(address.zipCode).toBe(zipCode);
|
|
62
|
-
expect(address._data.zipCode).toBe(address.zipCode);
|
|
63
|
-
expect(address.city).toBe(city);
|
|
64
|
-
expect(address.country).toBe(country);
|
|
65
|
-
expect(address.line1).toBe(line1);
|
|
66
|
-
expect(address.line2).toBe(line2);
|
|
67
|
-
expect(address.line3).toBe(line3);
|
|
68
|
-
expect(address.state).toBe(state);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('need required values', async () => {
|
|
72
|
-
const repository = new AddressRepository();
|
|
73
|
-
const addressWithoutZipCode = await repository.create({ city: randomString(1, 50), country: randomString(2) });
|
|
74
|
-
await expect(async () => await repository.send(addressWithoutZipCode)).rejects.toThrow(
|
|
75
|
-
'zipCode is required to send AddressModel',
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
const addressWithoutCity = await repository.create({ zipCode: 'Bloop', country: 'FR' });
|
|
79
|
-
await expect(async () => await repository.send(addressWithoutCity)).rejects.toThrow(
|
|
80
|
-
'city is required to send AddressModel',
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
const addressWithoutCountry = await repository.create({ zipCode: 'Bloop', city: randomString(12) });
|
|
84
|
-
await expect(async () => await repository.send(addressWithoutCountry)).rejects.toThrow(
|
|
85
|
-
'country is required to send AddressModel',
|
|
86
|
-
);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
describe('patch', () => {
|
|
90
|
-
it('is not available on address', async () => {
|
|
91
|
-
const repository = new AddressRepository();
|
|
92
|
-
|
|
93
|
-
const zipCode = randomString(2, 16);
|
|
94
|
-
const city = randomString(1, 50);
|
|
95
|
-
const country = randomString(2);
|
|
96
|
-
|
|
97
|
-
const address = await repository.create({ zipCode, city, country });
|
|
98
|
-
await repository.send(address);
|
|
99
|
-
address.setLine1(randomString(1, 25));
|
|
100
|
-
await expect(() => repository.send(address)).rejects.toThrow(StancerRouteInaccessibleError);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
describe('get', () => {
|
|
104
|
-
it('get the correct object', async () => {
|
|
105
|
-
const repository = new AddressRepository();
|
|
106
|
-
const id = idAddress('addr_YHvhVplBRGET3V7Ns4B6pzD2');
|
|
107
|
-
const address = await repository.create(id);
|
|
108
|
-
expect(address.id).toBe(id);
|
|
109
|
-
expect(address.zipCode).toBe('75008');
|
|
110
|
-
expect(address.zipCode).toBe(address._data.zipCode);
|
|
111
|
-
expect(address.city).toBe('Paris');
|
|
112
|
-
expect(address.country).toBe('FR');
|
|
113
|
-
expect(address.line1).toBe('10 rue');
|
|
114
|
-
expect(address.line2).toBe('de la ville');
|
|
115
|
-
expect(address.line3).toBe('leveque');
|
|
116
|
-
expect(address.state).toBe('IDF');
|
|
117
|
-
expect(address.createdAt).toBeInstanceOf(Temporal.Instant);
|
|
118
|
-
// we are not checking the exact hour for Timecode reason (not the same in our pipeline and locally)
|
|
119
|
-
expect(address.createdAt?.toLocaleString()).toContain('8/13/2026, ');
|
|
120
|
-
expect(address.createdAt?.toLocaleString()).toContain(':36:22 PM');
|
|
121
|
-
|
|
122
|
-
expect(address._data.createdAt).toStrictEqual(address.createdAt);
|
|
123
|
-
expect(address.deleted).toBe(false);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
});
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { Temporal } from 'temporal-polyfill';
|
|
2
|
-
import 'temporal-polyfill/global';
|
|
3
|
-
import { describe, expect, it } from 'vitest';
|
|
4
|
-
|
|
5
|
-
import { Configuration } from '#api/configuration.js';
|
|
6
|
-
import { PreferredNetworkCardEnum } from '#card/enum/network.js';
|
|
7
|
-
import { IdCard } from '#card/model.js';
|
|
8
|
-
import { CardRepository } from '#card/repository.js';
|
|
9
|
-
import { idCustomer } from '#customer/model.ts';
|
|
10
|
-
import { randomCVC, randomExpYear, randomMonth, randomNumber, randomString } from '#test/test-helper.js';
|
|
11
|
-
import { getValidCardNumber } from '#test/unit/card/card-helper.js';
|
|
12
|
-
|
|
13
|
-
const config = Configuration;
|
|
14
|
-
|
|
15
|
-
config.setKey({
|
|
16
|
-
privateLiveKey: null,
|
|
17
|
-
privateTestKey: process.env['API_KEY'] ?? null,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
config._host = process.env['API_HOST'] ?? 'api.stancer.com';
|
|
21
|
-
|
|
22
|
-
describe('card functional', () => {
|
|
23
|
-
describe('card creation', () => {
|
|
24
|
-
const expMonth = randomMonth();
|
|
25
|
-
const expYear = randomExpYear();
|
|
26
|
-
const number = getValidCardNumber();
|
|
27
|
-
|
|
28
|
-
it('create an card with minimum information', async () => {
|
|
29
|
-
const repository = new CardRepository();
|
|
30
|
-
|
|
31
|
-
const card = await repository.create({ expMonth, expYear, number });
|
|
32
|
-
await repository.send(card);
|
|
33
|
-
expect(card.id).toBeTruthy();
|
|
34
|
-
expect(card.id).toContain('card_');
|
|
35
|
-
expect(card.last4).toBe(number.slice(number.length - 4));
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('create a complete flat card', async () => {
|
|
39
|
-
const repository = new CardRepository();
|
|
40
|
-
const cvc = randomCVC();
|
|
41
|
-
const expMonth = randomMonth();
|
|
42
|
-
const expYear = randomExpYear();
|
|
43
|
-
const externalId = randomString(1, 36);
|
|
44
|
-
const number = getValidCardNumber();
|
|
45
|
-
const last4 = number.slice(number.length - 4);
|
|
46
|
-
const name = randomString(3, 64);
|
|
47
|
-
const preferredNetwork = PreferredNetworkCardEnum[randomNumber(0, PreferredNetworkCardEnum.length - 1)];
|
|
48
|
-
const zipCode = randomString(2, 8);
|
|
49
|
-
|
|
50
|
-
const card = await repository.create({
|
|
51
|
-
cvc,
|
|
52
|
-
expMonth,
|
|
53
|
-
expYear,
|
|
54
|
-
externalId,
|
|
55
|
-
number,
|
|
56
|
-
last4,
|
|
57
|
-
name,
|
|
58
|
-
preferredNetwork,
|
|
59
|
-
zipCode,
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
await repository.send(card);
|
|
63
|
-
|
|
64
|
-
expect(card.id).toBeTruthy();
|
|
65
|
-
expect(card).toMatchObject({ expMonth, expYear, last4 });
|
|
66
|
-
});
|
|
67
|
-
it('create a complete card with customer', async () => {
|
|
68
|
-
const repository = new CardRepository();
|
|
69
|
-
const customer = idCustomer(`cust_SsySBRtGUq3pG9zbSOhJSKCa`);
|
|
70
|
-
|
|
71
|
-
const expMonth = randomMonth();
|
|
72
|
-
const expYear = randomExpYear();
|
|
73
|
-
const number = getValidCardNumber();
|
|
74
|
-
|
|
75
|
-
const card = await repository.create({ customer, expMonth, expYear, number });
|
|
76
|
-
|
|
77
|
-
await repository.send(card);
|
|
78
|
-
|
|
79
|
-
expect(card.id).toBeTruthy();
|
|
80
|
-
expect(card.expMonth).toBe(expMonth);
|
|
81
|
-
expect(card.expYear).toBe(expYear);
|
|
82
|
-
expect(card.last4).toBe(number.slice(number.length - 4));
|
|
83
|
-
const now = Temporal.Now.plainDateISO();
|
|
84
|
-
// We check that the date had been created today.
|
|
85
|
-
// If not we cannot ensure the card has the customer we sent.
|
|
86
|
-
if (
|
|
87
|
-
card.createdAt?.toZonedDateTimeISO('UTC').year === now.year &&
|
|
88
|
-
card.createdAt?.toZonedDateTimeISO('UTC').month === now.month &&
|
|
89
|
-
card.createdAt?.toZonedDateTimeISO('UTC').day === now.day
|
|
90
|
-
) {
|
|
91
|
-
expect(card.customer).toBe(customer);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('need required expMonth', async () => {
|
|
96
|
-
const expYear = randomExpYear();
|
|
97
|
-
const number = getValidCardNumber();
|
|
98
|
-
|
|
99
|
-
const repository = new CardRepository();
|
|
100
|
-
|
|
101
|
-
const cardWithoutRequiredValue = await repository.create({ expYear, number });
|
|
102
|
-
|
|
103
|
-
await expect(async () => await repository.send(cardWithoutRequiredValue)).rejects.toThrow(
|
|
104
|
-
'expMonth is required to send CardModel',
|
|
105
|
-
);
|
|
106
|
-
});
|
|
107
|
-
it('need required expYear', async () => {
|
|
108
|
-
const repository = new CardRepository();
|
|
109
|
-
|
|
110
|
-
const cardWithoutRequiredValue = await repository.create({ expMonth, number });
|
|
111
|
-
|
|
112
|
-
await expect(async () => await repository.send(cardWithoutRequiredValue)).rejects.toThrow(
|
|
113
|
-
'expYear is required to send CardModel',
|
|
114
|
-
);
|
|
115
|
-
});
|
|
116
|
-
it('need required number', async () => {
|
|
117
|
-
const repository = new CardRepository();
|
|
118
|
-
|
|
119
|
-
const cardWithoutRequiredValue = await repository.create({ expMonth, expYear });
|
|
120
|
-
|
|
121
|
-
await expect(async () => await repository.send(cardWithoutRequiredValue)).rejects.toThrow(
|
|
122
|
-
'number is required to send CardModel',
|
|
123
|
-
);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
describe('patch', () => {
|
|
128
|
-
it('is available on card', async () => {
|
|
129
|
-
const repository = new CardRepository();
|
|
130
|
-
|
|
131
|
-
const expMonth = randomMonth();
|
|
132
|
-
const expYear = randomExpYear();
|
|
133
|
-
const number = getValidCardNumber();
|
|
134
|
-
const card = await repository.create({ expMonth, expYear, number });
|
|
135
|
-
|
|
136
|
-
await repository.send(card);
|
|
137
|
-
const id = card.id;
|
|
138
|
-
expect(id).toBeTruthy();
|
|
139
|
-
expect(card.expMonth).toBe(expMonth);
|
|
140
|
-
expect(card.expYear).toBe(expYear);
|
|
141
|
-
|
|
142
|
-
const newExpYear = randomExpYear() + 1;
|
|
143
|
-
card.setExpYear(newExpYear);
|
|
144
|
-
await repository.send(card);
|
|
145
|
-
expect(id).toBe(card.id);
|
|
146
|
-
expect(card.expYear).toBe(newExpYear);
|
|
147
|
-
expect(card.expMonth).toBe(expMonth);
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe('get', () => {
|
|
152
|
-
it('get the correct object', async () => {
|
|
153
|
-
const repository = new CardRepository();
|
|
154
|
-
const id = 'card_uqY2HrovY2sPm0Ac2xhnBkfU' as IdCard;
|
|
155
|
-
const card = await repository.create(id);
|
|
156
|
-
expect(card.id).toBe(id);
|
|
157
|
-
expect(card.brand).toBe('visa');
|
|
158
|
-
expect(card.country).toBe('US');
|
|
159
|
-
expect(card.funding).toBe('credit');
|
|
160
|
-
expect(card.last4).toBe('3055');
|
|
161
|
-
expect(card.nature).toBe('personal');
|
|
162
|
-
expect(card.network).toBe('visa');
|
|
163
|
-
expect(card.zipCode).toBe('75001');
|
|
164
|
-
expect(card.createdAt.epochMilliseconds).toBe(1758551022000);
|
|
165
|
-
expect(card.deleted).toBe(false);
|
|
166
|
-
expect(card.expMonth).toBe(12);
|
|
167
|
-
expect(card.expYear).toBe(2099);
|
|
168
|
-
});
|
|
169
|
-
it('get a 404 exception if unknown', async () => {
|
|
170
|
-
const id = 'card_' + randomString(24);
|
|
171
|
-
const repository = new CardRepository();
|
|
172
|
-
await expect(() => repository.create(id)).rejects.toThrow();
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
});
|