@syncmatters/connector-sdk 1.0.47 → 1.0.48
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/docs/09-testing.md +98 -1
- package/package.json +3 -3
package/docs/09-testing.md
CHANGED
|
@@ -154,7 +154,8 @@ To disable those tests use `cannotTestReason` instead
|
|
|
154
154
|
non-null (and ideally CHANGED) value in the `update` payload too — see the `verifyFields`
|
|
155
155
|
contract under "What each test needs" below. Use `withIssueSimulators` /
|
|
156
156
|
`UpsertIssueSimulator` (`verifyFields`, expected issue `type` + `fatal`) to deliberately
|
|
157
|
-
exercise your `upsertClean` issue reporting.
|
|
157
|
+
exercise your `upsertClean` issue reporting. The same call may return `fieldOptions` and
|
|
158
|
+
`changeCases`, see [upsertClean: field options and change cases](#upsertclean-field-options-and-change-cases).
|
|
158
159
|
- **File fields in `upsertPrepare`.** When the object has an upsert field of `type: "file"`,
|
|
159
160
|
every `upsertPrepare` call (upsert, delete and upsertClean tests) carries `withFileField`
|
|
160
161
|
set to its path (a field with `constraints: { mandatory: "add" }` is preferred, else the
|
|
@@ -313,6 +314,102 @@ itself), never by reading the connector under test. Asserting a returned value's
|
|
|
313
314
|
the right test of a type mapping: it proves the connector's behaviour, where a metadata check
|
|
314
315
|
would only prove its declaration.
|
|
315
316
|
|
|
317
|
+
## upsertClean: field options and change cases
|
|
318
|
+
|
|
319
|
+
The upsertClean test makes one `upsertPrepare` call, with `withIssueSimulators: true` and
|
|
320
|
+
`withChangeCases: true`, and with `withUpsertFieldOptions` when the spec declares
|
|
321
|
+
`upsert.canUpsertFieldOptions` and an upsert field is tagged `canUpdateOptions` (the path of the
|
|
322
|
+
first such field). After the issue simulators it runs two more parts with what that call
|
|
323
|
+
returned, each only when its data is there:
|
|
324
|
+
|
|
325
|
+
- **Field options** (`fieldOptions`), when the spec declares `upsert.canUpsertFieldOptions`.
|
|
326
|
+
- **Change cases** (`changeCases`), when the spec has `upsert.key.path`.
|
|
327
|
+
|
|
328
|
+
Both are parts of the `upsertClean` feature, not features of their own: `--only upsertClean`
|
|
329
|
+
runs them, the first failure of any part decides the `upsertClean` status, and each part records
|
|
330
|
+
its outcome, or why it was not tested, in the `upsertClean` details. A part without data is not
|
|
331
|
+
tested and leaves `upsertClean` and the object status as they were, so an existing suite runs
|
|
332
|
+
unchanged. The test still needs `insert` and `issueSimulators` first: without them it fails as
|
|
333
|
+
before and the parts do not run. Each part adds its own row from `insert` (without `batchSize`,
|
|
334
|
+
so every call writes at once), so `insert` must not hold a value that has to be unique across
|
|
335
|
+
rows; every row the test added is passed to `upsertCleanup` once.
|
|
336
|
+
|
|
337
|
+
### Field options
|
|
338
|
+
|
|
339
|
+
`fieldOptions` gives an option field (dropdown or multi-select) a value it does not have yet.
|
|
340
|
+
The harness writes `insert` with `value` at `field` through `upsertClean`, with the field in
|
|
341
|
+
`optionFields.fixSelected`, and passes when:
|
|
342
|
+
|
|
343
|
+
1. no issue is reported for the field;
|
|
344
|
+
2. the call returns the row, holding the value (a multi-select in any order);
|
|
345
|
+
3. the object's cached metadata then lists each new option on the upsert field's `optionValues`,
|
|
346
|
+
named by its label when `labels` gives one.
|
|
347
|
+
|
|
348
|
+
The harness asserts the cached metadata because that is what the platform updates after
|
|
349
|
+
`upsertFieldOptions()`: from your `metaUpdate`, or by a metadata refresh. Reading the option back
|
|
350
|
+
from the system is connector-specific and stays a custom check, if you need it.
|
|
351
|
+
|
|
352
|
+
```js
|
|
353
|
+
/** @type {SDKTest.UpsertData} */
|
|
354
|
+
const data = {
|
|
355
|
+
insert: { properties: { name: `sm_test ${uid}`, my_dropdown: "sel_1" } },
|
|
356
|
+
issueSimulators: [/* ... */],
|
|
357
|
+
fieldOptions: {
|
|
358
|
+
// defaults to withUpsertFieldOptions: the first upsert field tagged canUpdateOptions
|
|
359
|
+
field: toJsonPath("properties.my_dropdown"),
|
|
360
|
+
// options persist: make the new id unique per run
|
|
361
|
+
value: `added_${uid}`,
|
|
362
|
+
// optional: the option's name, given to the connector and asserted on the cached option
|
|
363
|
+
labels: { [`added_${uid}`]: `Added ${uid}` },
|
|
364
|
+
},
|
|
365
|
+
};
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
`value` may be an array for a multi-select, mixing ids the field has with new ones; at least one
|
|
369
|
+
must be new, or the test fails as invalid data (`makeUid()` is unique within a run only, so add a
|
|
370
|
+
time part). Leave `labels` out where the system keeps no label apart from the id. When the
|
|
371
|
+
connector gives an added option an id of its own (`resolvedIds`), the harness finds the option by
|
|
372
|
+
its label, or by a name equal to the id sent, and expects that id on the row.
|
|
373
|
+
|
|
374
|
+
Failures: `Option field not found on object`, `Option field does not allow new options
|
|
375
|
+
(canUpdateOptions)`, `Option test data invalid, no new option value`, `Issue reported for the
|
|
376
|
+
new option`, `Row with the new option not returned`, `New option not in cached metadata`, `New
|
|
377
|
+
option label does not match`, `Returned row does not hold the new option value`, and `Test spec
|
|
378
|
+
supports upsertFieldOptions, object metadata does not` (only when the data is there).
|
|
379
|
+
`upsertFieldOptionsCannotTestReason` and `upsertFieldOptionsSameAsObjectId` skip the part.
|
|
380
|
+
|
|
381
|
+
### Change cases
|
|
382
|
+
|
|
383
|
+
`changeCases` is an ordered list of `upsertClean` calls against one row. The harness adds a row
|
|
384
|
+
from `insert`, then sends each case's `upsert` with the row key written in (at `upsert.key.path`)
|
|
385
|
+
and the current row as `current`, and checks `hasChanges` against `expectChange`. When a call
|
|
386
|
+
returns a row, that row becomes the current row for the next case. A case may pass
|
|
387
|
+
`optionFields`, and may assert values on the current row after it with `expect` (the same
|
|
388
|
+
assertions as `UpsertData.expect`).
|
|
389
|
+
|
|
390
|
+
```js
|
|
391
|
+
const fixTags = { fixSelected: [["properties", "my_tags"]] };
|
|
392
|
+
const newTag = `tag_${uid}`;
|
|
393
|
+
data.changeCases = [
|
|
394
|
+
// the values the row already has: nothing to write
|
|
395
|
+
{ upsert: { properties: { my_tags: ["opt_1", "opt_2"] } }, expectChange: false },
|
|
396
|
+
{ upsert: { properties: { my_tags: ["opt_2"] } }, expectChange: true,
|
|
397
|
+
expect: [{ path: toJsonPath("properties.my_tags"), equals: ["opt_2"] }] },
|
|
398
|
+
// a new option, added on the way, then the same values again
|
|
399
|
+
{ upsert: { properties: { my_tags: ["opt_2", newTag] } }, expectChange: true, optionFields: fixTags },
|
|
400
|
+
{ upsert: { properties: { my_tags: ["opt_2", newTag] } }, expectChange: false, optionFields: fixTags },
|
|
401
|
+
// null is skipped, an empty string clears
|
|
402
|
+
{ upsert: { properties: { my_dropdown: null } }, expectChange: false },
|
|
403
|
+
{ upsert: { properties: { my_dropdown: "" } }, expectChange: true },
|
|
404
|
+
];
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
The cases run in order and stop at the first failure: `No change reported when one expected`,
|
|
408
|
+
`Change reported when none expected`, `Changed row not returned` (a change with no row back),
|
|
409
|
+
`Issue reported by a change case` (a case must be clean data: issue simulators test issues),
|
|
410
|
+
`Expected values did not match`, or `No row returned for the change cases insert`. The detail of
|
|
411
|
+
a failure holds the case number, the upsert sent, the current row and the response.
|
|
412
|
+
|
|
316
413
|
## `query.key`: the rows' key is the field tagged as the key
|
|
317
414
|
|
|
318
415
|
[04](./04-meta-objects-fields.md) makes `isKey` a contract: the tagged query field's value
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syncmatters/connector-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.48",
|
|
4
4
|
"description": "TypeScript type definitions for the SyncMatters connector SDK (types only - connectors execute on the SyncMatters platform)",
|
|
5
5
|
"types": "./index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"author": "SyncMatters",
|
|
14
14
|
"homepage": "https://syncmatters.com",
|
|
15
|
-
"typesContentHash": "
|
|
15
|
+
"typesContentHash": "75054838bcf9f5a9e844beab3de5a6b334890a8d36a5eff283ba33a439758927",
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@types/node": "*",
|
|
18
|
-
"@syncmatters/script-api": "^1.0.
|
|
18
|
+
"@syncmatters/script-api": "^1.0.50"
|
|
19
19
|
}
|
|
20
20
|
}
|