From 65d5722c38756d6180d359d2b6cceb091a13b2c2 Mon Sep 17 00:00:00 2001 From: Dominic Cassidy Date: Tue, 14 Oct 2025 12:55:41 +0100 Subject: [PATCH] add test for string enums --- test/basic.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/basic.js b/test/basic.js index 8c97575..19a5f9d 100644 --- a/test/basic.js +++ b/test/basic.js @@ -395,3 +395,41 @@ test('basic dispatch to non-existent route throws', async (t) => { const badMsg = { id: -1, name: '@test/invalid', value: 'error' } await t.exception(r.dispatch(badMsg, 'invalid-context'), /Handler not found for ID:-1/) }) + +test('can both encode and decode string enums', async (t) => { + const hd = await createTestSchema(t) + hd.rebuild( + { + schema: (schema) => { + const ns = schema.namespace('test') + ns.register({ + name: 'request', + strings: true, + enum: ['en', 'it'] + }) + }, + dispatch: (hyperdispatch) => { + const ns = hyperdispatch.namespace('test') + ns.register({ + name: 'test-request-1', + requestType: '@test/request' + }) + ns.register({ + name: 'test-request-2', + requestType: '@test/request' + }) + } + }, + { offset: 10 } + ) + const { encode, decode } = hd.module + + const encoded1 = encode('@test/test-request-1', 'en') + const encoded2 = encode('@test/test-request-2', 'it') + + const decoded1 = decode(encoded1) + const decoded2 = decode(encoded2) + t.is(decoded1.name, '@test/test-request-1') + t.is(decoded2.name, '@test/test-request-2') + t.is(decoded2.value, 'it') +})