From d810695b506dbc86bbad744b0e136776eddb20ee Mon Sep 17 00:00:00 2001 From: Patrick McLaughlin Date: Tue, 29 Mar 2022 18:51:55 -0400 Subject: [PATCH] chore: add test for decoding overlapping keys with flatten Although it is undefined behavior to define a `flatten` codec with overlapping keys, the actual codec needs to handle arbitrary input which might have them. This commit adds a test for this, and fortunately the existing code passes. --- packages/io-ts-http/test/combinators.test.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/io-ts-http/test/combinators.test.ts b/packages/io-ts-http/test/combinators.test.ts index a093db37..521dde74 100644 --- a/packages/io-ts-http/test/combinators.test.ts +++ b/packages/io-ts-http/test/combinators.test.ts @@ -39,6 +39,15 @@ describe('flattened', () => { it('combines with optional params', () => assertEncodes(codec, { foo: 42 }, { test: { foo: 42 }, anotherParam: {} })); + + it('does not get confused by overlapping extra parameters', () => { + const input = { + test: { foo: 42, bar: 'bad' }, + anotherParam: { foo: 123, bar: '123' }, + }; + const expected = { foo: 42, bar: '123' }; + assertDecodes(codec, input, expected); + }); }); describe('optionalized', () => {