From b0de73a4a11adf721882af53deabb0ad6cef97bf Mon Sep 17 00:00:00 2001 From: "IceHe.xyz" Date: Thu, 7 Apr 2022 11:42:20 +0800 Subject: [PATCH] test(core): get sign-in experience (#499) --- .../src/routes/sign-in-experience.test.ts | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/packages/core/src/routes/sign-in-experience.test.ts b/packages/core/src/routes/sign-in-experience.test.ts index 2771617f0..db899aea1 100644 --- a/packages/core/src/routes/sign-in-experience.test.ts +++ b/packages/core/src/routes/sign-in-experience.test.ts @@ -34,8 +34,10 @@ jest.mock('@/connectors', () => { }; }); +const findDefaultSignInExperience = jest.fn(async () => mockSignInExperience); + jest.mock('@/queries/sign-in-experience', () => ({ - findDefaultSignInExperience: jest.fn(async (): Promise => mockSignInExperience), + findDefaultSignInExperience: jest.fn(async () => findDefaultSignInExperience()), updateDefaultSignInExperience: jest.fn( async (data: Partial): Promise => ({ ...mockSignInExperience, @@ -46,10 +48,30 @@ jest.mock('@/queries/sign-in-experience', () => ({ const signInExperienceRequester = createRequester({ authedRoutes: signInExperiencesRoutes }); -it('GET /sign-in-exp', async () => { - const response = await signInExperienceRequester.get('/sign-in-exp'); - expect(response.status).toEqual(200); - expect(response.body).toEqual(mockSignInExperience); +describe('GET /sign-in-exp', () => { + it('should call findDefaultSignInExperience', async () => { + const response = await signInExperienceRequester.get('/sign-in-exp'); + expect(findDefaultSignInExperience).toHaveBeenCalledTimes(1); + expect(response.status).toEqual(200); + expect(response.body).toEqual(mockSignInExperience); + }); + + it('should filter enabled social connectors', async () => { + const signInExperience = { + ...mockSignInExperience, + signInMethods: { ...mockSignInMethods, social: SignInMethodState.secondary }, + socialSignInConnectorIds: ['facebook', 'github', 'google'], + }; + + findDefaultSignInExperience.mockImplementationOnce(async () => signInExperience); + + const response = await signInExperienceRequester.get('/sign-in-exp'); + expect(response.status).toEqual(200); + expect(response.body).toEqual({ + ...signInExperience, + socialSignInConnectorIds: ['facebook', 'github'], + }); + }); }); describe('PATCH /sign-in-exp', () => {