mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
feat(core): update sie (#2128)
This commit is contained in:
parent
37c8e703da
commit
5823e063d1
3 changed files with 26 additions and 35 deletions
|
@ -102,3 +102,7 @@ export const mockSignInMethod: SignIn['methods'][0] = {
|
|||
verificationCode: false,
|
||||
isPasswordPrimary: true,
|
||||
};
|
||||
|
||||
export const mockSignIn = {
|
||||
methods: [mockSignInMethod],
|
||||
};
|
||||
|
|
|
@ -14,9 +14,13 @@ import {
|
|||
mockSignInMethods,
|
||||
mockWechatConnector,
|
||||
mockColor,
|
||||
mockSignUp,
|
||||
mockSignIn,
|
||||
} from '@/__mocks__';
|
||||
import * as signInExpLib from '@/lib/sign-in-experience';
|
||||
import * as signInLib from '@/lib/sign-in-experience/sign-in';
|
||||
import * as signInMethodsLib from '@/lib/sign-in-experience/sign-in-methods';
|
||||
import * as signUpLib from '@/lib/sign-in-experience/sign-up';
|
||||
import { createRequester } from '@/utils/test-utils';
|
||||
|
||||
import signInExperiencesRoutes from './sign-in-experience';
|
||||
|
@ -65,39 +69,6 @@ describe('GET /sign-in-exp', () => {
|
|||
});
|
||||
|
||||
describe('PATCH /sign-in-exp', () => {
|
||||
it('should not update social connector targets when social sign-in is disabled', async () => {
|
||||
const signInMethods = { ...mockSignInMethods, social: SignInMethodState.Disabled };
|
||||
const response = await signInExperienceRequester.patch('/sign-in-exp').send({
|
||||
signInMethods,
|
||||
socialSignInConnectorTargets: ['facebook'],
|
||||
});
|
||||
expect(response).toMatchObject({
|
||||
status: 200,
|
||||
body: {
|
||||
...mockSignInExperience,
|
||||
signInMethods,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should update enabled social connector targets only when social sign-in is enabled', async () => {
|
||||
const signInMethods = { ...mockSignInMethods, social: SignInMethodState.Secondary };
|
||||
const socialSignInConnectorTargets = ['facebook'];
|
||||
const signInExperience = {
|
||||
signInMethods,
|
||||
socialSignInConnectorTargets,
|
||||
};
|
||||
const response = await signInExperienceRequester.patch('/sign-in-exp').send(signInExperience);
|
||||
expect(response).toMatchObject({
|
||||
status: 200,
|
||||
body: {
|
||||
...mockSignInExperience,
|
||||
signInMethods,
|
||||
socialSignInConnectorTargets,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should update social connector targets in correct sorting order', async () => {
|
||||
const signInMethods = { ...mockSignInMethods, social: SignInMethodState.Secondary };
|
||||
const socialSignInConnectorTargets = ['github', 'facebook'];
|
||||
|
@ -141,6 +112,8 @@ describe('PATCH /sign-in-exp', () => {
|
|||
const validateBranding = jest.spyOn(signInExpLib, 'validateBranding');
|
||||
const validateTermsOfUse = jest.spyOn(signInExpLib, 'validateTermsOfUse');
|
||||
const validateSignInMethods = jest.spyOn(signInMethodsLib, 'validateSignInMethods');
|
||||
const validateSignIn = jest.spyOn(signInLib, 'validateSignIn');
|
||||
const validateSignUp = jest.spyOn(signUpLib, 'validateSignUp');
|
||||
|
||||
const response = await signInExperienceRequester.patch('/sign-in-exp').send({
|
||||
color: mockColor,
|
||||
|
@ -148,15 +121,21 @@ describe('PATCH /sign-in-exp', () => {
|
|||
termsOfUse,
|
||||
signInMethods: mockSignInMethods,
|
||||
socialSignInConnectorTargets,
|
||||
signUp: mockSignUp,
|
||||
signIn: mockSignIn,
|
||||
forgotPassword: true,
|
||||
});
|
||||
const connectors = [mockFacebookConnector, mockGithubConnector, mockWechatConnector];
|
||||
|
||||
expect(validateBranding).toHaveBeenCalledWith(mockBranding);
|
||||
expect(validateTermsOfUse).toHaveBeenCalledWith(termsOfUse);
|
||||
expect(validateSignInMethods).toHaveBeenCalledWith(
|
||||
mockSignInMethods,
|
||||
socialSignInConnectorTargets,
|
||||
[mockFacebookConnector, mockGithubConnector, mockWechatConnector]
|
||||
connectors
|
||||
);
|
||||
expect(validateSignUp).toHaveBeenCalledWith(mockSignUp, connectors);
|
||||
expect(validateSignIn).toHaveBeenCalledWith(mockSignIn, mockSignUp, connectors);
|
||||
|
||||
expect(response).toMatchObject({
|
||||
status: 200,
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
validateSignInMethods,
|
||||
isEnabled,
|
||||
validateSignUp,
|
||||
validateSignIn,
|
||||
} from '@/lib/sign-in-experience';
|
||||
import koaGuard from '@/middleware/koa-guard';
|
||||
import {
|
||||
|
@ -34,7 +35,7 @@ export default function signInExperiencesRoutes<T extends AuthedRouter>(router:
|
|||
}),
|
||||
async (ctx, next) => {
|
||||
const { socialSignInConnectorTargets, ...rest } = ctx.guard.body;
|
||||
const { branding, termsOfUse, signInMethods, signUp } = rest;
|
||||
const { branding, termsOfUse, signInMethods, signUp, signIn } = rest;
|
||||
|
||||
if (branding) {
|
||||
validateBranding(branding);
|
||||
|
@ -67,6 +68,13 @@ export default function signInExperiencesRoutes<T extends AuthedRouter>(router:
|
|||
validateSignUp(signUp, enabledConnectors);
|
||||
}
|
||||
|
||||
if (signIn && signUp) {
|
||||
validateSignIn(signIn, signUp, enabledConnectors);
|
||||
} else if (signIn) {
|
||||
const signInExperience = await findDefaultSignInExperience();
|
||||
validateSignIn(signIn, signInExperience.signUp, enabledConnectors);
|
||||
}
|
||||
|
||||
// Update socialSignInConnectorTargets only when social sign-in is enabled.
|
||||
const signInExperience =
|
||||
signInMethods && isEnabled(signInMethods.social)
|
||||
|
|
Loading…
Reference in a new issue