0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-06 20:40:08 -05:00

test(core): get sign-in experience (#499)

This commit is contained in:
IceHe.xyz 2022-04-07 11:42:20 +08:00 committed by GitHub
parent ab50cf1168
commit b0de73a4a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -34,8 +34,10 @@ jest.mock('@/connectors', () => {
};
});
const findDefaultSignInExperience = jest.fn(async () => mockSignInExperience);
jest.mock('@/queries/sign-in-experience', () => ({
findDefaultSignInExperience: jest.fn(async (): Promise<SignInExperience> => mockSignInExperience),
findDefaultSignInExperience: jest.fn(async () => findDefaultSignInExperience()),
updateDefaultSignInExperience: jest.fn(
async (data: Partial<CreateSignInExperience>): Promise<SignInExperience> => ({
...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', () => {