From 3703fb8bc83506b72e26db4bf69b54ad55525347 Mon Sep 17 00:00:00 2001 From: Nishchal Gautam Date: Fri, 1 Nov 2019 17:29:46 +0700 Subject: [PATCH] test(searlie): validate data while decoding with headers --- src/Searilie.spec.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Searilie.spec.ts b/src/Searilie.spec.ts index 3e80740..ab5e675 100644 --- a/src/Searilie.spec.ts +++ b/src/Searilie.spec.ts @@ -36,12 +36,22 @@ describe("Searilie", () => { }); }); describe("decode using headers", () => { - const adapter: IAdapter = { - deserialize: jest.fn(() => [{a: 2}]), - getIdentifier: jest.fn(() => "A") - } as any; - const serializer = new Searilie(adapter); - expect(serializer.decodeUsingHeaders(`Aa,${INTEGER_IDENTIFIER}b:h2`)).toStrictEqual([{a: 2}]); + it("should throw error if wrong adapter", () => { + const adapter: IAdapter = { + deserialize: jest.fn(() => [{a: 2}]), + getIdentifier: jest.fn(() => "Z") + } as any; + const serializer = new Searilie(adapter); + expect(() => serializer.decodeUsingHeaders(`Aa,${INTEGER_IDENTIFIER}b:h2`)).toThrow("adapter mismatched"); + }); + it("should be able to decode properly", () => { + const adapter: IAdapter = { + deserialize: jest.fn(() => [{a: 2}]), + getIdentifier: jest.fn(() => "A") + } as any; + const serializer = new Searilie(adapter); + expect(serializer.decodeUsingHeaders(`Aa,${INTEGER_IDENTIFIER}b:h2`)).toStrictEqual([{a: 2}]); + }); }); describe("decode and encode with headers", () => { it("should decode and encode properly", () => {