-
-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(core): add register integration tests
add register integration tests
- Loading branch information
Showing
6 changed files
with
303 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...gration-tests/src/tests/api/experience-api/register-interaction/verification-code.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { | ||
InteractionEvent, | ||
SignInIdentifier, | ||
type VerificationCodeIdentifier, | ||
} from '@logto/schemas'; | ||
|
||
import { deleteUser } from '#src/api/admin-user.js'; | ||
import { initExperienceClient, logoutClient, processSession } from '#src/helpers/client.js'; | ||
import { setEmailConnector, setSmsConnector } from '#src/helpers/connector.js'; | ||
import { registerNewUserWithVerificationCode } from '#src/helpers/experience/index.js'; | ||
import { | ||
successfullySendVerificationCode, | ||
successfullyVerifyVerificationCode, | ||
} from '#src/helpers/experience/verification-code.js'; | ||
import { expectRejects } from '#src/helpers/index.js'; | ||
import { enableAllVerificationCodeSignInMethods } from '#src/helpers/sign-in-experience.js'; | ||
import { generateNewUser } from '#src/helpers/user.js'; | ||
import { devFeatureTest, generateEmail, generatePhone } from '#src/utils.js'; | ||
|
||
const verificationIdentifierType: readonly [SignInIdentifier.Email, SignInIdentifier.Phone] = | ||
Object.freeze([SignInIdentifier.Email, SignInIdentifier.Phone]); | ||
|
||
const identifiersTypeToUserProfile = Object.freeze({ | ||
email: 'primaryEmail', | ||
phone: 'primaryPhone', | ||
}); | ||
|
||
devFeatureTest.describe('Register interaction with verification code happy path', () => { | ||
beforeAll(async () => { | ||
await Promise.all([setEmailConnector(), setSmsConnector()]); | ||
await enableAllVerificationCodeSignInMethods({ | ||
identifiers: [SignInIdentifier.Email, SignInIdentifier.Phone], | ||
password: false, | ||
verify: true, | ||
}); | ||
}); | ||
|
||
it.each(verificationIdentifierType)( | ||
'Should register with verification code using %p successfully', | ||
async (identifier) => { | ||
const userId = await registerNewUserWithVerificationCode({ | ||
type: identifier, | ||
value: identifier === SignInIdentifier.Email ? generateEmail() : generatePhone(), | ||
}); | ||
|
||
await deleteUser(userId); | ||
} | ||
); | ||
|
||
it.each(verificationIdentifierType)( | ||
'Should fail to sign-up with existing %p identifier and directly sign-in instead ', | ||
async (identifierType) => { | ||
const { userProfile, user } = await generateNewUser({ | ||
[identifiersTypeToUserProfile[identifierType]]: true, | ||
}); | ||
|
||
const identifier: VerificationCodeIdentifier = { | ||
type: identifierType, | ||
value: userProfile[identifiersTypeToUserProfile[identifierType]]!, | ||
}; | ||
|
||
const client = await initExperienceClient(); | ||
await client.initInteraction({ interactionEvent: InteractionEvent.Register }); | ||
|
||
const { verificationId, code } = await successfullySendVerificationCode(client, { | ||
identifier, | ||
interactionEvent: InteractionEvent.Register, | ||
}); | ||
|
||
await successfullyVerifyVerificationCode(client, { | ||
identifier, | ||
verificationId, | ||
code, | ||
}); | ||
|
||
await expectRejects( | ||
client.identifyUser({ | ||
verificationId, | ||
}), | ||
{ | ||
code: `user.${identifierType}_already_in_use`, | ||
status: 422, | ||
} | ||
); | ||
|
||
await client.updateInteractionEvent({ | ||
interactionEvent: InteractionEvent.SignIn, | ||
}); | ||
|
||
await client.identifyUser({ | ||
verificationId, | ||
}); | ||
|
||
const { redirectTo } = await client.submitInteraction(); | ||
await processSession(client, redirectTo); | ||
await logoutClient(client); | ||
|
||
await deleteUser(user.id); | ||
} | ||
); | ||
}); |
48 changes: 48 additions & 0 deletions
48
packages/integration-tests/src/tests/api/experience-api/sign-in-interaction/social.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { ConnectorType } from '@logto/connector-kit'; | ||
import { generateStandardId } from '@logto/shared'; | ||
|
||
import { mockSocialConnectorId } from '#src/__mocks__/connectors-mock.js'; | ||
import { deleteUser, getUser } from '#src/api/admin-user.js'; | ||
import { clearConnectorsByTypes, setSocialConnector } from '#src/helpers/connector.js'; | ||
import { signInWithSocial } from '#src/helpers/experience/index.js'; | ||
import { devFeatureTest, generateEmail } from '#src/utils.js'; | ||
|
||
devFeatureTest.describe('social sign-in and sign-up', () => { | ||
const connectorIdMap = new Map<string, string>(); | ||
const socialUserId = generateStandardId(); | ||
const email = generateEmail(); | ||
|
||
beforeAll(async () => { | ||
await clearConnectorsByTypes([ConnectorType.Social]); | ||
|
||
const { id: socialConnectorId } = await setSocialConnector(); | ||
connectorIdMap.set(mockSocialConnectorId, socialConnectorId); | ||
}); | ||
|
||
afterAll(async () => { | ||
await clearConnectorsByTypes([ConnectorType.Social]); | ||
}); | ||
|
||
it('should successfully sign-up with social and sync email', async () => { | ||
const userId = await signInWithSocial( | ||
connectorIdMap.get(mockSocialConnectorId)!, | ||
{ | ||
id: socialUserId, | ||
email, | ||
}, | ||
true | ||
); | ||
|
||
const { primaryEmail } = await getUser(userId); | ||
expect(primaryEmail).toBe(email); | ||
}); | ||
|
||
it('should successfully sign-in with social', async () => { | ||
const userId = await signInWithSocial(connectorIdMap.get(mockSocialConnectorId)!, { | ||
id: socialUserId, | ||
email, | ||
}); | ||
|
||
await deleteUser(userId); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters