@appsemble/utils 0.30.14-test.6 → 0.32.1-test.14
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/README.md +3 -3
- package/allActions.js +5 -3
- package/api/components/parameters/$orderby.js +2 -2
- package/api/components/parameters/index.d.ts +2 -1
- package/api/components/parameters/index.js +2 -1
- package/api/components/parameters/webhookName.d.ts +2 -0
- package/api/components/parameters/webhookName.js +10 -0
- package/api/components/parameters/webhookSecretId.d.ts +2 -0
- package/api/components/parameters/webhookSecretId.js +8 -0
- package/api/components/schemas/ActionDefinition.js +3 -0
- package/api/components/schemas/App.js +8 -0
- package/api/components/schemas/AppDefinition.js +6 -0
- package/api/components/schemas/AppLayoutDefinition.js +8 -0
- package/api/components/schemas/AppServiceSecret.js +5 -0
- package/api/components/schemas/AppWebhookSecret.d.ts +2 -0
- package/api/components/schemas/AppWebhookSecret.js +25 -0
- package/api/components/schemas/DialogOkActionDefinition.js +1 -1
- package/api/components/schemas/FilterParametersDefinition.d.ts +2 -0
- package/api/components/schemas/FilterParametersDefinition.js +15 -0
- package/api/components/schemas/FlowCancelActionDefinition.js +1 -1
- package/api/components/schemas/FlowFinishActionDefinition.js +1 -1
- package/api/components/schemas/GroupMemberDeleteActionDefinition.js +1 -1
- package/api/components/schemas/ResourceDefinition.js +5 -0
- package/api/components/schemas/ResourceDeleteAllActionDefinition.d.ts +1 -0
- package/api/components/schemas/ResourceDeleteAllActionDefinition.js +21 -0
- package/api/components/schemas/ResourceDeleteBulkActionDefinition.d.ts +1 -0
- package/api/components/schemas/ResourceDeleteBulkActionDefinition.js +18 -0
- package/api/components/schemas/ResourceGetActionDefinition.js +3 -0
- package/api/components/schemas/ResourcePatchActionDefinition.js +3 -0
- package/api/components/schemas/ResourceSubscriptionStatusActionDefinition.js +1 -0
- package/api/components/schemas/ResourceSubscriptionSubscribeActionDefinition.js +1 -0
- package/api/components/schemas/ResourceSubscriptionToggleActionDefinition.js +1 -0
- package/api/components/schemas/ResourceSubscriptionUnsubscribeActionDefinition.js +1 -0
- package/api/components/schemas/ResourceUpdatePositionsActionDefinition.d.ts +1 -0
- package/api/components/schemas/ResourceUpdatePositionsActionDefinition.js +21 -0
- package/api/components/schemas/SecurityCronDefinition.d.ts +2 -0
- package/api/components/schemas/SecurityCronDefinition.js +26 -0
- package/api/components/schemas/SecurityDefinition.js +1 -0
- package/api/components/schemas/StorageSubtractActionDefinition.js +2 -2
- package/api/components/schemas/Training.js +2 -25
- package/api/components/schemas/TrainingCompleted.d.ts +2 -0
- package/api/components/schemas/TrainingCompleted.js +17 -0
- package/api/components/schemas/WebhookDefinition.d.ts +2 -0
- package/api/components/schemas/WebhookDefinition.js +17 -0
- package/api/components/schemas/index.d.ts +8 -1
- package/api/components/schemas/index.js +8 -1
- package/api/components/schemas/utils.js +1 -1
- package/api/components/securitySchemes/index.d.ts +1 -0
- package/api/components/securitySchemes/index.js +1 -0
- package/api/components/securitySchemes/webhook.d.ts +2 -0
- package/api/components/securitySchemes/webhook.js +6 -0
- package/api/paths/apps/appId/resources/resourceType/resourceId/positions.js +54 -0
- package/api/paths/apps/appId/secrets/webhook/secretId.js +61 -0
- package/api/paths/apps/appId/secrets/webhook.js +44 -0
- package/api/paths/apps/appId/webhooks/webhookName.js +35 -0
- package/api/paths/apps/appId.js +6 -0
- package/api/paths/auth/email/patchPassword.js +30 -0
- package/api/paths/index.d.ts +7 -5
- package/api/paths/index.js +16 -12
- package/api/paths/trainings/completeTraining.js +18 -0
- package/api/paths/trainings/completedTrainings.d.ts +2 -0
- package/api/paths/trainings/completedTrainings.js +21 -0
- package/api/paths/trainings/trainingIds.d.ts +2 -0
- package/api/paths/trainings/trainingIds.js +20 -0
- package/api/tags/index.js +4 -4
- package/appMessages.js +1 -1
- package/assets.js +1 -1
- package/authorization.d.ts +1 -1
- package/authorization.js +1 -1
- package/blockUtils.d.ts +1 -1
- package/blockUtils.js +1 -0
- package/convertToCsv.js +2 -0
- package/examples.js +214 -4
- package/formatRequestAction.js +2 -2
- package/has.d.ts +1 -1
- package/has.js +1 -1
- package/i18n.js +6 -8
- package/ics.js +1 -1
- package/iterApp.js +3 -3
- package/jsonschema.js +16 -3
- package/package.json +15 -11
- package/reference-schemas/actions/appMember.d.ts +2 -0
- package/reference-schemas/actions/appMember.js +21 -0
- package/reference-schemas/actions/flow.d.ts +2 -0
- package/reference-schemas/actions/flow.js +13 -0
- package/reference-schemas/actions/group.d.ts +2 -0
- package/reference-schemas/actions/group.js +13 -0
- package/reference-schemas/actions/index.d.ts +7 -0
- package/reference-schemas/actions/index.js +8 -0
- package/reference-schemas/actions/link.d.ts +2 -0
- package/reference-schemas/actions/link.js +9 -0
- package/reference-schemas/actions/miscellaneous.d.ts +2 -0
- package/reference-schemas/actions/miscellaneous.js +41 -0
- package/reference-schemas/actions/resources.d.ts +2 -0
- package/reference-schemas/actions/resources.js +19 -0
- package/reference-schemas/actions/storage.d.ts +2 -0
- package/reference-schemas/actions/storage.js +15 -0
- package/reference-schemas/remappers/conditionals.js +39 -0
- package/reference-schemas/remappers/data.js +26 -2
- package/reference-schemas/remappers/index.d.ts +1 -0
- package/reference-schemas/remappers/index.js +1 -0
- package/reference-schemas/remappers/objects.js +32 -0
- package/reference-schemas/remappers/odata.d.ts +2 -0
- package/reference-schemas/remappers/odata.js +95 -0
- package/reference-schemas/remappers/strings.js +33 -0
- package/reference-schemas/remappers/unsorted.js +9 -0
- package/remap.d.ts +2 -0
- package/remap.js +192 -15
- package/serializeResource.d.ts +7 -0
- package/serializeResource.js +7 -0
- package/serverActions.d.ts +1 -1
- package/serverActions.js +2 -0
- package/theme.js +5 -1
- package/validateStyle.js +2 -0
- package/validation.js +52 -16
- package/api/components/parameters/trainingBlockId.d.ts +0 -2
- package/api/components/parameters/trainingBlockId.js +0 -8
- package/api/components/schemas/TrainingBlock.d.ts +0 -2
- package/api/components/schemas/TrainingBlock.js +0 -38
- package/api/components/securitySchemes/cli.test.d.ts +0 -1
- package/api/components/securitySchemes/cli.test.js +0 -7
- package/api/index.test.d.ts +0 -1
- package/api/index.test.js +0 -180
- package/api/paths/trainingBlocks/trainingBlockId.js +0 -41
- package/api/paths/trainings/trainingId/blocks.js +0 -51
- package/api/paths/trainings/trainingId/users/current.js +0 -62
- package/api/paths/trainings/trainingId/users.js +0 -25
- package/api/paths/trainings/trainingId.js +0 -85
- package/api/paths/trainings.js +0 -44
- package/appMessages.test.d.ts +0 -1
- package/appMessages.test.js +0 -409
- package/blockUtils.test.d.ts +0 -1
- package/blockUtils.test.js +0 -77
- package/constants/patterns.test.d.ts +0 -1
- package/constants/patterns.test.js +0 -83
- package/convertToCsv.test.d.ts +0 -1
- package/convertToCsv.test.js +0 -55
- package/has.test.d.ts +0 -1
- package/has.test.js +0 -17
- package/i18n.test.d.ts +0 -1
- package/i18n.test.js +0 -76
- package/iterApp.test.d.ts +0 -1
- package/iterApp.test.js +0 -439
- package/jsonschema.test.d.ts +0 -1
- package/jsonschema.test.js +0 -256
- package/mapValues.test.d.ts +0 -1
- package/mapValues.test.js +0 -16
- package/miscellaneous.test.d.ts +0 -1
- package/miscellaneous.test.js +0 -87
- package/normalize.test.d.ts +0 -1
- package/normalize.test.js +0 -23
- package/objectCache.test.d.ts +0 -1
- package/objectCache.test.js +0 -20
- package/prefix.test.d.ts +0 -1
- package/prefix.test.js +0 -11
- package/remap.test.d.ts +0 -1
- package/remap.test.js +0 -1387
- package/string.test.d.ts +0 -1
- package/string.test.js +0 -27
- package/theme.test.d.ts +0 -1
- package/theme.test.js +0 -91
- package/validateStyle.test.d.ts +0 -1
- package/validateStyle.test.js +0 -13
- package/validation.test.d.ts +0 -1
- package/validation.test.js +0 -3121
- /package/api/paths/{trainingBlocks/trainingBlockId.d.ts → apps/appId/resources/resourceType/resourceId/positions.d.ts} +0 -0
- /package/api/paths/{trainings/trainingId.d.ts → apps/appId/secrets/webhook/secretId.d.ts} +0 -0
- /package/api/paths/{trainings.d.ts → apps/appId/secrets/webhook.d.ts} +0 -0
- /package/api/paths/{trainings/trainingId/blocks.d.ts → apps/appId/webhooks/webhookName.d.ts} +0 -0
- /package/api/paths/{trainings/trainingId/users.d.ts → auth/email/patchPassword.d.ts} +0 -0
- /package/api/paths/trainings/{trainingId/users/current.d.ts → completeTraining.d.ts} +0 -0
package/remap.test.js
DELETED
|
@@ -1,1387 +0,0 @@
|
|
|
1
|
-
import { IntlMessageFormat } from 'intl-messageformat';
|
|
2
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
-
import { createExampleContext, examples } from './examples.js';
|
|
4
|
-
import { remap } from './remap.js';
|
|
5
|
-
function runTests(tests) {
|
|
6
|
-
it.each(Object.entries(tests))('should %s', (name, { appMemberInfo, context, expected, history, input, mappers, messages, variables }) => {
|
|
7
|
-
const result = remap(mappers, input, {
|
|
8
|
-
getMessage: ({ defaultMessage, id }) => new IntlMessageFormat(messages?.messageIds?.[id] ?? defaultMessage),
|
|
9
|
-
getVariable: (variableName) => variables.find((variable) => variable.name === variableName)?.value,
|
|
10
|
-
url: 'https://example.com/en/example',
|
|
11
|
-
appUrl: 'https://example.com',
|
|
12
|
-
context,
|
|
13
|
-
history,
|
|
14
|
-
appId: 6789,
|
|
15
|
-
locale: 'en',
|
|
16
|
-
pageData: { hello: 'Page data' },
|
|
17
|
-
appMemberInfo,
|
|
18
|
-
});
|
|
19
|
-
expect(result).toStrictEqual(expected);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
describe('Primitive values', () => {
|
|
23
|
-
runTests({
|
|
24
|
-
'return a literal string': {
|
|
25
|
-
input: 'a string',
|
|
26
|
-
mappers: 'raw string',
|
|
27
|
-
expected: 'raw string',
|
|
28
|
-
},
|
|
29
|
-
'return a literal number': {
|
|
30
|
-
input: 'a string',
|
|
31
|
-
mappers: 42,
|
|
32
|
-
expected: 42,
|
|
33
|
-
},
|
|
34
|
-
'return a literal boolean': {
|
|
35
|
-
input: 'a string',
|
|
36
|
-
mappers: false,
|
|
37
|
-
expected: false,
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
describe('Nested arrays', () => {
|
|
42
|
-
runTests({
|
|
43
|
-
'flatten remappers': {
|
|
44
|
-
input: { value: 123 },
|
|
45
|
-
mappers: [[[[[{ prop: 'value' }]]]]],
|
|
46
|
-
expected: 123,
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
describe('app', () => {
|
|
51
|
-
runTests({
|
|
52
|
-
'return the app id': {
|
|
53
|
-
input: {},
|
|
54
|
-
mappers: { app: 'id' },
|
|
55
|
-
expected: 6789,
|
|
56
|
-
},
|
|
57
|
-
'return the curent url': {
|
|
58
|
-
input: {},
|
|
59
|
-
mappers: { app: 'url' },
|
|
60
|
-
expected: 'https://example.com',
|
|
61
|
-
},
|
|
62
|
-
'return the current locale': {
|
|
63
|
-
input: {},
|
|
64
|
-
mappers: { app: 'locale' },
|
|
65
|
-
expected: 'en',
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
describe('page', () => {
|
|
70
|
-
runTests({
|
|
71
|
-
'return the page url': {
|
|
72
|
-
input: {},
|
|
73
|
-
mappers: { page: 'url' },
|
|
74
|
-
expected: 'https://example.com/en/example',
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
runTests({
|
|
78
|
-
'return page data': {
|
|
79
|
-
input: {},
|
|
80
|
-
mappers: { page: 'data' },
|
|
81
|
-
expected: { hello: 'Page data' },
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
describe('context', () => {
|
|
86
|
-
runTests({
|
|
87
|
-
'get a simple property from context': {
|
|
88
|
-
input: {},
|
|
89
|
-
mappers: { context: 'name' },
|
|
90
|
-
expected: 'Spongebob',
|
|
91
|
-
context: { name: 'Spongebob' },
|
|
92
|
-
},
|
|
93
|
-
'get a nested property': {
|
|
94
|
-
input: {},
|
|
95
|
-
context: { address: { town: 'Bikini Bottom' } },
|
|
96
|
-
mappers: { context: 'address.town' },
|
|
97
|
-
expected: 'Bikini Bottom',
|
|
98
|
-
},
|
|
99
|
-
'handle null': {
|
|
100
|
-
input: {},
|
|
101
|
-
context: { name: 'Spongebob' },
|
|
102
|
-
mappers: { context: null },
|
|
103
|
-
expected: null,
|
|
104
|
-
},
|
|
105
|
-
'handle properties named null': {
|
|
106
|
-
input: {},
|
|
107
|
-
context: { null: 'Spongebob' },
|
|
108
|
-
mappers: { context: null },
|
|
109
|
-
expected: 'Spongebob',
|
|
110
|
-
},
|
|
111
|
-
'handle null values': {
|
|
112
|
-
input: {},
|
|
113
|
-
mappers: { context: 'foo.bar' },
|
|
114
|
-
expected: null,
|
|
115
|
-
},
|
|
116
|
-
'return null if context is not available': {
|
|
117
|
-
input: {},
|
|
118
|
-
mappers: { context: 'test' },
|
|
119
|
-
expected: null,
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
describe('variable', () => {
|
|
124
|
-
runTests({
|
|
125
|
-
'get a variable': {
|
|
126
|
-
input: {},
|
|
127
|
-
mappers: { variable: 'my-variable' },
|
|
128
|
-
expected: 'my-variable-value',
|
|
129
|
-
variables: [{ id: 0, name: 'my-variable', value: 'my-variable-value' }],
|
|
130
|
-
},
|
|
131
|
-
'get an undefined variable': {
|
|
132
|
-
input: {},
|
|
133
|
-
mappers: { variable: 'my-variable' },
|
|
134
|
-
expected: undefined,
|
|
135
|
-
variables: [],
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
describe('number.parse', () => {
|
|
140
|
-
runTests({
|
|
141
|
-
'return the parsed number': {
|
|
142
|
-
input: '42',
|
|
143
|
-
mappers: { 'number.parse': null },
|
|
144
|
-
expected: 42,
|
|
145
|
-
},
|
|
146
|
-
'return the parsed decimal number': {
|
|
147
|
-
input: '42.5',
|
|
148
|
-
mappers: { 'number.parse': null },
|
|
149
|
-
expected: 42.5,
|
|
150
|
-
},
|
|
151
|
-
'return 0 if there is no input': {
|
|
152
|
-
input: null,
|
|
153
|
-
mappers: { 'number.parse': null },
|
|
154
|
-
expected: 0,
|
|
155
|
-
},
|
|
156
|
-
'return the input if it can not be converted': {
|
|
157
|
-
input: 'test',
|
|
158
|
-
mappers: { 'number.parse': null },
|
|
159
|
-
expected: 'test',
|
|
160
|
-
},
|
|
161
|
-
'return the parsed integer from a remapper': {
|
|
162
|
-
input: { number: '42' },
|
|
163
|
-
mappers: { 'number.parse': { prop: 'number' } },
|
|
164
|
-
expected: 42,
|
|
165
|
-
},
|
|
166
|
-
'return the parsed decimal from a remapper': {
|
|
167
|
-
input: { number: '42.5' },
|
|
168
|
-
mappers: { 'number.parse': { prop: 'number' } },
|
|
169
|
-
expected: 42.5,
|
|
170
|
-
},
|
|
171
|
-
'return 0 if the remapped value is null': {
|
|
172
|
-
input: { number: null },
|
|
173
|
-
mappers: { 'number.parse': { prop: 'number' } },
|
|
174
|
-
expected: 0,
|
|
175
|
-
},
|
|
176
|
-
'return the remapped value if it can not be parsed': {
|
|
177
|
-
input: { number: 'test' },
|
|
178
|
-
mappers: { 'number.parse': { prop: 'number' } },
|
|
179
|
-
expected: 'test',
|
|
180
|
-
},
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
describe('date.now', () => {
|
|
184
|
-
beforeEach(() => {
|
|
185
|
-
vi.useFakeTimers({ now: 0 });
|
|
186
|
-
});
|
|
187
|
-
runTests({
|
|
188
|
-
'return the current date': {
|
|
189
|
-
input: 'whatever',
|
|
190
|
-
mappers: { 'date.now': {} },
|
|
191
|
-
expected: new Date(0),
|
|
192
|
-
},
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
describe('date.add', () => {
|
|
196
|
-
beforeEach(() => {
|
|
197
|
-
vi.useFakeTimers({ now: 0 });
|
|
198
|
-
});
|
|
199
|
-
runTests({
|
|
200
|
-
'add 3 days to the given date': {
|
|
201
|
-
input: 'whatever',
|
|
202
|
-
mappers: [{ 'date.now': {} }, { 'date.add': '3d' }],
|
|
203
|
-
expected: new Date(3 * 24 * 60 * 60 * 1e3),
|
|
204
|
-
},
|
|
205
|
-
'add 3 days to the given date as number': {
|
|
206
|
-
input: 20e3,
|
|
207
|
-
mappers: [{ 'date.add': '3d' }],
|
|
208
|
-
expected: new Date(3 * 24 * 60 * 60 * 1e3 + 20e3),
|
|
209
|
-
},
|
|
210
|
-
'subtract 1 day from the given date': {
|
|
211
|
-
input: 'whatever',
|
|
212
|
-
mappers: [{ 'date.now': {} }, { 'date.add': '-1d' }],
|
|
213
|
-
expected: new Date(-(24 * 60 * 60 * 1e3)),
|
|
214
|
-
},
|
|
215
|
-
'return input when input is nothing': {
|
|
216
|
-
input: undefined,
|
|
217
|
-
mappers: [{ 'date.add': '3d' }],
|
|
218
|
-
expected: undefined,
|
|
219
|
-
},
|
|
220
|
-
'return input when input is not a date': {
|
|
221
|
-
input: 'whatever',
|
|
222
|
-
mappers: [{ 'date.add': '3d' }],
|
|
223
|
-
expected: 'whatever',
|
|
224
|
-
},
|
|
225
|
-
'return input date when duration is invalid': {
|
|
226
|
-
input: new Date(1000),
|
|
227
|
-
mappers: [{ 'date.add': '3dd' }],
|
|
228
|
-
expected: new Date(1000),
|
|
229
|
-
},
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
describe('date.format', () => {
|
|
233
|
-
runTests({
|
|
234
|
-
'format date objects': {
|
|
235
|
-
input: new Date('2020-01-02T03:04:05Z'),
|
|
236
|
-
mappers: { 'date.format': null },
|
|
237
|
-
expected: '2020-01-02T03:04:05.000Z',
|
|
238
|
-
},
|
|
239
|
-
'format date strings': {
|
|
240
|
-
input: '2020-01-02T03:04:05Z',
|
|
241
|
-
mappers: { 'date.format': null },
|
|
242
|
-
expected: '2020-01-02T03:04:05.000Z',
|
|
243
|
-
},
|
|
244
|
-
'format unix timestamps': {
|
|
245
|
-
input: 0,
|
|
246
|
-
mappers: { 'date.format': null },
|
|
247
|
-
expected: '1970-01-01T00:00:00.000Z',
|
|
248
|
-
},
|
|
249
|
-
'format date objects to custom format': {
|
|
250
|
-
input: new Date('2020-01-02T03:04:05Z'),
|
|
251
|
-
mappers: { 'date.format': 'dd-MM-yyyy' },
|
|
252
|
-
expected: '02-01-2020',
|
|
253
|
-
},
|
|
254
|
-
'format date strings to custom format': {
|
|
255
|
-
input: '2020-01-02T03:04:05Z',
|
|
256
|
-
mappers: { 'date.format': 'yyyy-MM-dd' },
|
|
257
|
-
expected: '2020-01-02',
|
|
258
|
-
},
|
|
259
|
-
'format unix timestamps to custom format': {
|
|
260
|
-
input: 0,
|
|
261
|
-
mappers: { 'date.format': 'MM/dd/yyyy' },
|
|
262
|
-
expected: '01/01/1970',
|
|
263
|
-
},
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
describe('log', () => {
|
|
267
|
-
beforeEach(() => {
|
|
268
|
-
vi.spyOn(console, 'error').mockImplementation(null);
|
|
269
|
-
vi.spyOn(console, 'info').mockImplementation(null);
|
|
270
|
-
vi.spyOn(console, 'warn').mockImplementation(null);
|
|
271
|
-
});
|
|
272
|
-
function runLogTests(tests) {
|
|
273
|
-
it.each(Object.entries(tests))('should %s', (name, { appMemberInfo, context, expected: expectedInput, history, input, mappers, messages, variables, }) => {
|
|
274
|
-
const expected = JSON.stringify({
|
|
275
|
-
input: expectedInput,
|
|
276
|
-
context: {
|
|
277
|
-
root: {
|
|
278
|
-
message: 'hi mom!',
|
|
279
|
-
},
|
|
280
|
-
url: 'https://example.com/en/example',
|
|
281
|
-
appUrl: 'https://example.com',
|
|
282
|
-
appId: 6789,
|
|
283
|
-
locale: 'en',
|
|
284
|
-
pageData: {
|
|
285
|
-
hello: 'Page data',
|
|
286
|
-
},
|
|
287
|
-
},
|
|
288
|
-
}, null, 2);
|
|
289
|
-
remap(mappers, input, {
|
|
290
|
-
getMessage: ({ defaultMessage, id }) => new IntlMessageFormat(messages?.messageIds?.[id] ?? defaultMessage),
|
|
291
|
-
getVariable: (variableName) => variables.find((variable) => variable.name === variableName).value,
|
|
292
|
-
url: 'https://example.com/en/example',
|
|
293
|
-
appUrl: 'https://example.com',
|
|
294
|
-
context,
|
|
295
|
-
history,
|
|
296
|
-
appId: 6789,
|
|
297
|
-
locale: 'en',
|
|
298
|
-
pageData: { hello: 'Page data' },
|
|
299
|
-
appMemberInfo,
|
|
300
|
-
});
|
|
301
|
-
expect(console[mappers.log]).toHaveBeenCalledWith(expected);
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
runLogTests({
|
|
305
|
-
'log `hi mom!` with log level `info`': {
|
|
306
|
-
input: { message: 'hi mom!' },
|
|
307
|
-
mappers: { log: 'info' },
|
|
308
|
-
expected: { message: 'hi mom!' },
|
|
309
|
-
},
|
|
310
|
-
'log `hi mom!` with log level `warn`': {
|
|
311
|
-
input: { message: 'hi mom!' },
|
|
312
|
-
mappers: { log: 'warn' },
|
|
313
|
-
expected: { message: 'hi mom!' },
|
|
314
|
-
},
|
|
315
|
-
'log `hi mom!` with log level `error`': {
|
|
316
|
-
input: { message: 'hi mom!' },
|
|
317
|
-
mappers: { log: 'error' },
|
|
318
|
-
expected: { message: 'hi mom!' },
|
|
319
|
-
},
|
|
320
|
-
});
|
|
321
|
-
runTests({
|
|
322
|
-
'return input': {
|
|
323
|
-
input: 'input',
|
|
324
|
-
mappers: { log: 'info' },
|
|
325
|
-
expected: 'input',
|
|
326
|
-
},
|
|
327
|
-
});
|
|
328
|
-
});
|
|
329
|
-
describe('le', () => {
|
|
330
|
-
runTests({
|
|
331
|
-
'return true if the left value is less than the right value': {
|
|
332
|
-
input: { left: 42, right: 420 },
|
|
333
|
-
mappers: { lt: [{ prop: 'left' }, { prop: 'right' }] },
|
|
334
|
-
expected: true,
|
|
335
|
-
},
|
|
336
|
-
'work with dates': {
|
|
337
|
-
input: { left: new Date(200000), right: new Date(0) },
|
|
338
|
-
mappers: { gt: [{ prop: 'left' }, { prop: 'right' }] },
|
|
339
|
-
expected: true,
|
|
340
|
-
},
|
|
341
|
-
'work with strings': {
|
|
342
|
-
input: { left: 'aa', right: 'a' },
|
|
343
|
-
mappers: { gt: [{ prop: 'left' }, { prop: 'right' }] },
|
|
344
|
-
expected: true,
|
|
345
|
-
},
|
|
346
|
-
});
|
|
347
|
-
});
|
|
348
|
-
describe('ge', () => {
|
|
349
|
-
runTests({
|
|
350
|
-
'return true if the left value is greater than the right value': {
|
|
351
|
-
input: { left: 420, right: 42 },
|
|
352
|
-
mappers: { gt: [{ prop: 'left' }, { prop: 'right' }] },
|
|
353
|
-
expected: true,
|
|
354
|
-
},
|
|
355
|
-
'work with dates': {
|
|
356
|
-
input: { left: new Date(200000), right: new Date(0) },
|
|
357
|
-
mappers: { gt: [{ prop: 'left' }, { prop: 'right' }] },
|
|
358
|
-
expected: true,
|
|
359
|
-
},
|
|
360
|
-
'work with strings': {
|
|
361
|
-
input: { left: 'aa', right: 'a' },
|
|
362
|
-
mappers: { gt: [{ prop: 'left' }, { prop: 'right' }] },
|
|
363
|
-
expected: true,
|
|
364
|
-
},
|
|
365
|
-
});
|
|
366
|
-
});
|
|
367
|
-
describe('equals', () => {
|
|
368
|
-
runTests({
|
|
369
|
-
'return true if all values are equal': {
|
|
370
|
-
input: [1, 1, 1],
|
|
371
|
-
mappers: { equals: [{ prop: '0' }, { prop: '1' }, { prop: '2' }] },
|
|
372
|
-
expected: true,
|
|
373
|
-
},
|
|
374
|
-
'use deep equality': {
|
|
375
|
-
input: [{ foo: { bar: 3 } }, { foo: { bar: 3 } }],
|
|
376
|
-
mappers: { equals: [{ prop: '0' }, { prop: '1' }] },
|
|
377
|
-
expected: true,
|
|
378
|
-
},
|
|
379
|
-
'return false if not all values are equal': {
|
|
380
|
-
input: [{ foo: { bar: 3 } }, { foo: { bar: 2 } }],
|
|
381
|
-
mappers: { equals: [{ prop: '0' }, { prop: '1' }] },
|
|
382
|
-
expected: false,
|
|
383
|
-
},
|
|
384
|
-
'return true on empty arrays': {
|
|
385
|
-
input: { empty: [] },
|
|
386
|
-
mappers: { equals: [] },
|
|
387
|
-
expected: true,
|
|
388
|
-
},
|
|
389
|
-
'return true on arrays with 1 entry': {
|
|
390
|
-
input: { empty: [] },
|
|
391
|
-
mappers: { equals: [{ prop: 'empty' }] },
|
|
392
|
-
expected: true,
|
|
393
|
-
},
|
|
394
|
-
});
|
|
395
|
-
});
|
|
396
|
-
describe('not', () => {
|
|
397
|
-
runTests({
|
|
398
|
-
'return false if any of the values are equal to the first': {
|
|
399
|
-
input: [1, 2, 1],
|
|
400
|
-
mappers: { not: [{ prop: '0' }, { prop: '1' }, { prop: '2' }] },
|
|
401
|
-
expected: false,
|
|
402
|
-
},
|
|
403
|
-
'use deep equality': {
|
|
404
|
-
input: [{ foo: { bar: 3 } }, { foo: { bar: 3 } }],
|
|
405
|
-
mappers: { not: [{ prop: '0' }, { prop: '1' }] },
|
|
406
|
-
expected: false,
|
|
407
|
-
},
|
|
408
|
-
'return true if all values are not equal to the first': {
|
|
409
|
-
input: [{ foo: { bar: 3 } }, { foo: { bar: 2 } }, { foo: { bar: 2 } }],
|
|
410
|
-
mappers: { not: [{ prop: '0' }, { prop: '1' }] },
|
|
411
|
-
expected: true,
|
|
412
|
-
},
|
|
413
|
-
'return true if (computed) input is false': {
|
|
414
|
-
input: false,
|
|
415
|
-
mappers: { not: [{ root: null }] },
|
|
416
|
-
expected: true,
|
|
417
|
-
},
|
|
418
|
-
'return false if (computed) input is true': {
|
|
419
|
-
input: true,
|
|
420
|
-
mappers: { not: [{ root: null }] },
|
|
421
|
-
expected: false,
|
|
422
|
-
},
|
|
423
|
-
'return true when mappers is empty': {
|
|
424
|
-
input: true,
|
|
425
|
-
mappers: { not: [] },
|
|
426
|
-
expected: true,
|
|
427
|
-
},
|
|
428
|
-
});
|
|
429
|
-
});
|
|
430
|
-
describe('ics', () => {
|
|
431
|
-
runTests({
|
|
432
|
-
'support string date': {
|
|
433
|
-
input: {
|
|
434
|
-
date: '2023-01-01T00:00:00Z',
|
|
435
|
-
title: 'Happy new year!',
|
|
436
|
-
description: 'Best wishes for 2023 🍾',
|
|
437
|
-
url: 'https://example.com',
|
|
438
|
-
location: 'Earth',
|
|
439
|
-
latlng: [0, 0],
|
|
440
|
-
},
|
|
441
|
-
mappers: [
|
|
442
|
-
{
|
|
443
|
-
ics: {
|
|
444
|
-
start: { prop: 'date' },
|
|
445
|
-
title: { prop: 'title' },
|
|
446
|
-
description: { prop: 'description' },
|
|
447
|
-
duration: '24h',
|
|
448
|
-
url: { prop: 'url' },
|
|
449
|
-
location: { prop: 'location' },
|
|
450
|
-
coordinates: { prop: 'latlng' },
|
|
451
|
-
},
|
|
452
|
-
},
|
|
453
|
-
{ 'string.replace': { 'UID:[\\w-]+': 'UID:UID_STUB' } },
|
|
454
|
-
{ 'string.replace': { 'DTSTAMP:\\w+': 'DTSTAMP:DTSTAMP_STUB' } },
|
|
455
|
-
],
|
|
456
|
-
expected: `BEGIN:VCALENDAR\r
|
|
457
|
-
VERSION:2.0\r
|
|
458
|
-
CALSCALE:GREGORIAN\r
|
|
459
|
-
PRODID:https://example.com\r
|
|
460
|
-
METHOD:PUBLISH\r
|
|
461
|
-
X-PUBLISHED-TTL:PT1H\r
|
|
462
|
-
BEGIN:VEVENT\r
|
|
463
|
-
UID:UID_STUB\r
|
|
464
|
-
SUMMARY:Happy new year!\r
|
|
465
|
-
DTSTAMP:DTSTAMP_STUB\r
|
|
466
|
-
DTSTART:20230101T000000Z\r
|
|
467
|
-
DESCRIPTION:Best wishes for 2023 🍾\r
|
|
468
|
-
URL:https://example.com\r
|
|
469
|
-
GEO:0;0\r
|
|
470
|
-
LOCATION:Earth\r
|
|
471
|
-
DURATION:P1DT\r
|
|
472
|
-
END:VEVENT\r
|
|
473
|
-
END:VCALENDAR\r
|
|
474
|
-
`,
|
|
475
|
-
},
|
|
476
|
-
'support JavaScript date': {
|
|
477
|
-
input: {
|
|
478
|
-
date: new Date('2023-01-01T00:00:00Z'),
|
|
479
|
-
title: 'Happy new year!',
|
|
480
|
-
description: 'Best wishes for 2023 🍾',
|
|
481
|
-
url: 'https://example.com',
|
|
482
|
-
location: 'Earth',
|
|
483
|
-
latlng: [0, 0],
|
|
484
|
-
},
|
|
485
|
-
mappers: [
|
|
486
|
-
{
|
|
487
|
-
ics: {
|
|
488
|
-
start: { prop: 'date' },
|
|
489
|
-
title: { prop: 'title' },
|
|
490
|
-
description: { prop: 'description' },
|
|
491
|
-
duration: '24h',
|
|
492
|
-
url: { prop: 'url' },
|
|
493
|
-
location: { prop: 'location' },
|
|
494
|
-
coordinates: { prop: 'latlng' },
|
|
495
|
-
},
|
|
496
|
-
},
|
|
497
|
-
{ 'string.replace': { 'UID:[\\w-]+': 'UID:UID_STUB' } },
|
|
498
|
-
{ 'string.replace': { 'DTSTAMP:\\w+': 'DTSTAMP:DTSTAMP_STUB' } },
|
|
499
|
-
],
|
|
500
|
-
expected: `BEGIN:VCALENDAR\r
|
|
501
|
-
VERSION:2.0\r
|
|
502
|
-
CALSCALE:GREGORIAN\r
|
|
503
|
-
PRODID:https://example.com\r
|
|
504
|
-
METHOD:PUBLISH\r
|
|
505
|
-
X-PUBLISHED-TTL:PT1H\r
|
|
506
|
-
BEGIN:VEVENT\r
|
|
507
|
-
UID:UID_STUB\r
|
|
508
|
-
SUMMARY:Happy new year!\r
|
|
509
|
-
DTSTAMP:DTSTAMP_STUB\r
|
|
510
|
-
DTSTART:20230101T000000Z\r
|
|
511
|
-
DESCRIPTION:Best wishes for 2023 🍾\r
|
|
512
|
-
URL:https://example.com\r
|
|
513
|
-
GEO:0;0\r
|
|
514
|
-
LOCATION:Earth\r
|
|
515
|
-
DURATION:P1DT\r
|
|
516
|
-
END:VEVENT\r
|
|
517
|
-
END:VCALENDAR\r
|
|
518
|
-
`,
|
|
519
|
-
},
|
|
520
|
-
'support end string date': {
|
|
521
|
-
input: {
|
|
522
|
-
date: '2023-01-01T00:00:00Z',
|
|
523
|
-
endDate: '2023-01-02T00:00:00Z',
|
|
524
|
-
title: 'Happy new year!',
|
|
525
|
-
description: 'Best wishes for 2023 🍾',
|
|
526
|
-
url: 'https://example.com',
|
|
527
|
-
location: 'Earth',
|
|
528
|
-
latlng: [0, 0],
|
|
529
|
-
},
|
|
530
|
-
mappers: [
|
|
531
|
-
{
|
|
532
|
-
ics: {
|
|
533
|
-
start: { prop: 'date' },
|
|
534
|
-
title: { prop: 'title' },
|
|
535
|
-
description: { prop: 'description' },
|
|
536
|
-
end: { prop: 'endDate' },
|
|
537
|
-
url: { prop: 'url' },
|
|
538
|
-
location: { prop: 'location' },
|
|
539
|
-
coordinates: { prop: 'latlng' },
|
|
540
|
-
},
|
|
541
|
-
},
|
|
542
|
-
{ 'string.replace': { 'UID:[\\w-]+': 'UID:UID_STUB' } },
|
|
543
|
-
{ 'string.replace': { 'DTSTAMP:\\w+': 'DTSTAMP:DTSTAMP_STUB' } },
|
|
544
|
-
],
|
|
545
|
-
expected: `BEGIN:VCALENDAR\r
|
|
546
|
-
VERSION:2.0\r
|
|
547
|
-
CALSCALE:GREGORIAN\r
|
|
548
|
-
PRODID:https://example.com\r
|
|
549
|
-
METHOD:PUBLISH\r
|
|
550
|
-
X-PUBLISHED-TTL:PT1H\r
|
|
551
|
-
BEGIN:VEVENT\r
|
|
552
|
-
UID:UID_STUB\r
|
|
553
|
-
SUMMARY:Happy new year!\r
|
|
554
|
-
DTSTAMP:DTSTAMP_STUB\r
|
|
555
|
-
DTSTART:20230101T000000Z\r
|
|
556
|
-
DTEND:20230102T000000Z\r
|
|
557
|
-
DESCRIPTION:Best wishes for 2023 🍾\r
|
|
558
|
-
URL:https://example.com\r
|
|
559
|
-
GEO:0;0\r
|
|
560
|
-
LOCATION:Earth\r
|
|
561
|
-
END:VEVENT\r
|
|
562
|
-
END:VCALENDAR\r
|
|
563
|
-
`,
|
|
564
|
-
},
|
|
565
|
-
'support end JavaScript date': {
|
|
566
|
-
input: {
|
|
567
|
-
date: new Date('2023-01-01T00:00:00Z'),
|
|
568
|
-
endDate: new Date('2023-01-02T00:00:00Z'),
|
|
569
|
-
title: 'Happy new year!',
|
|
570
|
-
description: 'Best wishes for 2023 🍾',
|
|
571
|
-
url: 'https://example.com',
|
|
572
|
-
location: 'Earth',
|
|
573
|
-
latlng: [0, 0],
|
|
574
|
-
},
|
|
575
|
-
mappers: [
|
|
576
|
-
{
|
|
577
|
-
ics: {
|
|
578
|
-
start: { prop: 'date' },
|
|
579
|
-
title: { prop: 'title' },
|
|
580
|
-
description: { prop: 'description' },
|
|
581
|
-
end: { prop: 'endDate' },
|
|
582
|
-
url: { prop: 'url' },
|
|
583
|
-
location: { prop: 'location' },
|
|
584
|
-
coordinates: { prop: 'latlng' },
|
|
585
|
-
},
|
|
586
|
-
},
|
|
587
|
-
{ 'string.replace': { 'UID:[\\w-]+': 'UID:UID_STUB' } },
|
|
588
|
-
{ 'string.replace': { 'DTSTAMP:\\w+': 'DTSTAMP:DTSTAMP_STUB' } },
|
|
589
|
-
],
|
|
590
|
-
expected: `BEGIN:VCALENDAR\r
|
|
591
|
-
VERSION:2.0\r
|
|
592
|
-
CALSCALE:GREGORIAN\r
|
|
593
|
-
PRODID:https://example.com\r
|
|
594
|
-
METHOD:PUBLISH\r
|
|
595
|
-
X-PUBLISHED-TTL:PT1H\r
|
|
596
|
-
BEGIN:VEVENT\r
|
|
597
|
-
UID:UID_STUB\r
|
|
598
|
-
SUMMARY:Happy new year!\r
|
|
599
|
-
DTSTAMP:DTSTAMP_STUB\r
|
|
600
|
-
DTSTART:20230101T000000Z\r
|
|
601
|
-
DTEND:20230102T000000Z\r
|
|
602
|
-
DESCRIPTION:Best wishes for 2023 🍾\r
|
|
603
|
-
URL:https://example.com\r
|
|
604
|
-
GEO:0;0\r
|
|
605
|
-
LOCATION:Earth\r
|
|
606
|
-
END:VEVENT\r
|
|
607
|
-
END:VCALENDAR\r
|
|
608
|
-
`,
|
|
609
|
-
},
|
|
610
|
-
});
|
|
611
|
-
});
|
|
612
|
-
describe('if', () => {
|
|
613
|
-
runTests({
|
|
614
|
-
'return the value of then if condition is truthy': {
|
|
615
|
-
input: { really: true },
|
|
616
|
-
mappers: { if: { condition: { prop: 'really' }, else: 'no really', then: 'yes really' } },
|
|
617
|
-
expected: 'yes really',
|
|
618
|
-
},
|
|
619
|
-
'return the value of else if condition is falsy': {
|
|
620
|
-
input: { really: false },
|
|
621
|
-
mappers: { if: { condition: { prop: 'really' }, else: 'no really', then: 'yes really' } },
|
|
622
|
-
expected: 'no really',
|
|
623
|
-
},
|
|
624
|
-
'return the value of then if condition is empty': {
|
|
625
|
-
input: { really: false },
|
|
626
|
-
mappers: { if: { condition: [], else: 'no really', then: 'yes really' } },
|
|
627
|
-
expected: 'yes really',
|
|
628
|
-
},
|
|
629
|
-
'return input if else is empty': {
|
|
630
|
-
input: { really: false },
|
|
631
|
-
mappers: { if: { condition: { prop: 'really' }, else: [], then: 'yes really' } },
|
|
632
|
-
expected: { really: false },
|
|
633
|
-
},
|
|
634
|
-
'return input if then is empty': {
|
|
635
|
-
input: { really: true },
|
|
636
|
-
mappers: { if: { condition: { prop: 'really' }, else: 'no really', then: [] } },
|
|
637
|
-
expected: { really: true },
|
|
638
|
-
},
|
|
639
|
-
});
|
|
640
|
-
});
|
|
641
|
-
describe('match', () => {
|
|
642
|
-
runTests({
|
|
643
|
-
'return the value of the first case if case is truthy': {
|
|
644
|
-
input: {},
|
|
645
|
-
mappers: {
|
|
646
|
-
match: [
|
|
647
|
-
{ case: true, value: 'case 1' },
|
|
648
|
-
{ case: true, value: 'case 2' },
|
|
649
|
-
{ case: true, value: 'case 3' },
|
|
650
|
-
],
|
|
651
|
-
},
|
|
652
|
-
expected: 'case 1',
|
|
653
|
-
},
|
|
654
|
-
});
|
|
655
|
-
runTests({
|
|
656
|
-
'return the value of the second case if case 1 is falsy and 2 is truthy': {
|
|
657
|
-
input: {},
|
|
658
|
-
mappers: {
|
|
659
|
-
match: [
|
|
660
|
-
{ case: false, value: 'case 1' },
|
|
661
|
-
{ case: true, value: 'case 2' },
|
|
662
|
-
{ case: false, value: 'case 3' },
|
|
663
|
-
],
|
|
664
|
-
},
|
|
665
|
-
expected: 'case 2',
|
|
666
|
-
},
|
|
667
|
-
});
|
|
668
|
-
runTests({
|
|
669
|
-
'return null if all cases are falsy': {
|
|
670
|
-
input: {},
|
|
671
|
-
mappers: { match: [{ case: false, value: 'case 1' }] },
|
|
672
|
-
expected: null,
|
|
673
|
-
},
|
|
674
|
-
});
|
|
675
|
-
});
|
|
676
|
-
describe('object.from', () => {
|
|
677
|
-
runTests({
|
|
678
|
-
'create a new object from remappers': {
|
|
679
|
-
input: { givenName: 'Patrick', familyName: 'Star', species: 'Starfish' },
|
|
680
|
-
mappers: {
|
|
681
|
-
'object.from': { firstName: { prop: 'givenName' }, lastName: { prop: 'familyName' } },
|
|
682
|
-
},
|
|
683
|
-
expected: { firstName: 'Patrick', lastName: 'Star' },
|
|
684
|
-
},
|
|
685
|
-
});
|
|
686
|
-
});
|
|
687
|
-
describe('object.omit', () => {
|
|
688
|
-
runTests({
|
|
689
|
-
'omit properties from existing object': {
|
|
690
|
-
input: { foo: 'foo', bar: 'bar', baz: 'baz' },
|
|
691
|
-
mappers: {
|
|
692
|
-
'object.omit': ['bar'],
|
|
693
|
-
},
|
|
694
|
-
expected: { foo: 'foo', baz: 'baz' },
|
|
695
|
-
},
|
|
696
|
-
'delete nested properties': {
|
|
697
|
-
input: { foo: 1, bar: 'bar', baz: { test: 'foo', test2: 10 } },
|
|
698
|
-
mappers: {
|
|
699
|
-
'object.omit': ['bar', ['baz', 'test']],
|
|
700
|
-
},
|
|
701
|
-
expected: { foo: 1, baz: { test2: 10 } },
|
|
702
|
-
},
|
|
703
|
-
'handle non existing properties': {
|
|
704
|
-
input: { foo: 1, bar: 'bar', baz: { test: 'foo', test2: 10 } },
|
|
705
|
-
mappers: {
|
|
706
|
-
'object.omit': ['bar', ['baz', '5']],
|
|
707
|
-
},
|
|
708
|
-
expected: { foo: 1, baz: { test: 'foo', test2: 10 } },
|
|
709
|
-
},
|
|
710
|
-
});
|
|
711
|
-
});
|
|
712
|
-
describe('object.assign', () => {
|
|
713
|
-
runTests({
|
|
714
|
-
'assign to an object from remappers': {
|
|
715
|
-
input: { givenName: 'Patrick', familyName: 'Star' },
|
|
716
|
-
mappers: {
|
|
717
|
-
'object.assign': {
|
|
718
|
-
familyName: [{ prop: 'familyName' }, { 'string.case': 'lower' }],
|
|
719
|
-
species: 'Starfish',
|
|
720
|
-
},
|
|
721
|
-
},
|
|
722
|
-
expected: { givenName: 'Patrick', familyName: 'star', species: 'Starfish' },
|
|
723
|
-
},
|
|
724
|
-
});
|
|
725
|
-
});
|
|
726
|
-
describe('type', () => {
|
|
727
|
-
runTests({
|
|
728
|
-
'input array, type remapper test': {
|
|
729
|
-
input: [
|
|
730
|
-
{ firstName: 'John', lastName: 'Doe' },
|
|
731
|
-
{ firstName: 'Jane', lastName: 'Smith' },
|
|
732
|
-
],
|
|
733
|
-
mappers: { type: null },
|
|
734
|
-
expected: 'array',
|
|
735
|
-
},
|
|
736
|
-
'input object, type remapper test': {
|
|
737
|
-
input: { firstName: 'John', lastName: 'Doe' },
|
|
738
|
-
mappers: { type: null },
|
|
739
|
-
expected: 'object',
|
|
740
|
-
},
|
|
741
|
-
'input number, type remapper test': {
|
|
742
|
-
input: 1,
|
|
743
|
-
mappers: { type: null },
|
|
744
|
-
expected: 'number',
|
|
745
|
-
},
|
|
746
|
-
'input string, type remapper test': {
|
|
747
|
-
input: 'I am a string',
|
|
748
|
-
mappers: { type: null },
|
|
749
|
-
expected: 'string',
|
|
750
|
-
},
|
|
751
|
-
'null input type remapper test': {
|
|
752
|
-
input: null,
|
|
753
|
-
mappers: { type: null },
|
|
754
|
-
expected: null,
|
|
755
|
-
},
|
|
756
|
-
'undefined input type remapper test': {
|
|
757
|
-
input: undefined,
|
|
758
|
-
mappers: { type: null },
|
|
759
|
-
expected: 'undefined',
|
|
760
|
-
},
|
|
761
|
-
});
|
|
762
|
-
});
|
|
763
|
-
describe('array.map', () => {
|
|
764
|
-
runTests({
|
|
765
|
-
'apply remappers to each array item': {
|
|
766
|
-
input: [
|
|
767
|
-
{ firstName: 'John', lastName: 'Doe' },
|
|
768
|
-
{ firstName: 'Jane', lastName: 'Smith' },
|
|
769
|
-
],
|
|
770
|
-
mappers: {
|
|
771
|
-
'array.map': [
|
|
772
|
-
{
|
|
773
|
-
'string.format': {
|
|
774
|
-
template: '{firstName} {lastName}',
|
|
775
|
-
values: {
|
|
776
|
-
firstName: { prop: 'firstName' },
|
|
777
|
-
lastName: { prop: 'lastName' },
|
|
778
|
-
},
|
|
779
|
-
},
|
|
780
|
-
},
|
|
781
|
-
{ 'string.case': 'lower' },
|
|
782
|
-
],
|
|
783
|
-
},
|
|
784
|
-
expected: ['john doe', 'jane smith'],
|
|
785
|
-
},
|
|
786
|
-
});
|
|
787
|
-
});
|
|
788
|
-
describe('array.unique', () => {
|
|
789
|
-
runTests({
|
|
790
|
-
'return the input if the input is not an array': {
|
|
791
|
-
input: { a: 1, b: 2, c: 3 },
|
|
792
|
-
mappers: [{ 'array.unique': null }],
|
|
793
|
-
expected: { a: 1, b: 2, c: 3 },
|
|
794
|
-
},
|
|
795
|
-
'filter out duplicate values using primitive values without a remapper': {
|
|
796
|
-
input: [1, 2, 2, 3],
|
|
797
|
-
mappers: [{ 'array.unique': null }],
|
|
798
|
-
expected: [1, 2, 3],
|
|
799
|
-
},
|
|
800
|
-
'filter out duplicate values using complex values without a remapper': {
|
|
801
|
-
input: [
|
|
802
|
-
{ id: 1, value: 'one' },
|
|
803
|
-
{ id: 1, value: 'one' },
|
|
804
|
-
{ id: 1, value: 'one' },
|
|
805
|
-
{ id: 2, value: 'two' },
|
|
806
|
-
],
|
|
807
|
-
mappers: [{ 'array.unique': null }],
|
|
808
|
-
expected: [
|
|
809
|
-
{ id: 1, value: 'one' },
|
|
810
|
-
{ id: 2, value: 'two' },
|
|
811
|
-
],
|
|
812
|
-
},
|
|
813
|
-
'filter out duplicate values using complex values with a remapper': {
|
|
814
|
-
input: [
|
|
815
|
-
{ id: 1, value: 'one' },
|
|
816
|
-
{ id: 1, value: 'one' },
|
|
817
|
-
{ id: 1, value: 'ONE' },
|
|
818
|
-
{ id: 2, value: 'two' },
|
|
819
|
-
],
|
|
820
|
-
mappers: [{ 'array.unique': { prop: 'value' } }],
|
|
821
|
-
expected: [
|
|
822
|
-
{ id: 1, value: 'one' },
|
|
823
|
-
{ id: 1, value: 'ONE' },
|
|
824
|
-
{ id: 2, value: 'two' },
|
|
825
|
-
],
|
|
826
|
-
},
|
|
827
|
-
});
|
|
828
|
-
});
|
|
829
|
-
describe('array.flatten', () => {
|
|
830
|
-
runTests({
|
|
831
|
-
'with unspecified depth': {
|
|
832
|
-
input: [
|
|
833
|
-
'a',
|
|
834
|
-
['b'],
|
|
835
|
-
['c', 'd'],
|
|
836
|
-
[
|
|
837
|
-
['e', 'f'],
|
|
838
|
-
['g', 'h'],
|
|
839
|
-
],
|
|
840
|
-
],
|
|
841
|
-
mappers: [{ 'array.flatten': null }],
|
|
842
|
-
expected: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'],
|
|
843
|
-
},
|
|
844
|
-
'with statically specified depth': {
|
|
845
|
-
input: [
|
|
846
|
-
'a',
|
|
847
|
-
['b'],
|
|
848
|
-
['c', 'd'],
|
|
849
|
-
[
|
|
850
|
-
['e', 'f'],
|
|
851
|
-
['g', 'h'],
|
|
852
|
-
],
|
|
853
|
-
],
|
|
854
|
-
mappers: [{ 'array.flatten': 1 }],
|
|
855
|
-
expected: ['a', 'b', 'c', 'd', ['e', 'f'], ['g', 'h']],
|
|
856
|
-
},
|
|
857
|
-
'with dynamically specified depth': {
|
|
858
|
-
input: [
|
|
859
|
-
'a',
|
|
860
|
-
['b'],
|
|
861
|
-
['c', 'd'],
|
|
862
|
-
[
|
|
863
|
-
['e', 'f'],
|
|
864
|
-
['g', 'h'],
|
|
865
|
-
],
|
|
866
|
-
],
|
|
867
|
-
mappers: [{ 'array.flatten': { 'number.parse': '1' } }],
|
|
868
|
-
expected: ['a', 'b', 'c', 'd', ['e', 'f'], ['g', 'h']],
|
|
869
|
-
},
|
|
870
|
-
'with non array input': {
|
|
871
|
-
input: 'Oops',
|
|
872
|
-
mappers: [{ 'array.flatten': null }],
|
|
873
|
-
expected: 'Oops',
|
|
874
|
-
},
|
|
875
|
-
});
|
|
876
|
-
});
|
|
877
|
-
describe('array', () => {
|
|
878
|
-
runTests({
|
|
879
|
-
'return undefined if not in the context of array.map': {
|
|
880
|
-
input: {},
|
|
881
|
-
mappers: [
|
|
882
|
-
{
|
|
883
|
-
'object.from': {
|
|
884
|
-
index: [{ array: 'index' }],
|
|
885
|
-
length: [{ array: 'length' }],
|
|
886
|
-
item: [{ array: 'item' }],
|
|
887
|
-
},
|
|
888
|
-
},
|
|
889
|
-
],
|
|
890
|
-
expected: { index: undefined, length: undefined, item: undefined },
|
|
891
|
-
},
|
|
892
|
-
'return the index, length and item if in the context of array.map': {
|
|
893
|
-
input: { array: [{ value: 'a' }, { value: 'b' }, { value: 'c' }] },
|
|
894
|
-
mappers: [
|
|
895
|
-
{ prop: 'array' },
|
|
896
|
-
{
|
|
897
|
-
'array.map': [
|
|
898
|
-
{
|
|
899
|
-
'object.from': {
|
|
900
|
-
value: [{ prop: 'value' }],
|
|
901
|
-
index: [{ array: 'index' }],
|
|
902
|
-
length: [{ array: 'length' }],
|
|
903
|
-
item: [{ array: 'item' }],
|
|
904
|
-
},
|
|
905
|
-
},
|
|
906
|
-
],
|
|
907
|
-
},
|
|
908
|
-
],
|
|
909
|
-
expected: [
|
|
910
|
-
{ value: 'a', index: 0, length: 3, item: { value: 'a' } },
|
|
911
|
-
{ value: 'b', index: 1, length: 3, item: { value: 'b' } },
|
|
912
|
-
{ value: 'c', index: 2, length: 3, item: { value: 'c' } },
|
|
913
|
-
],
|
|
914
|
-
},
|
|
915
|
-
});
|
|
916
|
-
});
|
|
917
|
-
describe('array.filter', () => {
|
|
918
|
-
runTests({
|
|
919
|
-
'return a new array containing the object with specified value from array': {
|
|
920
|
-
input: [{ name: 'Craig' }, { name: 'Joey' }, { name: 'Stuart' }],
|
|
921
|
-
mappers: [{ 'array.filter': { equals: [{ prop: 'name' }, 'Craig'] } }],
|
|
922
|
-
expected: [{ name: 'Craig' }],
|
|
923
|
-
},
|
|
924
|
-
'return a new array containing the 2 objects with specified value from array': {
|
|
925
|
-
input: [{ name: 'Craig' }, { name: 'Joey' }, { name: 'Stuart' }, { name: 'Craig' }],
|
|
926
|
-
mappers: [{ 'array.filter': { equals: [{ prop: 'name' }, 'Craig'] } }],
|
|
927
|
-
expected: [{ name: 'Craig' }, { name: 'Craig' }],
|
|
928
|
-
},
|
|
929
|
-
'return a new array containing a single value when the array does not include objects': {
|
|
930
|
-
input: ['Craig', 'Joey', 'Stuart'],
|
|
931
|
-
mappers: [{ 'array.filter': { equals: [{ array: 'item' }, 'Craig'] } }],
|
|
932
|
-
expected: ['Craig'],
|
|
933
|
-
},
|
|
934
|
-
'return an empty array when condition doesn’t match anything': {
|
|
935
|
-
input: ['Craig', 'Joey', 'Stuart'],
|
|
936
|
-
mappers: [{ 'array.filter': { equals: [{ array: 'item' }, 'Peter'] } }],
|
|
937
|
-
expected: [],
|
|
938
|
-
},
|
|
939
|
-
'it should filter arrays with mixed content type(string)': {
|
|
940
|
-
input: ['Craig', 5, 'Joey', 7, 'Stuart'],
|
|
941
|
-
mappers: [{ 'array.filter': { equals: [{ array: 'item' }, 'Stuart'] } }],
|
|
942
|
-
expected: ['Stuart'],
|
|
943
|
-
},
|
|
944
|
-
'it should filter arrays with mixed content type based on type of the item': {
|
|
945
|
-
input: ['Craig', 5, 'Joey', 7, 'Stuart'],
|
|
946
|
-
mappers: [{ 'array.filter': { equals: [{ type: { array: 'item' } }, 'number'] } }],
|
|
947
|
-
expected: [5, 7],
|
|
948
|
-
},
|
|
949
|
-
});
|
|
950
|
-
});
|
|
951
|
-
describe('array.find', () => {
|
|
952
|
-
runTests({
|
|
953
|
-
'return object with specified value from array': {
|
|
954
|
-
input: [{ name: 'Craig' }, { name: 'Joey' }, { name: 'Stuart' }],
|
|
955
|
-
mappers: [{ 'array.find': { equals: [{ prop: 'name' }, 'Craig'] } }],
|
|
956
|
-
expected: { name: 'Craig' },
|
|
957
|
-
},
|
|
958
|
-
'return undefined when condition doesn’t match anything': {
|
|
959
|
-
input: [{ name: 'Craig' }],
|
|
960
|
-
mappers: [{ 'array.find': { equals: [{ prop: 'name' }, 'foo'] } }],
|
|
961
|
-
expected: null,
|
|
962
|
-
},
|
|
963
|
-
'return single value when the array does not include objects': {
|
|
964
|
-
input: ['Craig', 'Stuart'],
|
|
965
|
-
mappers: [{ 'array.find': 'Craig' }],
|
|
966
|
-
expected: 'Craig',
|
|
967
|
-
},
|
|
968
|
-
});
|
|
969
|
-
});
|
|
970
|
-
describe('array.from', () => {
|
|
971
|
-
runTests({
|
|
972
|
-
'create new array with remapped values': {
|
|
973
|
-
input: { foo: 'bar' },
|
|
974
|
-
mappers: [{ 'array.from': [{ 'object.from': { foo: { prop: 'foo' } } }, 'baz'] }],
|
|
975
|
-
expected: [{ foo: 'bar' }, 'baz'],
|
|
976
|
-
},
|
|
977
|
-
'create empty array': {
|
|
978
|
-
input: { foo: 'bar' },
|
|
979
|
-
mappers: [{ 'array.from': [] }],
|
|
980
|
-
expected: [],
|
|
981
|
-
},
|
|
982
|
-
});
|
|
983
|
-
});
|
|
984
|
-
describe('array.append', () => {
|
|
985
|
-
runTests({
|
|
986
|
-
'append remapped value to array': {
|
|
987
|
-
input: ['baz'],
|
|
988
|
-
mappers: [{ 'array.append': [{ 'object.from': { foo: 'bar' } }] }],
|
|
989
|
-
expected: ['baz', { foo: 'bar' }],
|
|
990
|
-
},
|
|
991
|
-
'create empty array': {
|
|
992
|
-
input: { foo: 'bar' },
|
|
993
|
-
mappers: [{ 'array.append': [] }],
|
|
994
|
-
expected: [],
|
|
995
|
-
},
|
|
996
|
-
});
|
|
997
|
-
});
|
|
998
|
-
describe('array.omit', () => {
|
|
999
|
-
runTests({
|
|
1000
|
-
'omit objects at given remapped indices': {
|
|
1001
|
-
input: [{ foo: '...' }, { bar: '...' }, { baz: '...' }],
|
|
1002
|
-
mappers: [{ 'array.omit': [0, { context: 'index' }] }],
|
|
1003
|
-
expected: [{ bar: '...' }],
|
|
1004
|
-
context: { index: 2 },
|
|
1005
|
-
},
|
|
1006
|
-
'omit nothing': {
|
|
1007
|
-
input: [{ foo: '...' }, { bar: '...' }, { baz: '...' }],
|
|
1008
|
-
mappers: [{ 'array.omit': [{ static: 'index' }] }],
|
|
1009
|
-
expected: [{ foo: '...' }, { bar: '...' }, { baz: '...' }],
|
|
1010
|
-
},
|
|
1011
|
-
'create empty array': {
|
|
1012
|
-
input: { foo: 'bar' },
|
|
1013
|
-
mappers: [{ 'array.omit': [] }],
|
|
1014
|
-
expected: [],
|
|
1015
|
-
},
|
|
1016
|
-
});
|
|
1017
|
-
});
|
|
1018
|
-
describe('null.strip', () => {
|
|
1019
|
-
runTests({
|
|
1020
|
-
'strip null values': {
|
|
1021
|
-
input: { foo: null, bar: { baz: undefined }, fooz: [null, , undefined] },
|
|
1022
|
-
mappers: [{ 'null.strip': null }],
|
|
1023
|
-
expected: { bar: {}, fooz: [] },
|
|
1024
|
-
},
|
|
1025
|
-
'support depth': {
|
|
1026
|
-
input: { foo: null, bar: { baz: undefined }, fooz: [null, , undefined] },
|
|
1027
|
-
mappers: [{ 'null.strip': { depth: 1 } }],
|
|
1028
|
-
expected: { bar: { baz: undefined }, fooz: [null, , undefined] },
|
|
1029
|
-
},
|
|
1030
|
-
});
|
|
1031
|
-
});
|
|
1032
|
-
describe('prop', () => {
|
|
1033
|
-
runTests({
|
|
1034
|
-
'get a simple property': {
|
|
1035
|
-
input: { name: 'Spongebob' },
|
|
1036
|
-
mappers: { prop: 'name' },
|
|
1037
|
-
expected: 'Spongebob',
|
|
1038
|
-
},
|
|
1039
|
-
'get a nested property': {
|
|
1040
|
-
input: { address: { town: 'Bikini Bottom' } },
|
|
1041
|
-
mappers: { prop: ['address', 'town'] },
|
|
1042
|
-
expected: 'Bikini Bottom',
|
|
1043
|
-
},
|
|
1044
|
-
'get a property with a . in the key': {
|
|
1045
|
-
input: { 'address.town': 'Bikini Bottom' },
|
|
1046
|
-
mappers: { prop: 'address.town' },
|
|
1047
|
-
expected: 'Bikini Bottom',
|
|
1048
|
-
},
|
|
1049
|
-
'handle numbers': {
|
|
1050
|
-
input: { names: ['foo', 'bar'] },
|
|
1051
|
-
mappers: [{ prop: 'names' }, { prop: 0 }],
|
|
1052
|
-
expected: 'foo',
|
|
1053
|
-
},
|
|
1054
|
-
'handle a single remapper': {
|
|
1055
|
-
input: { en: 'English', nl: 'Dutch' },
|
|
1056
|
-
mappers: [{ prop: { app: 'locale' } }],
|
|
1057
|
-
expected: 'English',
|
|
1058
|
-
},
|
|
1059
|
-
'handle an array of remappers': {
|
|
1060
|
-
input: { address: { town: 'Bikini Bottom' } },
|
|
1061
|
-
mappers: [{ prop: [{ 'object.from': { prop: 'address' } }, { prop: 'prop' }] }],
|
|
1062
|
-
expected: { town: 'Bikini Bottom' },
|
|
1063
|
-
},
|
|
1064
|
-
'handle an array of remappers with numbers': {
|
|
1065
|
-
input: { languages: ['English', 'Dutch'] },
|
|
1066
|
-
mappers: [
|
|
1067
|
-
{ prop: [{ 'object.from': { prop: 'languages' } }, { prop: 'prop' }] },
|
|
1068
|
-
{ prop: 0 },
|
|
1069
|
-
],
|
|
1070
|
-
expected: 'English',
|
|
1071
|
-
},
|
|
1072
|
-
'handle null': {
|
|
1073
|
-
input: { name: 'Spongebob' },
|
|
1074
|
-
mappers: { prop: null },
|
|
1075
|
-
expected: undefined,
|
|
1076
|
-
},
|
|
1077
|
-
'handle properties named null': {
|
|
1078
|
-
input: { null: 'Spongebob' },
|
|
1079
|
-
mappers: { prop: null },
|
|
1080
|
-
expected: 'Spongebob',
|
|
1081
|
-
},
|
|
1082
|
-
'handle undefined values': {
|
|
1083
|
-
input: {},
|
|
1084
|
-
mappers: { prop: 'foo' },
|
|
1085
|
-
expected: undefined,
|
|
1086
|
-
},
|
|
1087
|
-
'handle null values': {
|
|
1088
|
-
input: { foo: null },
|
|
1089
|
-
mappers: { prop: 'foo' },
|
|
1090
|
-
expected: null,
|
|
1091
|
-
},
|
|
1092
|
-
'handle array input': {
|
|
1093
|
-
input: ['one', 'two', 'three', 'four'],
|
|
1094
|
-
mappers: { prop: 1 },
|
|
1095
|
-
expected: 'two',
|
|
1096
|
-
},
|
|
1097
|
-
'handle array input and negative index': {
|
|
1098
|
-
input: ['one', 'two', 'three', 'four'],
|
|
1099
|
-
mappers: { prop: -3 },
|
|
1100
|
-
expected: 'two',
|
|
1101
|
-
},
|
|
1102
|
-
});
|
|
1103
|
-
});
|
|
1104
|
-
describe('random.choice', () => {
|
|
1105
|
-
it('should return random entries from a list', () => {
|
|
1106
|
-
const input = [1, 2, 3, 4];
|
|
1107
|
-
const result = remap({ 'random.choice': null }, input, null);
|
|
1108
|
-
expect(input).toContain(result);
|
|
1109
|
-
});
|
|
1110
|
-
runTests({
|
|
1111
|
-
'return the input if the input is not an array': {
|
|
1112
|
-
input: { input: [1, 2, 3, 4] },
|
|
1113
|
-
mappers: [{ 'random.choice': null }],
|
|
1114
|
-
expected: { input: [1, 2, 3, 4] },
|
|
1115
|
-
},
|
|
1116
|
-
});
|
|
1117
|
-
});
|
|
1118
|
-
describe('random.integer', () => {
|
|
1119
|
-
beforeEach(() => {
|
|
1120
|
-
vi.spyOn(Math, 'random').mockReturnValue(0.5);
|
|
1121
|
-
});
|
|
1122
|
-
runTests({
|
|
1123
|
-
'return the input if the input is not an array': {
|
|
1124
|
-
input: { input: undefined },
|
|
1125
|
-
mappers: [{ 'random.integer': [5, 10] }],
|
|
1126
|
-
expected: 7,
|
|
1127
|
-
},
|
|
1128
|
-
});
|
|
1129
|
-
});
|
|
1130
|
-
describe('random.float', () => {
|
|
1131
|
-
beforeEach(() => {
|
|
1132
|
-
vi.spyOn(Math, 'random').mockReturnValue(0.5);
|
|
1133
|
-
});
|
|
1134
|
-
runTests({
|
|
1135
|
-
'return the input if the input is not an array': {
|
|
1136
|
-
input: { input: undefined },
|
|
1137
|
-
mappers: [{ 'random.float': [5, 10] }],
|
|
1138
|
-
expected: 7.5,
|
|
1139
|
-
},
|
|
1140
|
-
});
|
|
1141
|
-
});
|
|
1142
|
-
describe('random.string', () => {
|
|
1143
|
-
beforeEach(() => {
|
|
1144
|
-
vi.spyOn(Math, 'random')
|
|
1145
|
-
.mockReturnValueOnce(0)
|
|
1146
|
-
.mockReturnValueOnce(0.4)
|
|
1147
|
-
.mockReturnValueOnce(0.5)
|
|
1148
|
-
.mockReturnValueOnce(0.6)
|
|
1149
|
-
.mockReturnValueOnce(0.7)
|
|
1150
|
-
.mockReturnValueOnce(0.8)
|
|
1151
|
-
.mockReturnValueOnce(0.2)
|
|
1152
|
-
.mockReturnValueOnce(0.3)
|
|
1153
|
-
.mockReturnValueOnce(0.4)
|
|
1154
|
-
.mockReturnValueOnce(0.5)
|
|
1155
|
-
.mockReturnValueOnce(0.7)
|
|
1156
|
-
.mockReturnValueOnce(0.9)
|
|
1157
|
-
.mockReturnValueOnce(0.6);
|
|
1158
|
-
});
|
|
1159
|
-
runTests({
|
|
1160
|
-
'return the input if the input is not an array': {
|
|
1161
|
-
input: { input: undefined },
|
|
1162
|
-
mappers: [{ 'random.string': { choice: 'abcdefghijklmnopqrstuvwzyx', length: 12 } }],
|
|
1163
|
-
expected: 'aknpsufhknszp',
|
|
1164
|
-
},
|
|
1165
|
-
});
|
|
1166
|
-
});
|
|
1167
|
-
describe('root', () => {
|
|
1168
|
-
runTests({
|
|
1169
|
-
'return the root input data': {
|
|
1170
|
-
input: { input: 'data' },
|
|
1171
|
-
mappers: [{ prop: 'input' }, { root: null }],
|
|
1172
|
-
expected: { input: 'data' },
|
|
1173
|
-
},
|
|
1174
|
-
'not overwrite the root in the context': {
|
|
1175
|
-
input: { input: 'data' },
|
|
1176
|
-
mappers: [{ prop: 'input' }, { 'object.from': { key: { root: null } } }],
|
|
1177
|
-
expected: { key: { input: 'data' } },
|
|
1178
|
-
},
|
|
1179
|
-
});
|
|
1180
|
-
});
|
|
1181
|
-
describe('history', () => {
|
|
1182
|
-
runTests({
|
|
1183
|
-
'return the first history item': {
|
|
1184
|
-
input: { input: 'data' },
|
|
1185
|
-
history: [{ old: 'monke' }, { latest: 'monke' }],
|
|
1186
|
-
mappers: [{ prop: 'input' }, { history: 0 }],
|
|
1187
|
-
expected: { old: 'monke' },
|
|
1188
|
-
},
|
|
1189
|
-
});
|
|
1190
|
-
});
|
|
1191
|
-
describe('from.history', () => {
|
|
1192
|
-
runTests({
|
|
1193
|
-
'create new object with props from the second history item': {
|
|
1194
|
-
input: { input: 'data' },
|
|
1195
|
-
history: [{ old: 'monke' }, { rescue: 'monke', sadge: 'monke' }],
|
|
1196
|
-
mappers: [{ 'from.history': { index: 1, props: { happy: { prop: 'rescue' } } } }],
|
|
1197
|
-
expected: { happy: 'monke' },
|
|
1198
|
-
},
|
|
1199
|
-
});
|
|
1200
|
-
});
|
|
1201
|
-
describe('assign.history', () => {
|
|
1202
|
-
runTests({
|
|
1203
|
-
'assign the second history item props defined in prop remappers to the output': {
|
|
1204
|
-
input: { input: 'data' },
|
|
1205
|
-
history: [{ old: 'monke' }, { rescue: 'monke', sadge: 'monke' }],
|
|
1206
|
-
mappers: [{ 'assign.history': { index: 1, props: { happy: { prop: 'rescue' } } } }],
|
|
1207
|
-
expected: { input: 'data', happy: 'monke' },
|
|
1208
|
-
},
|
|
1209
|
-
});
|
|
1210
|
-
});
|
|
1211
|
-
describe('omit.history', () => {
|
|
1212
|
-
runTests({
|
|
1213
|
-
'assign the second history item props to the output except omitted props': {
|
|
1214
|
-
input: { input: 'data' },
|
|
1215
|
-
history: [{ old: 'monke' }, { rescue: 'monke', sadge: 'monke' }],
|
|
1216
|
-
mappers: [{ 'omit.history': { index: 1, keys: ['sadge'] } }],
|
|
1217
|
-
expected: { input: 'data', rescue: 'monke' },
|
|
1218
|
-
},
|
|
1219
|
-
'not assign nested omitted props': {
|
|
1220
|
-
input: { input: 'data' },
|
|
1221
|
-
history: [{ rescue: 'monke', nested: { sadge: 'monke', safe: 'monke' } }],
|
|
1222
|
-
mappers: [{ 'omit.history': { index: 0, keys: [['nested', 'sadge']] } }],
|
|
1223
|
-
expected: { input: 'data', rescue: 'monke', nested: { safe: 'monke' } },
|
|
1224
|
-
},
|
|
1225
|
-
'handle non existing properties': {
|
|
1226
|
-
input: { input: 'data' },
|
|
1227
|
-
history: [{ rescue: 'monke', nested: { happy: 'monke', safe: 'monke' } }],
|
|
1228
|
-
mappers: [{ 'omit.history': { index: 0, keys: [['nested', 'nonexistent']] } }],
|
|
1229
|
-
expected: { input: 'data', rescue: 'monke', nested: { happy: 'monke', safe: 'monke' } },
|
|
1230
|
-
},
|
|
1231
|
-
});
|
|
1232
|
-
});
|
|
1233
|
-
describe('string.case', () => {
|
|
1234
|
-
runTests({
|
|
1235
|
-
'convert a string to upper case': {
|
|
1236
|
-
input: 'I’m a Goofy Goober',
|
|
1237
|
-
mappers: { 'string.case': 'upper' },
|
|
1238
|
-
expected: 'I’M A GOOFY GOOBER',
|
|
1239
|
-
},
|
|
1240
|
-
'convert a string to lower case': {
|
|
1241
|
-
input: 'We’re all Goofy Goobers',
|
|
1242
|
-
mappers: { 'string.case': 'lower' },
|
|
1243
|
-
expected: 'we’re all goofy goobers',
|
|
1244
|
-
},
|
|
1245
|
-
});
|
|
1246
|
-
});
|
|
1247
|
-
describe('string.format', () => {
|
|
1248
|
-
runTests({
|
|
1249
|
-
'format a template string': {
|
|
1250
|
-
input: { name: 'Krusty Krab', food: 'krabby patties' },
|
|
1251
|
-
mappers: {
|
|
1252
|
-
'string.format': {
|
|
1253
|
-
template: 'The {restaurant} serves {highlight}',
|
|
1254
|
-
values: { restaurant: { prop: 'name' }, highlight: { prop: 'food' } },
|
|
1255
|
-
},
|
|
1256
|
-
},
|
|
1257
|
-
expected: 'The Krusty Krab serves krabby patties',
|
|
1258
|
-
},
|
|
1259
|
-
'escape formatting double curly brackets': {
|
|
1260
|
-
input: { food: 'krabby patty' },
|
|
1261
|
-
mappers: {
|
|
1262
|
-
'string.format': {
|
|
1263
|
-
template: "A {burger} can be ressembled in ascii using: '{{I}}'",
|
|
1264
|
-
values: { burger: { prop: 'food' } },
|
|
1265
|
-
},
|
|
1266
|
-
},
|
|
1267
|
-
expected: 'A krabby patty can be ressembled in ascii using: {{I}}',
|
|
1268
|
-
},
|
|
1269
|
-
'format unknown values to empty strings': {
|
|
1270
|
-
input: {},
|
|
1271
|
-
mappers: { 'string.format': { template: '‘{value}’ is unknown', values: {} } },
|
|
1272
|
-
expected: 'The intl string context variable "value" was not provided to the string "‘{value}’ is unknown"',
|
|
1273
|
-
},
|
|
1274
|
-
'format dates it parsed': {
|
|
1275
|
-
input: { date: '1970-01-01T00:00:00.000Z' },
|
|
1276
|
-
mappers: {
|
|
1277
|
-
'string.format': {
|
|
1278
|
-
template: 'Date’s year: {year, date, :: yyyy}',
|
|
1279
|
-
values: { year: [{ prop: 'date' }, { 'date.parse': '' }] },
|
|
1280
|
-
},
|
|
1281
|
-
},
|
|
1282
|
-
expected: 'Date’s year: 1970',
|
|
1283
|
-
},
|
|
1284
|
-
'format multilingual messages': {
|
|
1285
|
-
input: null,
|
|
1286
|
-
mappers: {
|
|
1287
|
-
'string.format': {
|
|
1288
|
-
messageId: 'patty',
|
|
1289
|
-
values: { type: 'Krabby' },
|
|
1290
|
-
},
|
|
1291
|
-
},
|
|
1292
|
-
expected: 'Krabby Patty',
|
|
1293
|
-
messages: {
|
|
1294
|
-
core: {},
|
|
1295
|
-
app: {},
|
|
1296
|
-
blocks: {},
|
|
1297
|
-
messageIds: {
|
|
1298
|
-
patty: '{type} Patty',
|
|
1299
|
-
},
|
|
1300
|
-
},
|
|
1301
|
-
},
|
|
1302
|
-
});
|
|
1303
|
-
});
|
|
1304
|
-
describe('static', () => {
|
|
1305
|
-
runTests({
|
|
1306
|
-
'return a static value': {
|
|
1307
|
-
input: null,
|
|
1308
|
-
mappers: { static: 'Hello world' },
|
|
1309
|
-
expected: 'Hello world',
|
|
1310
|
-
},
|
|
1311
|
-
'return an object': {
|
|
1312
|
-
input: null,
|
|
1313
|
-
mappers: { static: { foo: { bar: 123 } } },
|
|
1314
|
-
expected: { foo: { bar: 123 } },
|
|
1315
|
-
},
|
|
1316
|
-
'return an array': {
|
|
1317
|
-
input: null,
|
|
1318
|
-
mappers: { static: [{ foo: 123 }, 321, [1, 2, 3]] },
|
|
1319
|
-
expected: [{ foo: 123 }, 321, [1, 2, 3]],
|
|
1320
|
-
},
|
|
1321
|
-
'apply regex replacements': {
|
|
1322
|
-
input: null,
|
|
1323
|
-
mappers: [{ static: '1234 AA' }, { 'string.replace': { '\\s+': '' } }],
|
|
1324
|
-
expected: '1234AA',
|
|
1325
|
-
},
|
|
1326
|
-
});
|
|
1327
|
-
});
|
|
1328
|
-
describe('translate', () => {
|
|
1329
|
-
runTests({
|
|
1330
|
-
'format multilingual messages': {
|
|
1331
|
-
input: null,
|
|
1332
|
-
mappers: {
|
|
1333
|
-
translate: 'patty',
|
|
1334
|
-
},
|
|
1335
|
-
expected: 'Patty',
|
|
1336
|
-
messages: {
|
|
1337
|
-
core: {},
|
|
1338
|
-
app: {},
|
|
1339
|
-
blocks: {},
|
|
1340
|
-
messageIds: {
|
|
1341
|
-
patty: 'Patty',
|
|
1342
|
-
},
|
|
1343
|
-
},
|
|
1344
|
-
},
|
|
1345
|
-
'handle untranslated multilingual messages': {
|
|
1346
|
-
input: null,
|
|
1347
|
-
mappers: {
|
|
1348
|
-
translate: 'patty',
|
|
1349
|
-
},
|
|
1350
|
-
expected: '{patty}',
|
|
1351
|
-
messages: {
|
|
1352
|
-
core: {},
|
|
1353
|
-
app: {},
|
|
1354
|
-
blocks: {},
|
|
1355
|
-
messageIds: {
|
|
1356
|
-
patty: '',
|
|
1357
|
-
},
|
|
1358
|
-
},
|
|
1359
|
-
},
|
|
1360
|
-
});
|
|
1361
|
-
});
|
|
1362
|
-
describe('user', () => {
|
|
1363
|
-
runTests({
|
|
1364
|
-
'insert user info': {
|
|
1365
|
-
input: null,
|
|
1366
|
-
mappers: { 'app.member': 'name' },
|
|
1367
|
-
expected: 'Me',
|
|
1368
|
-
appMemberInfo: {
|
|
1369
|
-
sub: '1',
|
|
1370
|
-
name: 'Me',
|
|
1371
|
-
email: 'me@example.com',
|
|
1372
|
-
email_verified: true,
|
|
1373
|
-
picture: '',
|
|
1374
|
-
role: 'Member',
|
|
1375
|
-
demo: false,
|
|
1376
|
-
},
|
|
1377
|
-
},
|
|
1378
|
-
});
|
|
1379
|
-
});
|
|
1380
|
-
describe.each(Object.entries(examples))('should test remapper example: %s', (name, { input, remapper, result: expected, skip }) => {
|
|
1381
|
-
it.skipIf(skip)('to be valid.', () => {
|
|
1382
|
-
const context = createExampleContext(new URL('https://example.com'), 'en');
|
|
1383
|
-
const result = remap(remapper, input, context);
|
|
1384
|
-
expect(result).toStrictEqual(expected);
|
|
1385
|
-
});
|
|
1386
|
-
});
|
|
1387
|
-
//# sourceMappingURL=remap.test.js.map
|