3.1 KiB
id, name, status, depends_on, scope, risk, impact, level
| id | name | status | depends_on | scope | risk | impact | level | |
|---|---|---|---|---|---|---|---|---|
| redis-adapter-tests | Write tests for Redis event target adapter | completed |
|
moderate | medium | component | implementation |
Description
The Redis event target adapter (event-target-redis.ts) is implemented but has zero tests. The architecture doc lists 7 specific test scenarios. Tests need a running Redis instance or a mock. Since this is a dev dependency, we can use ioredis-mock or start a Redis container in CI. The test strategy needs to handle the Redis dependency.
The architecture specifies these test scenarios:
- Publish path — dispatchEvent sends to Redis with correct channel and serialized envelope
- Subscribe path — addEventListener subscribes to Redis, onMessage dispatches to local listeners
- Unsubscribe — removeEventListener unsubscribes from Redis when no listeners remain for a topic
- Topic scoping — type:id topics are correctly formed
- Envelope serialization — full
{ type, id, payload }round-trips through JSON - Multiple listeners — multiple listeners on same topic, single Redis subscribe
- Error propagation — what happens on connection failure
Note: test 7 (error propagation) is partially blocked by the missing error handling in the current implementation (tracked in task redis-channel-prefix-and-error-handling). The test should exist but may need to be adjusted once error handling is added.
Acceptance Criteria
test/event-target-redis.test.tsexists and passes- Test approach for Redis dependency is decided (mock, container, or ioredis-mock)
- Test: dispatchEvent publishes correct channel and serialized envelope
- Test: addEventListener subscribes to Redis and dispatches to local listeners
- Test: removeEventListener unsubscribes from Redis when no listeners remain
- Test: type:id topic scoping works correctly
- Test: EventEnvelope round-trips through JSON serialization
- Test: multiple listeners on same topic result in single Redis subscribe
- Test: custom serializer option works
References
- docs/architecture/event-targets/redis.md
- src/event-target-redis.ts
Notes
Test approach: Manual Redis mock (no external dependencies). The createMockRedis() helper creates a lightweight mock that tracks publish/subscribe/unsubscribe calls and provides simulateMessage() to trigger the message event handler. This avoids needing ioredis-mock or a running Redis instance.
Test 7 (error propagation) is not included because the current implementation lacks error handling — tracked in redis-channel-prefix-and-error-handling task.
Summary
Implemented comprehensive tests for the Redis event target adapter using a manual mock approach (no external dependencies needed).
- Created:
test/event-target-redis.test.ts(17 tests across 7 describe blocks) - Tests: 17, all passing
- Coverage: dispatchEvent/publish path, addEventListener/subscribe path, removeEventListener/unsubscribe path, topic scoping, envelope round-trip serialization, multiple listeners (single Redis subscribe), custom serializer, EventListenerObject support