Repository navigation
Resolve #230, #231, #233, #237: event poller ingestion and test coverage - #307
Merged
Tybravo merged 2 commits intoOct 21, 2026
Merged
Conversation
…ainn#237: tests and event poller ingestion SwiftChainn#230: add repository tests for NotificationPreferenceRepository covering findOrCreate defaults, cross-user device detach on registerDevice, idempotent re-registration, removeDevice scoping and pruneTokens. SwiftChainn#231: add an integration suite for the fleet routes (member add/remove rules, treasury validation, fleet lookup, invite -> accept -> metrics and invite -> decline). Repair the existing fleet suite fixtures, which were written against an older model (no treasuryAddress, businessMetadata or members) and could not pass against the current API. SwiftChainn#233: add unit tests for ProofOfDeliveryService covering the MIME allow-list, the size cap, the upload flow and metadata, assigned-driver authorization, delivery state checks, lookups and the assertProofOfDeliveryExists guard. SwiftChainn#237: replace the event poller stub with a getEvents ingestion loop. Each cycle pages through escrow_funded events from the checkpoint, records them in EventLog (deduplicated on transactionHash and eventType), dispatches them to the matching handler, marks handler failures as failed with errorMessage, and advances IndexerStatus.lastProcessedLedger. Supporting fixes: - src/routes/delivery.routes.ts: the fee-estimate route called an undefined validate(); it now uses the validateRequest import. This made app.ts fail to load, which broke every suite that imports it. - src/controllers/fleetController.ts: enforce the documented Stellar public-key format for treasury addresses and reject a duplicate fleet name for the same owner with 409. Docs: indexer reference and architecture notes now describe the implemented poller; TODO.md updated.
…hainn#233) Add an integration test that runs releaseEscrow against the real escrow and proof-of-delivery services. It covers a release rejected with 422 when no proof is on record, a release that completes the delivery once proof is uploaded, and a release rejected again after the proof is removed. The existing escrow E2E suite mocks the whole proof-of-delivery service, so it could not exercise this guard.
|
@Vera-Auth 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! 🚀 |
Collaborator
|
Thank you for contributing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR resolves four issues in one change set: three test-coverage issues and one indexer feature. The feature is the event poller, which was a stub.
Commit:
f2deed3(author and committer Vera-Auth).Implementation by issue
#230 NotificationPreferenceRepository tests
File:
tests/notificationPreferenceRepository.test.ts. Runs against in-memory MongoDB, so the uniquedevices.tokenindex is exercised for real.findOrCreateByUserIdcreates defaults on first call and returns the same document afterwards.registerDeviceattaches a token and detaches it from the previous owner.removeDeviceremoves only the given token.pruneTokensremoves the listed tokens across users, returns the modified count, and does nothing for an empty list.Note on the issue text: #230 says
pruneTokensremoves stale tokens "based onlastSeenAt". The implementation takes an explicit token list and never readslastSeenAt. The tests cover the real behaviour. If age-based pruning is wanted, it is a separate change.#231 Fleet routes integration tests
Files:
tests/integration/fleetRoutes.test.ts(new, 23 tests) andtests/fleet.test.ts(existing suite, fixtures repaired).The existing
tests/fleet.test.tscould not pass against the current API. Its fixtures omittedtreasuryAddressandbusinessMetadata, which the controller and model require, and some used adriversfield the setup did not populate. Its metrics expectation also lackedtotalEscrowValueAsset. Those fixtures are repaired, and the suite is green (32/32).Behaviour added to the controller, because the issue and the docs call for it:
POST /api/v1/fleetsnow rejects a treasury address that does not match^G[A-Z0-9]{55}$(docs/fleet.md) with 400. Before this change any non-empty string was accepted.POST /api/v1/fleetsreturns 409 when the same owner already has a fleet with the same name. The service layer already had this check, but the route did not call the service.Both are behaviour changes. Clients that send non-Stellar treasury addresses, or repeat a fleet name, will now get 400 or 409.
#233 ProofOfDeliveryService unit tests
File:
tests/proofOfDeliveryService.test.ts. Real Delivery documents on in-memory MongoDB. Only the storage driver is mocked.Covers the MIME allow-list (accepted and rejected types), the size cap (exact limit and one byte over), stored metadata and the storage key, assigned-driver authorization, 409 for completed and cancelled deliveries, 400 and 404 lookups, and the
assertProofOfDeliveryExistsguard (passes with proof, 422 without).Not covered here, and tracked as follow-ups below: the escrow release path that calls the guard (
escrow.service.ts), and the admin role check.#237 Event poller ingestion
Files:
src/services/eventPoller.ts(rewritten),tests/eventPoller.test.ts(new, 12 tests),backend/docs/indexer.md,docs/architecture.md,TODO.md.Each cycle:
IndexerStatuscheckpoint forSTELLAR_NETWORKand callsgetLatestLedger().getEvents()from the ledger after the checkpoint, filtered on the escrow funded topic. It stops at the first empty page, which avoids stopping early when the RPC caps the page size.EventLogand dispatches it tohandleEscrowFundedEvent. Dedupe uses the existing unique index on{transactionHash, eventType}. A record alreadyprocessedorfailedis skipped. A record leftpendingby an interrupted cycle is processed again.failedwitherrorMessage. The checkpoint still advances.IndexerStatus.lastProcessedLedgerto the synced ledger. RPC or database errors leave it unchanged.startEventPoller()andstopEventPoller()keep their signatures, soserver.tsand the graceful-shutdown service need no change. The poller does not start whenESCROW_CONTRACT_IDis unset.Design choices to review:
EventPoller. Subscriptions are injected, so the poller is testable without the network.monitorService.checkIndexerLag, not by the poller.Tests and results
Run from the repository root after
pnpm install --frozen-lockfile.npx jest tests/notificationPreferenceRepository.test.ts tests/proofOfDeliveryService.test.tsnpx jest tests/fleet.test.tsnpx jest tests/integration/fleetRoutes.test.tsnpx jest tests/eventPoller.test.tsnpx jest(full suite)npx eslinton every changed source and test filenpx tsc --noEmittests/deliveryStatusTransition.test.ts:96(stray characters). This is onmaintoo.The 14 failing suites are the same suites that fail on
main: disputes, delivery status update and transition, QR code, delivery ETA, escrow E2E, escrow handlers, indexer API, Swagger, auth flow, delivery flow and socket location. A run of those suites on a cleanmainworktree produced the same failing set. Those failures are outside this change. Onmainseveral of these suites could not load at all, because of thevalidatebug fixed below. They now load and run, and the remaining failures are in their own logic.Compatibility and security
src/routes/delivery.routes.ts: the fee-estimate route calledvalidate(...), which was never imported. Becauseapp.tsloads this route, the whole app failed to load in tests. The call now uses the existingvalidateRequestimport. No behaviour change beyond the app loading.getEventsand writesEventLog/IndexerStatusonce the server starts withESCROW_CONTRACT_IDset. This is new runtime behaviour. Handlers must be idempotent, because apendingrecord can be processed again.Known limitations and follow-ups
EventLogrecords are not retried yet. They are markedfailedfor a later retry tool.ProofOfDeliveryServiceauthorization only checks the assigned driver. An unassigned delivery accepts an upload from any authenticated user, and the admin role is not checked at the service layer. The issue asks for driver-or-admin only. This PR does not change that. Tests lock in only the assigned-driver rule.assertProofOfDeliveryExistsis not tested directly. The guard itself is tested.backend/tests/..., but test files live in the repository roottests/directory. The new files follow that layout.closes #230
closes #231
closes #233
closes #237