From 741135a171f05f5b7f0370a7fc008def77bd0769 Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Mon, 15 May 2023 09:19:55 +0200 Subject: [PATCH] fix: add missing options parameter back in (#3770) This PR adds the missing serialization of the AuthenticationRequired response back in. It was mistakenly removed in #3633. This PR also adds another test to verify that it the options property is present. --- src/lib/error/unleash-error.test.ts | 19 +++++++++++++++++++ src/lib/types/authentication-required.ts | 1 + 2 files changed, 20 insertions(+) diff --git a/src/lib/error/unleash-error.test.ts b/src/lib/error/unleash-error.test.ts index 1faf18b844..2df0727b0e 100644 --- a/src/lib/error/unleash-error.test.ts +++ b/src/lib/error/unleash-error.test.ts @@ -369,6 +369,25 @@ describe('Error serialization special cases', () => { expect(json).toMatchObject({ path, type }); }); + it('AuthenticationRequired adds `options` if they are present', () => { + const config = { + type: 'password', + path: `base-path/auth/simple/login`, + message: 'You must sign in order to use Unleash', + options: [ + { + type: 'google', + message: 'Sign in with Google', + path: `base-path/auth/google/login`, + }, + ], + }; + + const json = new AuthenticationRequired(config).toJSON(); + + expect(json).toMatchObject(config); + }); + it('NoAccessError: adds `permission`', () => { const permission = 'x'; const error = new NoAccessError(permission); diff --git a/src/lib/types/authentication-required.ts b/src/lib/types/authentication-required.ts index 5883acec65..9efd6579b4 100644 --- a/src/lib/types/authentication-required.ts +++ b/src/lib/types/authentication-required.ts @@ -39,6 +39,7 @@ class AuthenticationRequired extends UnleashError { ...super.toJSON(), path: this.path, type: this.type, + ...(this.options ? { options: this.options } : {}), }; } }