@syncmatters/connector-sdk 1.0.19 → 1.0.20
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 +166 -17
- package/docs/15-example-test-file.md +69 -3
- package/package.json +3 -3
package/docs/09-testing.md
CHANGED
|
@@ -73,7 +73,8 @@ export default class Test {
|
|
|
73
73
|
|
|
74
74
|
// prepare hooks - create/arrange the data a given test needs, return what it should expect:
|
|
75
75
|
// listPrepare, idsFilterPrepare, checkpointFilterStep1Prepare / Step2Prepare,
|
|
76
|
-
// matchFilterPrepare, relatedFilterPrepare, upsertPrepare
|
|
76
|
+
// matchFilterPrepare, relatedFilterPrepare, rowFiltersPrepare, upsertPrepare
|
|
77
|
+
// and, for what is not shaped like a feature, customChecks() (below)
|
|
77
78
|
}
|
|
78
79
|
```
|
|
79
80
|
|
|
@@ -110,10 +111,14 @@ To disable those tests use `cannotTestReason` instead
|
|
|
110
111
|
([15-example-test-file.md](./15-example-test-file.md) shows the worked semantics):
|
|
111
112
|
|
|
112
113
|
- `listPrepare` / `idsFilterPrepare` — arrange rows and return what the suite should expect.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
- `rowFiltersPrepare` — one `RowFilterData { rowFilter, expectedRowIds, fields?, expect? }` per
|
|
115
|
+
case, for the filters `meta()` declares in `queryFilter.rowFilter`. The harness queries each
|
|
116
|
+
with its `rowFilter` (and `fields`), in order, and the rows must be exactly `expectedRowIds`;
|
|
117
|
+
the first case that fails decides the object's `rowFilter` status (`Row not returned`,
|
|
118
|
+
`Returned unexpected row`, or the `expect` failures below), details under `rowFilter`. Row
|
|
119
|
+
filters have no `ObjectFeatures` flag, so a suite without the hook (or one that returns
|
|
120
|
+
`undefined`) reads `Not tested` with the reason and the object is NOT made Partial; with
|
|
121
|
+
neither the hook nor declared row filters the status is `Not supported`.
|
|
117
122
|
- `checkpointFilterStep1Prepare` / `Step2Prepare` — the two-step round-trip test of your
|
|
118
123
|
differential contract; see [Checkpoint testing](#checkpoint-testing-what-the-two-steps-prove)
|
|
119
124
|
below, it is the most-misimplemented pair.
|
|
@@ -137,7 +142,7 @@ To disable those tests use `cannotTestReason` instead
|
|
|
137
142
|
## Expected values and errors: the `expect` clause
|
|
138
143
|
|
|
139
144
|
The data every prepare hook returns (`ListData`, `IdsFilterData`, `CheckpointStep1Data`,
|
|
140
|
-
`CheckpointStep2Data`, `MatchData`, `RelationshipData`) takes an optional `expect`, for what a
|
|
145
|
+
`CheckpointStep2Data`, `MatchData`, `RelationshipData`, `RowFilterData`) takes an optional `expect`, for what a
|
|
141
146
|
row-id comparison cannot prove: that a value comes back in the right form, or that a call fails
|
|
142
147
|
the way it must.
|
|
143
148
|
|
|
@@ -212,10 +217,24 @@ succeeded, the rows it returned — is recorded in the details either way. What
|
|
|
212
217
|
| `CheckpointStep2Data` | the step 2 query, from the checkpoint step 1 emitted |
|
|
213
218
|
| `MatchData` | that match query |
|
|
214
219
|
| `RelationshipData` | the related query (the 'from' row is still fetched by `idsFilter` and must exist) |
|
|
220
|
+
| `RowFilterData` | that row-filter query |
|
|
215
221
|
|
|
216
222
|
`expectedRowIds` / `expectedMatchRowIds` / `expectedRelatedRowIds` may be empty when `error` is
|
|
217
223
|
set.
|
|
218
224
|
|
|
225
|
+
A timeout is the typical row-filter case: SQL Server's statement filter with a `WAITFOR` and a
|
|
226
|
+
`requestTimeoutOverride` shorter than the wait must fail with the driver's timeout, not hang or
|
|
227
|
+
return rows:
|
|
228
|
+
|
|
229
|
+
```js
|
|
230
|
+
/** @type {SDKTest.RowFilterData} */
|
|
231
|
+
const timeoutCase = {
|
|
232
|
+
rowFilter: { where: { clause: "1 = 1; WAITFOR DELAY '00:00:05'" }, requestTimeoutOverride: 1000 },
|
|
233
|
+
expectedRowIds: [],
|
|
234
|
+
expect: { error: { code: "ETIMEOUT" } },
|
|
235
|
+
};
|
|
236
|
+
```
|
|
237
|
+
|
|
219
238
|
**Upsert**: `UpsertData.expect` is `{ insert?, update? }`, each an assertion list for this
|
|
220
239
|
data's own row as queried back after that phase. `upsertPrepare` runs once per row, and the
|
|
221
240
|
row's key is only assigned by the insert, so there is nothing to key by. The asserted paths are
|
|
@@ -263,6 +282,59 @@ This catches a connector that keys its rows on one column and tags another, whic
|
|
|
263
282
|
only a sync finds. A spec without `query.key` (anything generated before it existed) skips
|
|
264
283
|
these checks.
|
|
265
284
|
|
|
285
|
+
## Custom checks: `customChecks()`
|
|
286
|
+
|
|
287
|
+
Some tests are not shaped like an object feature: a free statement with typed parameters,
|
|
288
|
+
500 sequential statements to prove connections are released, a connection-level timeout, an API
|
|
289
|
+
quirk. They go in `customChecks()`, which returns named checks the harness runs **after the
|
|
290
|
+
feature tests, in declaration order**, each with its own status, duration and details:
|
|
291
|
+
|
|
292
|
+
```js
|
|
293
|
+
/** @type {SDKTest.TestFeatureProvider["customChecks"]} */
|
|
294
|
+
async customChecks() {
|
|
295
|
+
return [
|
|
296
|
+
{
|
|
297
|
+
id: "exec-typed-parameters", // stable: keys the result and details, and is what --check names
|
|
298
|
+
name: "$Exec binds typed parameters",
|
|
299
|
+
objectId: "$Exec", // gated like a feature; omit for a connection-level check
|
|
300
|
+
timeoutMs: 30000, // default 60 000
|
|
301
|
+
run: async ({ connection, meta, record }) => {
|
|
302
|
+
const rows = await collect(connection.query["$Exec"]({ rowFilter: { statement: "SELECT @p0 AS v", parameters: [{ name: "p0", sqlType: "int", value: 42 }] } }));
|
|
303
|
+
record("returned", { rows }); // a detail on the check, under the usual caps
|
|
304
|
+
if (rows[0]?.data.v !== 42) throw new Error(`expected 42, got ${rows[0]?.data.v}`);
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
];
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
- **Status**: `Passed`, `Failed: <message>` (the first line of what `run` threw; the full error
|
|
312
|
+
is kept as the check's `fatalError`), or `Not tested` with `notTestedReason`. Results are
|
|
313
|
+
`CustomCheckResult { id, name, status, notTestedReason?, durationMs, fatalError? }`, on the
|
|
314
|
+
object's result for a check with an `objectId` and on the run's for one without.
|
|
315
|
+
- **Details**: `record(message, data)` adds a detail under `details["check:<id>"]`; the harness
|
|
316
|
+
adds one saying how the check ended. Same caps and ~48-hour retention as every feature's.
|
|
317
|
+
- **Selection**: a check with an `objectId` whose object is not on the connection (not selected
|
|
318
|
+
on a two-phase connection, or not returned by `meta()`) reads `Not tested` with the reason —
|
|
319
|
+
it does not fail. The object need not be one of `objectIds()`; if it is, the harness's object
|
|
320
|
+
check fails the run first, as it does for any tested object. A check without an `objectId` is
|
|
321
|
+
connection-level and always runs. `ctx.meta` is the check object's metadata.
|
|
322
|
+
- **Timeout**: `timeoutMs` (default 60 000) is capped at the run's remaining budget when the run
|
|
323
|
+
has one. A check still running at its timeout fails (`Failed: Timed out after <n>ms`), what it
|
|
324
|
+
records afterwards is dropped, and the next check runs.
|
|
325
|
+
- **Roll-up**: a failed check fails its object and the run; a check not tested makes a Passed
|
|
326
|
+
object Partial and keeps a run that would pass at `Partial: Not all features/objects can be
|
|
327
|
+
tested`.
|
|
328
|
+
- **Which checks a run reaches**: all of them on a full run; with `--object`, the
|
|
329
|
+
connection-level checks plus the selected objects'; none with `--only
|
|
330
|
+
connection|meta|discover|query`; exactly the named ones with `--check <id>` (repeatable),
|
|
331
|
+
whatever else the run tests. An id the suite does not declare fails as `No such check in the
|
|
332
|
+
test suite`.
|
|
333
|
+
|
|
334
|
+
A check is the escape hatch, not the default. If the same check turns up in a second connector,
|
|
335
|
+
it belongs in the harness as a feature; and a value assertion on rows a feature already fetches
|
|
336
|
+
belongs in that feature's `expect`, where it reports on the feature.
|
|
337
|
+
|
|
266
338
|
## Fixtures on two-phase connections: fixed names, seeded in `before()`
|
|
267
339
|
|
|
268
340
|
A two-phase test connection collects only the objects it selected. So a fixture object — a
|
|
@@ -274,7 +346,7 @@ connection right after it.
|
|
|
274
346
|
The procedure:
|
|
275
347
|
|
|
276
348
|
1. Create the fixtures once, with fixed names (the SQLServer suite's `dbo.sm_test_*` pattern).
|
|
277
|
-
2. Run `sm test --only discover`.
|
|
349
|
+
2. Run `sm connector test --only discover`.
|
|
278
350
|
3. Select the fixtures on the test connection.
|
|
279
351
|
4. Run the suite.
|
|
280
352
|
|
|
@@ -406,25 +478,31 @@ The harness always executes platform-side. What each entry point actually runs:
|
|
|
406
478
|
|
|
407
479
|
| Command | What runs |
|
|
408
480
|
| ---------------------------- | ----------------------------------------------------------------------------------------------- |
|
|
409
|
-
| `sm test` | The FULL suite — `connection.test()` + `metaRefresh()` + every object feature above. Identical to the web UI's connector test. |
|
|
410
|
-
| `sm test --only connection` | `connection.test()` only — credentials check, nothing else. The harness has NOT run. |
|
|
411
|
-
| `sm test --only meta` | `connection.metaRefresh()` only — for a connection with a selection, that is `meta()` over the selected objects. |
|
|
412
|
-
| `sm test --only discover` | `connection.discover()` only (two-phase connectors) — reports the catalogue size, which settings it returned overrides for, and how long it took, then refreshes the selection and checks every selected object is in the catalogue. |
|
|
413
|
-
| `sm test --only query` | Every object's plain list query only — no ids/checkpoint/match/related, no writes.
|
|
481
|
+
| `sm connector test` | The FULL suite — `connection.test()` + `metaRefresh()` + every object feature above + every custom check. Identical to the web UI's connector test. |
|
|
482
|
+
| `sm connector test --only connection` | `connection.test()` only — credentials check, nothing else. The harness has NOT run. |
|
|
483
|
+
| `sm connector test --only meta` | `connection.metaRefresh()` only — for a connection with a selection, that is `meta()` over the selected objects. |
|
|
484
|
+
| `sm connector test --only discover` | `connection.discover()` only (two-phase connectors) — reports the catalogue size, which settings it returned overrides for, and how long it took, then refreshes the selection and checks every selected object is in the catalogue. |
|
|
485
|
+
| `sm connector test --only query` | Every object's plain list query only — no ids/checkpoint/match/related, no writes, no custom checks. |
|
|
486
|
+
| `sm connector test --object <id>` | The full suite for the named object(s), plus the connection-level custom checks and those object(s)' checks. |
|
|
487
|
+
| `sm connector test --check <id>` | Only the named custom check(s) (repeat the flag); no object features unless `--object` is given too. The fast loop for one failing check. |
|
|
414
488
|
| Web UI (connector → test results → run) | Same engine, feature selection via the run dialog. |
|
|
415
489
|
|
|
490
|
+
(The old short name `sm test` now prints the replacement and exits 2.)
|
|
491
|
+
|
|
416
492
|
Each feature test records the inputs it ran with and what the connector returned — pass or
|
|
417
493
|
fail — onto the saved result as diagnostic `details` (the ids an `idsFilter` ran with and the
|
|
418
|
-
rows returned; expected vs actual rows per match rule / relationship; upserted rows
|
|
419
|
-
query-back
|
|
494
|
+
rows returned; expected vs actual rows per match rule / relationship / row filter; upserted rows
|
|
495
|
+
and their query-back; what each custom check recorded). The web UI shows custom checks in a
|
|
496
|
+
"Custom checks" table under each object and under the connection, and `sm connector test`
|
|
497
|
+
prints one line per check after the object lines. Review them on the web UI's test results screen instead of re-running with extra
|
|
420
498
|
logging. Payloads over the size budget are dropped and flagged `truncated`; details hold real
|
|
421
499
|
connection data and are scrubbed ~48 hours after the run (statuses are kept).
|
|
422
500
|
|
|
423
501
|
Do not mistake a passing `--only connection` or `--only query` for suite coverage — only the
|
|
424
|
-
full run exercises the prepare hooks and write features. `sm test` needs a developer token
|
|
502
|
+
full run exercises the prepare hooks and write features. `sm connector test` needs a developer token
|
|
425
503
|
with the `scripts:read`, `connections:read` and `scripts:execute` scopes; a 403 from the CLI
|
|
426
504
|
names the missing one. The dev loop around it: `sm validate` (workspace structure), `checkJs`
|
|
427
|
-
type checking against the SDK types, `sm push`, then `sm test`. Keep `test()` cheap and
|
|
505
|
+
type checking against the SDK types, `sm push`, then `sm connector test`. Keep `test()` cheap and
|
|
428
506
|
`meta()` deterministic so the suite stays fast.
|
|
429
507
|
|
|
430
508
|
Three workspace facts that bite here:
|
|
@@ -442,8 +520,79 @@ Three workspace facts that bite here:
|
|
|
442
520
|
`sm connector features` (or the web UI's feature-generate action) after `meta()` changes;
|
|
443
521
|
new relationships/match rules will NOT be tested until you do, because the generated
|
|
444
522
|
`relationshipsTo`/`matchRules` spec still reflects the old metadata. The loop is:
|
|
445
|
-
edit `meta()` → `sm push` → `sm connector features` → `sm test`.
|
|
523
|
+
edit `meta()` → `sm push` → `sm connector features` → `sm connector test`.
|
|
446
524
|
- The typed test connection (the `API.connections.<connection_name>.Connection` `@typedef` in
|
|
447
525
|
the `mod Test.mjs` example above) resolves from **generated** typings:
|
|
448
526
|
`types/connections/*.d.ts` in a CLI workspace (`sm types` refreshes them; `sm pull` runs it
|
|
449
527
|
automatically) — never hand-write these.
|
|
528
|
+
|
|
529
|
+
## Migrating an old test module to `mod Test.mjs`
|
|
530
|
+
|
|
531
|
+
Many connectors still carry a second suite in `files/Scripts/Tests/mod <Conn>.mjs`, run by the
|
|
532
|
+
loop in `_tst Connector.mjs`: every `test*` method is called, logged as Success or Fail, and the
|
|
533
|
+
run throws at the end. The harness replaces it. Port each method to the first of these that
|
|
534
|
+
fits, and delete the old module and its `_tst` entry when the last method has moved:
|
|
535
|
+
|
|
536
|
+
1. **An existing feature.** Most methods (list, by id, by ids, by last-modified, match rules,
|
|
537
|
+
related rows, insert/update, the `test_*_metadata` methods) are already what the harness
|
|
538
|
+
tests. Port them as prepare data (`listPrepare`, `idsFilterPrepare`, ...), not as checks;
|
|
539
|
+
metadata methods are covered by the generated spec and the `fieldMetadata` feature.
|
|
540
|
+
2. **An `expect` clause.** A method that checks a returned value's form (a rowversion as hex, a
|
|
541
|
+
GUID, a decimal's value, a column that must not be echoed) or a call that must fail (a
|
|
542
|
+
timeout, a rejected id, a `*_not_exist` query) becomes `expect.rows` or `expect.error` on the
|
|
543
|
+
feature data that makes that call.
|
|
544
|
+
3. **A custom check**, for what is left: a method that is not shaped like a feature.
|
|
545
|
+
|
|
546
|
+
Porting a method to a custom check:
|
|
547
|
+
|
|
548
|
+
```js
|
|
549
|
+
// old: files/Scripts/Tests/mod SQLServer v2.mjs
|
|
550
|
+
async testExec() {
|
|
551
|
+
const rows = await collect(this.conn.query["$Exec"]({ rowFilter: { statement: "SELECT 1 AS one" } }));
|
|
552
|
+
if (rows[0].data.one !== 1) throw new Error("exec did not return 1");
|
|
553
|
+
this.log.info("exec ok");
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// new: in mod Test.mjs
|
|
557
|
+
async customChecks() {
|
|
558
|
+
return [
|
|
559
|
+
{
|
|
560
|
+
id: "exec",
|
|
561
|
+
name: "$Exec returns a statement's rows",
|
|
562
|
+
objectId: "$Exec",
|
|
563
|
+
run: async ({ connection, record }) => {
|
|
564
|
+
const rows = await collect(connection.query["$Exec"]({ rowFilter: { statement: "SELECT 1 AS one" } }));
|
|
565
|
+
record("returned", { rows });
|
|
566
|
+
if (rows[0]?.data.one !== 1) throw new Error(`exec returned ${JSON.stringify(rows[0]?.data)}`);
|
|
567
|
+
},
|
|
568
|
+
},
|
|
569
|
+
];
|
|
570
|
+
}
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
- The method body moves into `run`; `this.conn` becomes `ctx.connection` (or the suite's own
|
|
574
|
+
typed connection from `before()`), `this.log.info` of what you want to review later becomes
|
|
575
|
+
`ctx.record`, and the `throw` stays: throwing is how a check fails.
|
|
576
|
+
- Give it a stable `id` (the old method name without `test` is a good one) and, when it
|
|
577
|
+
exercises one object, that `objectId`, so an unselected object reads Not tested instead of
|
|
578
|
+
failing.
|
|
579
|
+
- `onlyTest*` / `skipTest*` renames are gone: `--check <id>` runs one check, and a check that
|
|
580
|
+
must not run is deleted or given a reason in its own code, not renamed.
|
|
581
|
+
- A method that loops or times (500 sequential statements, a large read) keeps its loop; put
|
|
582
|
+
the timing in `record`, not in a pass/fail threshold, and set `timeoutMs` above what it needs.
|
|
583
|
+
- Setup the old module did in its constructor or `before()` moves to the suite's `before()`,
|
|
584
|
+
which runs once for features and checks alike. **Seed rows there, never objects**.
|
|
585
|
+
|
|
586
|
+
What cannot be ported:
|
|
587
|
+
|
|
588
|
+
- **Creating a table, custom object or other schema per test** (the `SMTST<random>` pattern).
|
|
589
|
+
A two-phase test connection only collects the objects it selected, so an object made during
|
|
590
|
+
the run is never on it. Use a fixed fixture instead ([above](#fixtures-on-two-phase-connections-fixed-names-seeded-in-before)):
|
|
591
|
+
create it once with a fixed name, discover, select it, and let the check or feature seed rows.
|
|
592
|
+
Tests that only prove "a table can be created" go.
|
|
593
|
+
- **Anything whose pass/fail is a timing threshold.** A threshold needs a per-environment budget
|
|
594
|
+
the harness does not have; record the timing as a detail instead.
|
|
595
|
+
- **Methods that depend on another method having run first.** Checks run in declaration order,
|
|
596
|
+
but each must stand alone (a `--check` run may run only one); share state through `before()`.
|
|
597
|
+
- **Platform tests** (`mod ScriptAPI`, `Storage`, `Webhook`, `Drives`, ...) are not connector
|
|
598
|
+
tests and stay where they are, with `_tst Main.mjs`.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The test-file counterpart to [12-example-connector.md](./12-example-connector.md): the complete
|
|
4
4
|
`mod Test.mjs` + `mod ObjectTestFeatures.mjs` pair for the Acme connector, on one page. The
|
|
5
|
-
platform's connector test suite AND the CLI's `sm test` both require a file of sidecar
|
|
5
|
+
platform's connector test suite AND the CLI's `sm connector test` both require a file of sidecar
|
|
6
6
|
type `"connectortest"` in the connector's folder — **a connector without one cannot be
|
|
7
7
|
run-tested at all**. Harness conventions and hook semantics live in
|
|
8
8
|
[09-testing.md](./09-testing.md); this page shows them applied end to end against Acme's three
|
|
@@ -39,7 +39,7 @@ generated module via `module_script_file_paths`:
|
|
|
39
39
|
}
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
Keep exactly one `"connectortest"` file per connector folder — `sm test` resolves the test
|
|
42
|
+
Keep exactly one `"connectortest"` file per connector folder — `sm connector test` resolves the test
|
|
43
43
|
module from the folder beside the connector's entry file, and several candidates are ambiguous
|
|
44
44
|
(`<Name>.test.mjs` wins when present).
|
|
45
45
|
|
|
@@ -180,6 +180,8 @@ export default class TestFeatureProvider {
|
|
|
180
180
|
#connection;
|
|
181
181
|
/** @type string */
|
|
182
182
|
#fixtureCompanyId = ""; // shared parent row for contact test data
|
|
183
|
+
/** @type string */
|
|
184
|
+
#fixtureVendorId = ""; // the sandbox's one vendor company, for the companyType row filter
|
|
183
185
|
|
|
184
186
|
/** @type SDKTest.TestFeatureProvider["before"] */
|
|
185
187
|
async before(ctx) {
|
|
@@ -213,6 +215,10 @@ export default class TestFeatureProvider {
|
|
|
213
215
|
const company = await this.#connection.queryOne.companies();
|
|
214
216
|
if (!company) throw new Error("Sandbox has no companies - seed at least one before testing");
|
|
215
217
|
this.#fixtureCompanyId = company.meta.key;
|
|
218
|
+
for await (const row of this.#connection.query.companies()) {
|
|
219
|
+
if (row.data.name === "sm_fixture Vendor") this.#fixtureVendorId = row.meta.key;
|
|
220
|
+
}
|
|
221
|
+
if (!this.#fixtureVendorId) throw new Error("Sandbox fixture 'sm_fixture Vendor' is missing - create it once as a vendor");
|
|
216
222
|
}
|
|
217
223
|
|
|
218
224
|
/** @type SDKTest.TestFeatureProvider["after"] */
|
|
@@ -494,6 +500,57 @@ export default class TestFeatureProvider {
|
|
|
494
500
|
await this.#deleteRows(options.meta.id, options.inserted.map((r) => r.meta.key));
|
|
495
501
|
}
|
|
496
502
|
|
|
503
|
+
/** @type SDKTest.TestFeatureProvider["rowFiltersPrepare"] */
|
|
504
|
+
async rowFiltersPrepare(options) {
|
|
505
|
+
// companies declares one row filter, companyType (12). Acme's API cannot set a company's
|
|
506
|
+
// type, so the sandbox holds a fixed fixture instead: exactly one vendor, named
|
|
507
|
+
// "sm_fixture Vendor", created once and never touched by the suite (the fixed-fixture rule, 09).
|
|
508
|
+
// before() looked its key up; every other sandbox company is a customer.
|
|
509
|
+
if (options.meta.id !== "companies") return undefined;
|
|
510
|
+
return [
|
|
511
|
+
{
|
|
512
|
+
rowFilter: { companyType: "vendor" },
|
|
513
|
+
expectedRowIds: [this.#fixtureVendorId],
|
|
514
|
+
expect: { rows: { "*": [{ path: [{ path: "name" }], equals: "sm_fixture Vendor" }] } },
|
|
515
|
+
},
|
|
516
|
+
];
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/** @type SDKTest.TestFeatureProvider["customChecks"] */
|
|
520
|
+
async customChecks() {
|
|
521
|
+
// what is not shaped like an object feature; each check reports its own status (09)
|
|
522
|
+
return [
|
|
523
|
+
{
|
|
524
|
+
// connection-level (no objectId): always runs
|
|
525
|
+
id: "sequential-tests",
|
|
526
|
+
name: "20 sequential test() calls all succeed",
|
|
527
|
+
run: async ({ record }) => {
|
|
528
|
+
const started = Date.now();
|
|
529
|
+
for (let i = 0; i < 20; i++) {
|
|
530
|
+
const result = await this.#connection.test();
|
|
531
|
+
if (!result.success) throw new Error(`test() call ${i + 1} failed: ${result.message}`);
|
|
532
|
+
}
|
|
533
|
+
record("20 test() calls", { durationMs: Date.now() - started }); // timing is a detail, not a threshold
|
|
534
|
+
},
|
|
535
|
+
},
|
|
536
|
+
{
|
|
537
|
+
// object-level: reads Not tested, not Failed, if contacts is not selected on the connection
|
|
538
|
+
id: "contacts-page-walk",
|
|
539
|
+
name: "Listing three pages of contacts returns no duplicate keys",
|
|
540
|
+
objectId: "contacts",
|
|
541
|
+
timeoutMs: 120000,
|
|
542
|
+
run: async ({ record }) => {
|
|
543
|
+
const seen = new Set();
|
|
544
|
+
for await (const row of this.#connection.query.contacts({ limit: 300 })) {
|
|
545
|
+
if (seen.has(row.meta.key)) throw new Error(`key ${row.meta.key} returned twice`);
|
|
546
|
+
seen.add(row.meta.key);
|
|
547
|
+
}
|
|
548
|
+
record(`${seen.size} distinct contacts`);
|
|
549
|
+
},
|
|
550
|
+
},
|
|
551
|
+
];
|
|
552
|
+
}
|
|
553
|
+
|
|
497
554
|
// === private helpers ======================================================
|
|
498
555
|
|
|
499
556
|
/** Create one prefixed row; creating counts as a modification for checkpoint tests.
|
|
@@ -570,7 +627,7 @@ Nothing in this pair changes when a connector gains `discover()`
|
|
|
570
627
|
regenerates `mod ObjectTestFeatures.mjs` without it — it warns about the catalogue entries the
|
|
571
628
|
connection did not select, so read that output rather than assuming a shrunken generated file is
|
|
572
629
|
the connector's doing. Widen the test connection's selection rather than scoping the object out;
|
|
573
|
-
`sm test --only discover` ([09](./09-testing.md#running-the-suite)) checks the catalogue against
|
|
630
|
+
`sm connector test --only discover` ([09](./09-testing.md#running-the-suite)) checks the catalogue against
|
|
574
631
|
the selection and prints what is missing.
|
|
575
632
|
|
|
576
633
|
The same rule applies to fixture objects a suite owns, such as a sandbox table or a custom
|
|
@@ -633,3 +690,12 @@ async before({ connection }) {
|
|
|
633
690
|
10. **`query.key` is generated, like `upsert.key`.** It names the field whose value IS
|
|
634
691
|
`row.meta.key`, and the list and idsFilter tests check every row against it. If the
|
|
635
692
|
generated file lacks it, it predates the check: regenerate.
|
|
693
|
+
11. **Row filters are tested from a fixed fixture.** `rowFiltersPrepare` has to name the exact
|
|
694
|
+
rows a filter returns, so it needs a sandbox whose answer it knows: here one vendor company
|
|
695
|
+
created once and looked up in `before()`, never created by the run. Without the hook
|
|
696
|
+
companies' row filter reads `Not tested`, which does not make the object Partial.
|
|
697
|
+
12. **Custom checks are for what no feature expresses**, and each reports on its own:
|
|
698
|
+
`sequential-tests` on the connection, `contacts-page-walk` under contacts (Not tested, not
|
|
699
|
+
Failed, if contacts is not selected). Throwing fails a check; `record` puts what you want to
|
|
700
|
+
review later on the result; timings are details, never thresholds. Rerun one with
|
|
701
|
+
`sm connector test Acme --check contacts-page-walk`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syncmatters/connector-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.20",
|
|
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": "376c97b772af51a69f5155aff7c80362062a74710e0672b3dd0582679b5cfffb",
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@types/node": "*",
|
|
18
|
-
"@syncmatters/script-api": "^1.0.
|
|
18
|
+
"@syncmatters/script-api": "^1.0.21"
|
|
19
19
|
}
|
|
20
20
|
}
|