2022-03-30 15:04:27 +08:00
|
|
|
import ky from 'ky';
|
|
|
|
|
|
|
|
import { consent } from './consent';
|
|
|
|
import {
|
|
|
|
register,
|
|
|
|
sendEmailPasscode as registerSendEmailPasscode,
|
2022-04-14 11:26:10 +08:00
|
|
|
sendSmsPasscode as registerSendSmsPasscode,
|
2022-03-30 15:04:27 +08:00
|
|
|
verifyEmailPasscode as registerVerifyEmailPasscode,
|
2022-04-14 11:26:10 +08:00
|
|
|
verifySmsPasscode as registerVerifySmsPasscode,
|
2022-03-30 15:04:27 +08:00
|
|
|
} from './register';
|
|
|
|
import {
|
|
|
|
signInBasic,
|
2022-04-14 11:26:10 +08:00
|
|
|
sendSmsPasscode,
|
2022-03-30 15:04:27 +08:00
|
|
|
sendEmailPasscode,
|
|
|
|
verifyEmailPasscode,
|
2022-04-14 11:26:10 +08:00
|
|
|
verifySmsPasscode,
|
2022-03-30 15:04:27 +08:00
|
|
|
} from './sign-in';
|
2022-04-12 15:03:38 +08:00
|
|
|
import {
|
|
|
|
invokeSocialSignIn,
|
|
|
|
signInWithSoical,
|
|
|
|
bindSocialAccount,
|
|
|
|
registerWithSocial,
|
|
|
|
} from './social';
|
2022-03-30 15:04:27 +08:00
|
|
|
|
|
|
|
jest.mock('ky', () => ({
|
|
|
|
post: jest.fn(() => ({
|
|
|
|
json: jest.fn(),
|
|
|
|
})),
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('api', () => {
|
|
|
|
const username = 'username';
|
|
|
|
const password = 'password';
|
|
|
|
const phone = '18888888';
|
|
|
|
const passcode = '111111';
|
|
|
|
const email = 'foo@logto.io';
|
|
|
|
|
|
|
|
const mockKyPost = ky.post as jest.Mock;
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mockKyPost.mockClear();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('signInBasic', async () => {
|
|
|
|
await signInBasic(username, password);
|
|
|
|
expect(ky.post).toBeCalledWith('/api/session/sign-in/username-password', {
|
|
|
|
json: {
|
|
|
|
username,
|
|
|
|
password,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-04-14 11:26:10 +08:00
|
|
|
it('sendSmsPasscode', async () => {
|
|
|
|
await sendSmsPasscode(phone);
|
|
|
|
expect(ky.post).toBeCalledWith('/api/session/sign-in/passwordless/sms/send-passcode', {
|
2022-03-30 15:04:27 +08:00
|
|
|
json: {
|
|
|
|
phone,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-04-14 11:26:10 +08:00
|
|
|
it('verifySmsPasscode', async () => {
|
|
|
|
await verifySmsPasscode(phone, passcode);
|
|
|
|
expect(ky.post).toBeCalledWith('/api/session/sign-in/passwordless/sms/verify-passcode', {
|
2022-03-30 15:04:27 +08:00
|
|
|
json: {
|
|
|
|
phone,
|
|
|
|
passcode,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sendEmailPasscode', async () => {
|
|
|
|
await sendEmailPasscode(email);
|
2022-04-09 12:20:21 +08:00
|
|
|
expect(ky.post).toBeCalledWith('/api/session/sign-in/passwordless/email/send-passcode', {
|
2022-03-30 15:04:27 +08:00
|
|
|
json: {
|
|
|
|
email,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('verifyEmailPasscode', async () => {
|
|
|
|
await verifyEmailPasscode(email, passcode);
|
2022-04-09 12:20:21 +08:00
|
|
|
expect(ky.post).toBeCalledWith('/api/session/sign-in/passwordless/email/verify-passcode', {
|
2022-03-30 15:04:27 +08:00
|
|
|
json: {
|
|
|
|
email,
|
|
|
|
passcode,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('consent', async () => {
|
|
|
|
await consent();
|
|
|
|
expect(ky.post).toBeCalledWith('/api/session/consent');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('register', async () => {
|
|
|
|
await register(username, password);
|
|
|
|
expect(ky.post).toBeCalledWith('/api/session/register/username-password', {
|
|
|
|
json: {
|
|
|
|
username,
|
|
|
|
password,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-04-14 11:26:10 +08:00
|
|
|
it('registerSendSmsPasscode', async () => {
|
|
|
|
await registerSendSmsPasscode(phone);
|
|
|
|
expect(ky.post).toBeCalledWith('/api/session/register/passwordless/sms/send-passcode', {
|
2022-03-30 15:04:27 +08:00
|
|
|
json: {
|
|
|
|
phone,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-04-14 11:26:10 +08:00
|
|
|
it('registerVerifySmsPasscode', async () => {
|
|
|
|
await registerVerifySmsPasscode(phone, passcode);
|
|
|
|
expect(ky.post).toBeCalledWith('/api/session/register/passwordless/sms/verify-passcode', {
|
2022-03-30 15:04:27 +08:00
|
|
|
json: {
|
|
|
|
phone,
|
|
|
|
passcode,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('registerSendEmailPasscode', async () => {
|
|
|
|
await registerSendEmailPasscode(email);
|
2022-04-09 12:20:21 +08:00
|
|
|
expect(ky.post).toBeCalledWith('/api/session/register/passwordless/email/send-passcode', {
|
2022-03-30 15:04:27 +08:00
|
|
|
json: {
|
|
|
|
email,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('registerVerifyEmailPasscode', async () => {
|
|
|
|
await registerVerifyEmailPasscode(email, passcode);
|
2022-04-09 12:20:21 +08:00
|
|
|
expect(ky.post).toBeCalledWith('/api/session/register/passwordless/email/verify-passcode', {
|
2022-03-30 15:04:27 +08:00
|
|
|
json: {
|
|
|
|
email,
|
|
|
|
passcode,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2022-04-09 12:20:21 +08:00
|
|
|
|
2022-04-12 15:03:38 +08:00
|
|
|
it('invokeSocialSignIn', async () => {
|
|
|
|
await invokeSocialSignIn('connectorId', 'state', 'redirectUri');
|
2022-04-09 12:20:21 +08:00
|
|
|
expect(ky.post).toBeCalledWith('/api/session/sign-in/social', {
|
|
|
|
json: {
|
|
|
|
connectorId: 'connectorId',
|
|
|
|
state: 'state',
|
|
|
|
redirectUri: 'redirectUri',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-04-12 15:03:38 +08:00
|
|
|
it('signInWithSoical', async () => {
|
2022-04-09 12:20:21 +08:00
|
|
|
const parameters = {
|
|
|
|
connectorId: 'connectorId',
|
|
|
|
state: 'state',
|
|
|
|
redirectUri: 'redirectUri',
|
|
|
|
code: 'code',
|
|
|
|
};
|
2022-04-12 15:03:38 +08:00
|
|
|
await signInWithSoical(parameters);
|
2022-04-09 12:20:21 +08:00
|
|
|
expect(ky.post).toBeCalledWith('/api/session/sign-in/social', {
|
|
|
|
json: parameters,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('bindSocialAccount', async () => {
|
|
|
|
await bindSocialAccount('connectorId');
|
|
|
|
expect(ky.post).toBeCalledWith('/api/session/sign-in/bind-social-related-user', {
|
|
|
|
json: {
|
|
|
|
connectorId: 'connectorId',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('registerWithSocial', async () => {
|
|
|
|
await registerWithSocial('connectorId');
|
|
|
|
expect(ky.post).toBeCalledWith('/api/session/register/social', {
|
|
|
|
json: {
|
|
|
|
connectorId: 'connectorId',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2022-03-30 15:04:27 +08:00
|
|
|
});
|