Skip to content

test: add smoke + error-property tests, shared mock factories, connec… - #567

Merged
BigBen-7 merged 1 commit into
Lead-Studios:mainfrom
feyishola:feature/sdk-tests-and-lifecycle-docs
Aug 30, 2026
Merged

test: add smoke + error-property tests, shared mock factories, connec…#567
BigBen-7 merged 1 commit into
Lead-Studios:mainfrom
feyishola:feature/sdk-tests-and-lifecycle-docs

Conversation

@feyishola

Copy link
Copy Markdown
Contributor

closes #523
closes #524
closes #525
closes #526

test: add smoke + error-property tests, shared mock factories, connect() lifecycle docs

Adds the missing module-load and error-shape regression tests, promotes the
per-file mock boilerplate into shared factories, and documents the client
connect/disconnect lifecycle.

tests/smoke.test.ts (new)

Nothing in the suite simply imported the SDK and confirmed it loads, so a
broken re-export in src/index.ts failed at consumer runtime rather than in
CI. This imports the public barrel and asserts VeriTixClient, VeriTixError,
VeriTixErrorCode and getTestnetConfig all resolve, plus that
getTestnetConfig() returns a testnet config pointing at a soroban RPC URL.

tests/utils/errors.test.ts

VeriTixError is the primary error class and consumers pattern-match on its
shape, so the four things they rely on are now pinned: name, the
Error/VeriTixError prototype chain, code (the enum value) and message.

tests/helpers/mocks.ts

The file already existed with create* helpers; this adds the canonical
make* factories alongside them so existing call-sites keep working:

makeMockServer(overrides?) -> jest.Mocked<SorobanRpc.Server>
makeMockKeypair() -> deterministic Keypair
makeConnectedClient(keypair?) -> connected, signing-capable client
makeReadOnlyClient() -> connected client with no keypair
mockSuccessfulTransaction(server) -> PENDING send + SUCCESS confirm
mockSimulationResult(server, rv) -> simulateTransaction returning rv

Also fixes TEST_SECRET, which was an invalid strkey (55 chars, bad
checksum). Keypair.fromSecret() threw "invalid encoded string" on it, so
any helper deriving a keypair was unusable until this was corrected.

tests/client.test.ts, tests/issue-442-getLedgerInfo.test.ts

Both defined a local makeConnectedClient() that hand-rolled a mock server
and injected it via field assignment. They now build on the shared
factories and keep only what is genuinely test-specific: the per-test
ledger sequence and the mock-server handle they assert against. Pass/fail
counts are unchanged from before the migration.

src/client.ts

Documents the connect()/disconnect() lifecycle on connect(): call it once
at startup; module calls made beforehand throw VeriTixError with code
CLIENT_NOT_CONNECTED (raised by the lazy server proxy the modules hold);
reconnection is never automatic, and the only retries are the
exponential-backoff attempts within a single connect() call.

Two clarifications versus the originally proposed wording, both corrected
to match the code: connect() does NOT verify the contract exists (it only
calls getLatestLedger() -- healthCheck() is what checks the contract), and
pre-connect module calls throw CLIENT_NOT_CONNECTED, not CONNECTION_FAILED.
A mid-session RPC drop is also not detected up front -- connected stays
true, so calls fail with the underlying transport error instead.

Comment-only change; no behaviour is affected.

Notes

The smoke test immediately caught a real defect it was designed to catch:
src/index.ts re-exports EventGalleryService, which imports @nestjs/common
-- a package that is neither declared in package.json nor installed. Any
consumer importing from the package barrel hits "Cannot find module
'@nestjs/common'". The fix (add the dependency, or drop the export) is
outside the scope of this change and is not included here.

Several files on main do not currently compile due to pre-existing merge
artifacts (src/client.ts, src/client-security.ts, src/types/index.ts,
src/modules/dispute.ts, tests/recurring.test.ts, tests/escrow.test.ts,
tests/utils/network.test.ts), and src/utils/errors.ts is missing seven
entries from its error-message map. None of that is touched here. The
tests above were verified against a scratch copy with those breakages
patched; the two remaining failures in the touched files (four connect()
event tests in client.test.ts, one error-mapping test in errors.test.ts)
are pre-existing and unrelated.

…t() lifecycle docs

- tests/smoke.test.ts (new): imports the public barrel and asserts the
  headline exports resolve, so a broken re-export in src/index.ts fails in
  CI instead of at consumer runtime.
- tests/utils/errors.test.ts: pin VeriTixError's name, prototype chain,
  code and message so the property structure cannot regress.
- tests/helpers/mocks.ts: add the canonical make* factories
  (makeMockServer, makeMockKeypair, makeConnectedClient, makeReadOnlyClient,
  mockSuccessfulTransaction, mockSimulationResult). Also fixes TEST_SECRET,
  which was an invalid strkey and threw on Keypair.fromSecret().
- tests/client.test.ts, tests/issue-442-getLedgerInfo.test.ts: build their
  local helpers on the shared factories instead of duplicating the
  mock-server + field-injection boilerplate.
- src/client.ts: document the connect()/disconnect() lifecycle — when to
  call it, what module calls throw beforehand, and that reconnection is
  never automatic.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@drips-wave

drips-wave Bot commented Aug 29, 2026

Copy link
Copy Markdown

@feyishola Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@BigBen-7
BigBen-7 merged commit a95aaa6 into Lead-Studios:main Aug 30, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment