@syncmatters/connector-sdk 1.0.46 → 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.
Files changed (2) hide show
  1. package/docs/09-testing.md +118 -2
  2. package/package.json +3 -3
@@ -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
@@ -204,6 +205,24 @@ const idsFilterData = {
204
205
  };
205
206
  ```
206
207
 
208
+ **`noRows: true`** says the query must succeed and return nothing: an unknown id that reads as
209
+ "not found" rather than an error, a filter or match that finds nothing, a parent without
210
+ children, a checkpoint with nothing newer. Row filters, match rules, related filters and
211
+ checkpoint step 2 honour it. Without it an empty expected id list is still rejected as invalid
212
+ test data, so a prepare hook that found nothing by accident cannot pass; with it the list must
213
+ be empty.
214
+
215
+ ```js
216
+ /** @type {SDKTest.RowFilterData} */
217
+ const unknownId = { rowFilter: { id: "999999999" }, expectedRowIds: [], expect: { noRows: true } };
218
+
219
+ /** @type {SDKTest.CheckpointStep2Data} - a quiet sandbox: nothing changed since the emitted checkpoint */
220
+ const step2 = { expectedRowIds: [], expect: { noRows: true } };
221
+ ```
222
+
223
+ Do not set `noRows` because a prepare hook's own query came back empty: state it only where the
224
+ suite knows the answer is "nothing" (an id it made up, a row it did not change).
225
+
207
226
  **`rows`** maps a row's `meta.key` (or `"*"` for every row) to assertions on `row.data` by path.
208
227
  Each assertion is one of:
209
228
 
@@ -295,6 +314,102 @@ itself), never by reading the connector under test. Asserting a returned value's
295
314
  the right test of a type mapping: it proves the connector's behaviour, where a metadata check
296
315
  would only prove its declaration.
297
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
+
298
413
  ## `query.key`: the rows' key is the field tagged as the key
299
414
 
300
415
  [04](./04-meta-objects-fields.md) makes `isKey` a contract: the tagged query field's value
@@ -539,7 +654,8 @@ Requirements that only surface as cryptic failures when unmet:
539
654
  normalizes or formats. And return the SAME `verifyFields` paths from both prepare calls:
540
655
  the harness reads row 2's values through call 1's paths.
541
656
  - **relatedFilterPrepare needs a declaring-object row that actually has related rows** —
542
- `expectedRelatedRowIds` must be non-empty. In the parent-owns-children shape that means a
657
+ `expectedRelatedRowIds` must be non-empty (a case that proves "this parent has no children"
658
+ says so with `expect: { noRows: true }`). In the parent-owns-children shape that means a
543
659
  parent with at least one child in the sandbox (create one in `before()` when the API allows;
544
660
  otherwise seed the sandbox account once and document it in the test file).
545
661
  - **Checkpoint step 2 does not have to create data** — see
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncmatters/connector-sdk",
3
- "version": "1.0.46",
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": "68b1eba052b8a26ee11cdecc81796e2f921819c36e808a2a091bf7d6e9def32b",
15
+ "typesContentHash": "75054838bcf9f5a9e844beab3de5a6b334890a8d36a5eff283ba33a439758927",
16
16
  "dependencies": {
17
17
  "@types/node": "*",
18
- "@syncmatters/script-api": "^1.0.48"
18
+ "@syncmatters/script-api": "^1.0.50"
19
19
  }
20
20
  }