0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-20 21:32:31 -05:00

refactor(core,schemas): pascalcase enum keys (#558)

* refactor(schemas): pascalcase enum keys

* chore(core): pascalcase enum keys
This commit is contained in:
IceHe.xyz 2022-04-18 13:35:48 +08:00 committed by GitHub
parent a5235f6ad1
commit 3da3309cbf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 78 additions and 78 deletions

View file

@ -24,14 +24,14 @@ export const mockSignInExperience: SignInExperience = {
},
languageInfo: {
autoDetect: true,
fallbackLanguage: Language.english,
fixedLanguage: Language.chinese,
fallbackLanguage: Language.English,
fixedLanguage: Language.Chinese,
},
signInMethods: {
username: SignInMethodState.primary,
email: SignInMethodState.disabled,
sms: SignInMethodState.disabled,
social: SignInMethodState.secondary,
username: SignInMethodState.Primary,
email: SignInMethodState.Disabled,
sms: SignInMethodState.Disabled,
social: SignInMethodState.Secondary,
},
socialSignInConnectorIds: ['github', 'facebook'],
};
@ -52,13 +52,13 @@ export const mockTermsOfUse: TermsOfUse = {
export const mockLanguageInfo: LanguageInfo = {
autoDetect: true,
fallbackLanguage: Language.english,
fixedLanguage: Language.chinese,
fallbackLanguage: Language.English,
fixedLanguage: Language.Chinese,
};
export const mockSignInMethods: SignInMethods = {
username: SignInMethodState.primary,
email: SignInMethodState.disabled,
sms: SignInMethodState.disabled,
social: SignInMethodState.disabled,
username: SignInMethodState.Primary,
email: SignInMethodState.Disabled,
sms: SignInMethodState.Disabled,
social: SignInMethodState.Disabled,
};

View file

@ -61,15 +61,15 @@ describe('validate terms of use', () => {
describe('check whether the social sign in method state is enabled', () => {
it('should be truthy when sign-in method state is primary', () => {
expect(isEnabled(SignInMethodState.primary)).toBeTruthy();
expect(isEnabled(SignInMethodState.Primary)).toBeTruthy();
});
it('should be truthy when sign-in method state is secondary', () => {
expect(isEnabled(SignInMethodState.secondary)).toBeTruthy();
expect(isEnabled(SignInMethodState.Secondary)).toBeTruthy();
});
it('should be falsy when sign-in method state is disabled', () => {
expect(isEnabled(SignInMethodState.disabled)).toBeFalsy();
expect(isEnabled(SignInMethodState.Disabled)).toBeFalsy();
});
});
@ -78,7 +78,7 @@ describe('validate sign-in methods', () => {
test('should throw when there is no primary sign-in method', () => {
expect(() => {
validateSignInMethods(
{ ...mockSignInMethods, username: SignInMethodState.disabled },
{ ...mockSignInMethods, username: SignInMethodState.Disabled },
[],
[]
);
@ -89,7 +89,7 @@ describe('validate sign-in methods', () => {
test('should throw when there are more than one primary sign-in methods', () => {
expect(() => {
validateSignInMethods({ ...mockSignInMethods, social: SignInMethodState.primary }, [], []);
validateSignInMethods({ ...mockSignInMethods, social: SignInMethodState.Primary }, [], []);
}).toMatchError(
new RequestError('sign_in_experiences.not_one_and_only_one_primary_sign_in_method')
);
@ -100,7 +100,7 @@ describe('validate sign-in methods', () => {
test('should throw when there is no enabled email connector and email sign-in method is enabled', async () => {
expect(() => {
validateSignInMethods(
{ ...mockSignInMethods, email: SignInMethodState.secondary },
{ ...mockSignInMethods, email: SignInMethodState.Secondary },
[],
enabledConnectorInstances as ConnectorInstance[]
);
@ -115,7 +115,7 @@ describe('validate sign-in methods', () => {
test('should throw when there is no enabled SMS connector and SMS sign-in method is enabled', () => {
expect(() => {
validateSignInMethods(
{ ...mockSignInMethods, sms: SignInMethodState.secondary },
{ ...mockSignInMethods, sms: SignInMethodState.Secondary },
[],
enabledConnectorInstances as ConnectorInstance[]
);
@ -129,7 +129,7 @@ describe('validate sign-in methods', () => {
test('should throw when there is no enabled social connector and social sign-in method is enabled', () => {
expect(() => {
validateSignInMethods({ ...mockSignInMethods, social: SignInMethodState.secondary }, [], [
validateSignInMethods({ ...mockSignInMethods, social: SignInMethodState.Secondary }, [], [
mockAliyunDmConnectorInstance,
] as ConnectorInstance[]);
}).toMatchError(
@ -144,7 +144,7 @@ describe('validate sign-in methods', () => {
test('should throw when the social connector IDs are empty and social sign-in method is enabled', () => {
expect(() => {
validateSignInMethods(
{ ...mockSignInMethods, social: SignInMethodState.secondary },
{ ...mockSignInMethods, social: SignInMethodState.Secondary },
[],
enabledConnectorInstances as ConnectorInstance[]
);
@ -155,7 +155,7 @@ describe('validate sign-in methods', () => {
test('should not validate selected social connectors when social sign-in method is disabled', () => {
expect(() => {
validateSignInMethods(
{ ...mockSignInMethods, social: SignInMethodState.disabled },
{ ...mockSignInMethods, social: SignInMethodState.Disabled },
['google', 'facebook'],
enabledConnectorInstances as ConnectorInstance[]
);
@ -165,7 +165,7 @@ describe('validate sign-in methods', () => {
test('should throw when some selected social connector are disabled and social sign-in method is enabled', () => {
expect(() => {
validateSignInMethods(
{ ...mockSignInMethods, social: SignInMethodState.secondary },
{ ...mockSignInMethods, social: SignInMethodState.Secondary },
['google', 'facebook'],
enabledConnectorInstances as ConnectorInstance[]
);
@ -175,7 +175,7 @@ describe('validate sign-in methods', () => {
test('should not throw when all selected social connectors are enabled and social sign-in method is enabled', () => {
expect(() => {
validateSignInMethods(
{ ...mockSignInMethods, social: SignInMethodState.secondary },
{ ...mockSignInMethods, social: SignInMethodState.Secondary },
['facebook', 'github'],
enabledConnectorInstances as ConnectorInstance[]
);

View file

@ -23,7 +23,7 @@ export const validateTermsOfUse = (termsOfUse: TermsOfUse) => {
);
};
export const isEnabled = (state: SignInMethodState) => state !== SignInMethodState.disabled;
export const isEnabled = (state: SignInMethodState) => state !== SignInMethodState.Disabled;
export const validateSignInMethods = (
signInMethods: SignInMethods,
@ -32,7 +32,7 @@ export const validateSignInMethods = (
) => {
const signInMethodStates = Object.values(signInMethods);
assertThat(
signInMethodStates.filter((state) => state === SignInMethodState.primary).length === 1,
signInMethodStates.filter((state) => state === SignInMethodState.Primary).length === 1,
'sign_in_experiences.not_one_and_only_one_primary_sign_in_method'
);

View file

@ -24,11 +24,11 @@ describe('koaRoleGuard middleware', () => {
it('should throw if user dose not have admin role', async () => {
ctx.userInfo.roleNames = ['guest'];
await expect(koaRoleGuard(UserRole.admin)(ctx, next)).rejects.toMatchError(unauthorizedError);
await expect(koaRoleGuard(UserRole.Admin)(ctx, next)).rejects.toMatchError(unauthorizedError);
});
it('should not throw for admin user', async () => {
ctx.userInfo.roleNames = ['admin'];
await expect(koaRoleGuard(UserRole.admin)(ctx, next)).resolves.not.toThrow();
await expect(koaRoleGuard(UserRole.Admin)(ctx, next)).resolves.not.toThrow();
});
});

View file

@ -125,30 +125,30 @@ describe('signInMethods', () => {
describe('username', () => {
test.each(validSignInMethodStates)('%p should success', async (state) => {
if (state === SignInMethodState.primary) {
if (state === SignInMethodState.Primary) {
return;
}
const signInExperience = {
signInMethods: {
username: state,
email: SignInMethodState.primary,
sms: SignInMethodState.disabled,
social: SignInMethodState.disabled,
email: SignInMethodState.Primary,
sms: SignInMethodState.Disabled,
social: SignInMethodState.Disabled,
},
};
await expectPatchResponseStatus(signInExperience, 200);
});
test.each(invalidSignInMethodStates)('%p should fail', async (state) => {
if (state === SignInMethodState.primary) {
if (state === SignInMethodState.Primary) {
return;
}
const signInExperience = {
signInMethods: {
username: state,
email: SignInMethodState.primary,
sms: SignInMethodState.disabled,
social: SignInMethodState.disabled,
email: SignInMethodState.Primary,
sms: SignInMethodState.Disabled,
social: SignInMethodState.Disabled,
},
};
await expectPatchResponseStatus(signInExperience, 400);
@ -157,30 +157,30 @@ describe('signInMethods', () => {
describe('email', () => {
test.each(validSignInMethodStates)('%p should success', async (state) => {
if (state === SignInMethodState.primary) {
if (state === SignInMethodState.Primary) {
return;
}
const signInExperience = {
signInMethods: {
username: SignInMethodState.disabled,
username: SignInMethodState.Disabled,
email: state,
sms: SignInMethodState.primary,
social: SignInMethodState.disabled,
sms: SignInMethodState.Primary,
social: SignInMethodState.Disabled,
},
};
await expectPatchResponseStatus(signInExperience, 200);
});
test.each(invalidSignInMethodStates)('%p should fail', async (state) => {
if (state === SignInMethodState.primary) {
if (state === SignInMethodState.Primary) {
return;
}
const signInExperience = {
signInMethods: {
username: SignInMethodState.disabled,
username: SignInMethodState.Disabled,
email: state,
sms: SignInMethodState.primary,
social: SignInMethodState.disabled,
sms: SignInMethodState.Primary,
social: SignInMethodState.Disabled,
},
};
await expectPatchResponseStatus(signInExperience, 400);
@ -189,15 +189,15 @@ describe('signInMethods', () => {
describe('sms', () => {
test.each(validSignInMethodStates)('%p should success', async (state) => {
if (state === SignInMethodState.primary) {
if (state === SignInMethodState.Primary) {
return;
}
const signInExperience = {
signInMethods: {
username: SignInMethodState.disabled,
email: SignInMethodState.disabled,
username: SignInMethodState.Disabled,
email: SignInMethodState.Disabled,
sms: state,
social: SignInMethodState.primary,
social: SignInMethodState.Primary,
},
socialSignInConnectorIds: ['github'],
};
@ -205,15 +205,15 @@ describe('signInMethods', () => {
});
test.each(invalidSignInMethodStates)('%p should fail', async (state) => {
if (state === SignInMethodState.primary) {
if (state === SignInMethodState.Primary) {
return;
}
const signInExperience = {
signInMethods: {
username: SignInMethodState.disabled,
email: SignInMethodState.disabled,
username: SignInMethodState.Disabled,
email: SignInMethodState.Disabled,
sms: state,
social: SignInMethodState.primary,
social: SignInMethodState.Primary,
},
socialSignInConnectorIds: ['github'],
};
@ -223,14 +223,14 @@ describe('signInMethods', () => {
describe('social', () => {
test.each(validSignInMethodStates)('%p should success', async (state) => {
if (state === SignInMethodState.primary) {
if (state === SignInMethodState.Primary) {
return;
}
const signInExperience = {
signInMethods: {
username: SignInMethodState.primary,
email: SignInMethodState.disabled,
sms: SignInMethodState.disabled,
username: SignInMethodState.Primary,
email: SignInMethodState.Disabled,
sms: SignInMethodState.Disabled,
social: state,
},
socialSignInConnectorIds: ['github'],
@ -239,14 +239,14 @@ describe('signInMethods', () => {
});
test.each(invalidSignInMethodStates)('%p should fail', async (state) => {
if (state === SignInMethodState.primary) {
if (state === SignInMethodState.Primary) {
return;
}
const signInExperience = {
signInMethods: {
username: SignInMethodState.primary,
email: SignInMethodState.disabled,
sms: SignInMethodState.disabled,
username: SignInMethodState.Primary,
email: SignInMethodState.Disabled,
sms: SignInMethodState.Disabled,
social: state,
},
socialSignInConnectorIds: ['github'],
@ -262,7 +262,7 @@ describe('socialSignInConnectorIds', () => {
async (socialSignInConnectorIds) => {
await expectPatchResponseStatus(
{
signInMethods: { ...mockSignInMethods, social: SignInMethodState.secondary },
signInMethods: { ...mockSignInMethods, social: SignInMethodState.Secondary },
socialSignInConnectorIds,
},
200
@ -275,7 +275,7 @@ describe('socialSignInConnectorIds', () => {
async (socialSignInConnectorIds: any[]) => {
await expectPatchResponseStatus(
{
signInMethods: { ...mockSignInMethods, social: SignInMethodState.secondary },
signInMethods: { ...mockSignInMethods, social: SignInMethodState.Secondary },
socialSignInConnectorIds,
},
400

View file

@ -63,7 +63,7 @@ describe('GET /sign-in-exp', () => {
it('should filter enabled social connectors', async () => {
const signInExperience = {
...mockSignInExperience,
signInMethods: { ...mockSignInMethods, social: SignInMethodState.secondary },
signInMethods: { ...mockSignInMethods, social: SignInMethodState.Secondary },
socialSignInConnectorIds: ['facebook', 'github', 'google'],
};
@ -93,7 +93,7 @@ describe('GET /sign-in-settings', () => {
describe('PATCH /sign-in-exp', () => {
it('should not update social connector ids when social sign-in is disabled', async () => {
const signInMethods = { ...mockSignInMethods, social: SignInMethodState.disabled };
const signInMethods = { ...mockSignInMethods, social: SignInMethodState.Disabled };
const response = await signInExperienceRequester.patch('/sign-in-exp').send({
signInMethods,
socialSignInConnectorIds: ['facebook'],
@ -108,7 +108,7 @@ describe('PATCH /sign-in-exp', () => {
});
it('should update enabled social connector IDs only when social sign-in is enabled', async () => {
const signInMethods = { ...mockSignInMethods, social: SignInMethodState.secondary };
const signInMethods = { ...mockSignInMethods, social: SignInMethodState.Secondary };
const socialSignInConnectorIds = ['facebook'];
const signInExperience = {
signInMethods,
@ -126,7 +126,7 @@ describe('PATCH /sign-in-exp', () => {
});
it('should update social connector IDs in correct sorting order', async () => {
const signInMethods = { ...mockSignInMethods, social: SignInMethodState.secondary };
const signInMethods = { ...mockSignInMethods, social: SignInMethodState.Secondary };
const socialSignInConnectorIds = ['github', 'facebook'];
const signInExperience = {
signInMethods,

View file

@ -110,8 +110,8 @@ export const termsOfUseGuard = z.object({
export type TermsOfUse = z.infer<typeof termsOfUseGuard>;
export enum Language {
english = 'en',
chinese = 'zh-cn',
English = 'en',
Chinese = 'zh-cn',
}
export const languageInfoGuard = z.object({
@ -130,9 +130,9 @@ export enum SignInMethodKey {
}
export enum SignInMethodState {
primary = 'primary',
secondary = 'secondary',
disabled = 'disabled',
Primary = 'primary',
Secondary = 'secondary',
Disabled = 'disabled',
}
export const signInMethodsGuard = z.object({

View file

@ -12,17 +12,17 @@ export const defaultSignInExperience: Readonly<CreateSignInExperience> = {
},
languageInfo: {
autoDetect: true,
fallbackLanguage: Language.english,
fixedLanguage: Language.english,
fallbackLanguage: Language.English,
fixedLanguage: Language.English,
},
termsOfUse: {
enabled: false,
},
signInMethods: {
username: SignInMethodState.primary,
email: SignInMethodState.disabled,
sms: SignInMethodState.disabled,
social: SignInMethodState.disabled,
username: SignInMethodState.Primary,
email: SignInMethodState.Disabled,
sms: SignInMethodState.Disabled,
social: SignInMethodState.Disabled,
},
socialSignInConnectorIds: [],
};

View file

@ -18,5 +18,5 @@ export type UserInfo<Keys extends keyof CreateUser = typeof userInfoSelectFields
>;
export enum UserRole {
admin = 'admin',
Admin = 'admin',
}