@relaybus/testing 0.3.0 → 0.4.0

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/README.md CHANGED
@@ -40,6 +40,37 @@ claimer that keeps claiming drains the workload. Pass `keepsCompletedRecords:
40
40
  true` when the store keeps a completion history; run the suite once per mode the
41
41
  store supports.
42
42
 
43
+ ## Codec contract
44
+
45
+ Before adopting a wire format that other services already use, prove that a codec writes and reads it exactly. Give
46
+ `kafkaCodecContract` or `rabbitMqCodecContract` captured messages and the events they carry; each case is one test that
47
+ checks `encode(event)` against the captured message (value or body byte for byte or as canonical JSON, key, headers,
48
+ timestamp or properties) and that decoding the captured message gives the event:
49
+
50
+ ```ts
51
+ import { kafkaCodecContract } from '@relaybus/testing';
52
+ import { decodeKafkaRecord } from '@relaybus/kafka';
53
+
54
+ kafkaCodecContract('orders format', {
55
+ encode: orderCodec.encode,
56
+ decode: (record) => decodeKafkaRecord(orderCodec, record),
57
+ compare: 'bytes', // or 'json' to ignore key order and spacing
58
+ ignoreHeaders: ['traceparent'],
59
+ cases: [
60
+ {
61
+ name: 'order placed',
62
+ envelope, // the event
63
+ record: { topic: 'orders', key: 'order-1', headers: {}, value: '{"orderId":"1"}' }, // the captured record
64
+ // only: 'decode', // for a message only other producers write
65
+ },
66
+ ],
67
+ });
68
+ ```
69
+
70
+ `rabbitMqCodecContract` takes the same shape with `decodeRabbitMqMessage` from `@relaybus/rabbitmq` and captured messages
71
+ (routing key, properties, headers, body). `kafkaCodecMismatches` and `rabbitMqCodecMismatches` return the differences as
72
+ text lines instead of registering tests.
73
+
43
74
  ## FakeClock
44
75
 
45
76
  ```ts