Skip to content

Commit

Permalink
refactor(test): rebase and update the latest profile api
Browse files Browse the repository at this point in the history
rebase and update the latest profile api
  • Loading branch information
simeng-li committed Jul 25, 2024
1 parent b65e032 commit cd7e902
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/integration-tests/src/client/experience/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export class ExperienceClient extends MockClient {
}

public async updateProfile(payload: UpdateProfileApiPayload) {
return api.patch(`${experienceRoutes.profile}`, {
return api.post(`${experienceRoutes.profile}`, {
headers: { cookie: this.interactionCookie },
json: payload,
});
Expand Down
5 changes: 4 additions & 1 deletion packages/integration-tests/src/helpers/experience/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ export const registerNewUserWithVerificationCode = async (

const password = generatePassword();

await client.updateProfile({ password });
await client.updateProfile({
type: 'password',
value: password,
});
}

const { redirectTo } = await client.submitInteraction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,27 @@ devFeatureTest.describe('Fulfill User Profiles', () => {

await client.initInteraction({ interactionEvent: InteractionEvent.ForgotPassword });

await expectRejects(client.updateProfile({ username: 'username ' }), {
status: 400,
code: 'session.not_supported_for_forgot_password',
});
await expectRejects(
client.updateProfile({ type: SignInIdentifier.Username, value: 'username' }),
{
status: 400,
code: 'session.not_supported_for_forgot_password',
}
);
});

it('should throw 404 if the interaction is not identified', async () => {
const client = await initExperienceClient();

await client.initInteraction({ interactionEvent: InteractionEvent.SignIn });

await expectRejects(client.updateProfile({ username: 'username' }), {
status: 404,
code: 'session.identifier_not_found',
});
await expectRejects(
client.updateProfile({ type: SignInIdentifier.Username, value: 'username' }),
{
status: 404,
code: 'session.identifier_not_found',
}
);
});

it('should throw 422 if the profile field is already exist in current user account', async () => {
Expand All @@ -67,12 +73,15 @@ devFeatureTest.describe('Fulfill User Profiles', () => {
const client = await initExperienceClient();
await identifyUserWithUsernamePassword(client, username, password);

await expectRejects(client.updateProfile({ username: 'username' }), {
status: 422,
code: 'user.username_exists_in_profile',
});
await expectRejects(
client.updateProfile({ type: SignInIdentifier.Username, value: 'username' }),
{
status: 422,
code: 'user.username_exists_in_profile',
}
);

await expectRejects(client.updateProfile({ password: 'password' }), {
await expectRejects(client.updateProfile({ type: 'password', value: 'password' }), {
status: 422,
code: 'user.password_exists_in_profile',
});
Expand Down Expand Up @@ -102,7 +111,7 @@ devFeatureTest.describe('Fulfill User Profiles', () => {
code: verificationCode,
});

await expectRejects(client.updateProfile({ email: { verificationId } }), {
await expectRejects(client.updateProfile({ type: SignInIdentifier.Email, verificationId }), {
status: 422,
code: 'user.email_already_in_use',
});
Expand All @@ -124,10 +133,13 @@ devFeatureTest.describe('Fulfill User Profiles', () => {
const client = await initExperienceClient();
await identifyUserWithUsernamePassword(client, username, password);

await expectRejects(client.updateProfile({ username: 'username' }), {
status: 403,
code: 'session.mfa.require_mfa_verification',
});
await expectRejects(
client.updateProfile({ type: SignInIdentifier.Username, value: 'username' }),
{
status: 403,
code: 'session.mfa.require_mfa_verification',
}
);
});

it('should update the profile successfully if the mfa is enabled and verified', async () => {
Expand Down Expand Up @@ -164,7 +176,9 @@ devFeatureTest.describe('Fulfill User Profiles', () => {
code: verificationCode,
});

await expect(client.updateProfile({ email: { verificationId } })).resolves.not.toThrow();
await expect(
client.updateProfile({ type: SignInIdentifier.Email, verificationId })
).resolves.not.toThrow();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ devFeatureTest.describe('sign-in with password verification happy path', () => {
code: verificationCode,
});

await client.updateProfile({ email: { verificationId } });
await client.updateProfile({ type: SignInIdentifier.Email, verificationId });

const { redirectTo } = await client.submitInteraction();
await processSession(client, redirectTo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ devFeatureTest.describe('social sign-in and sign-up', () => {
status: 422,
});

await client.updateProfile({ username: generateUsername() });
await client.updateProfile({ type: SignInIdentifier.Username, value: generateUsername() });

const { redirectTo } = await client.submitInteraction();
const userId = await processSession(client, redirectTo);
Expand Down

0 comments on commit cd7e902

Please sign in to comment.