mirror of
https://github.com/logto-io/logto.git
synced 2025-01-06 20:40:08 -05:00
feat(ui): add password less related api (#459)
* feat(ui): add password less related api add password less related api * test(ui): add api ut add api ut
This commit is contained in:
parent
10fc7e4205
commit
0444efd844
3 changed files with 238 additions and 0 deletions
138
packages/ui/src/apis/index.test.ts
Normal file
138
packages/ui/src/apis/index.test.ts
Normal file
|
@ -0,0 +1,138 @@
|
|||
import ky from 'ky';
|
||||
|
||||
import { consent } from './consent';
|
||||
import {
|
||||
register,
|
||||
sendEmailPasscode as registerSendEmailPasscode,
|
||||
sendPhonePasscode as registerSendPhonePasscode,
|
||||
verifyEmailPasscode as registerVerifyEmailPasscode,
|
||||
verifyPhonePasscode as registerVerifyPhonePasscode,
|
||||
} from './register';
|
||||
import {
|
||||
signInBasic,
|
||||
sendPhonePasscode,
|
||||
sendEmailPasscode,
|
||||
verifyEmailPasscode,
|
||||
verifyPhonePasscode,
|
||||
} from './sign-in';
|
||||
|
||||
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,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('sendPhonePasscode', async () => {
|
||||
await sendPhonePasscode(phone);
|
||||
expect(ky.post).toBeCalledWith('/session/sign-in/passwordless/phone/send-passcode', {
|
||||
json: {
|
||||
phone,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('verifyPhonePasscode', async () => {
|
||||
await verifyPhonePasscode(phone, passcode);
|
||||
expect(ky.post).toBeCalledWith('/session/sign-in/passwordless/phone/verify-passcode', {
|
||||
json: {
|
||||
phone,
|
||||
passcode,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('sendEmailPasscode', async () => {
|
||||
await sendEmailPasscode(email);
|
||||
expect(ky.post).toBeCalledWith('/session/sign-in/passwordless/email/send-passcode', {
|
||||
json: {
|
||||
email,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('verifyEmailPasscode', async () => {
|
||||
await verifyEmailPasscode(email, passcode);
|
||||
expect(ky.post).toBeCalledWith('/session/sign-in/passwordless/email/verify-passcode', {
|
||||
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,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('registerSendPhonePasscode', async () => {
|
||||
await registerSendPhonePasscode(phone);
|
||||
expect(ky.post).toBeCalledWith('/session/register/passwordless/phone/send-passcode', {
|
||||
json: {
|
||||
phone,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('registerVerifyPhonePasscode', async () => {
|
||||
await registerVerifyPhonePasscode(phone, passcode);
|
||||
expect(ky.post).toBeCalledWith('/session/register/passwordless/phone/verify-passcode', {
|
||||
json: {
|
||||
phone,
|
||||
passcode,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('registerSendEmailPasscode', async () => {
|
||||
await registerSendEmailPasscode(email);
|
||||
expect(ky.post).toBeCalledWith('/session/register/passwordless/email/send-passcode', {
|
||||
json: {
|
||||
email,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('registerVerifyEmailPasscode', async () => {
|
||||
await registerVerifyEmailPasscode(email, passcode);
|
||||
expect(ky.post).toBeCalledWith('/session/register/passwordless/email/verify-passcode', {
|
||||
json: {
|
||||
email,
|
||||
passcode,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
|
@ -14,3 +14,53 @@ export const register = async (username: string, password: string) => {
|
|||
})
|
||||
.json<Response>();
|
||||
};
|
||||
|
||||
export const sendPhonePasscode = async (phone: string) => {
|
||||
return ky
|
||||
.post('/session/register/passwordless/phone/send-passcode', {
|
||||
json: {
|
||||
phone,
|
||||
},
|
||||
})
|
||||
.json();
|
||||
};
|
||||
|
||||
export const verifyPhonePasscode = async (phone: string, passcode: string) => {
|
||||
type Response = {
|
||||
redirectTo: string;
|
||||
};
|
||||
|
||||
return ky
|
||||
.post('/session/register/passwordless/phone/verify-passcode', {
|
||||
json: {
|
||||
phone,
|
||||
passcode,
|
||||
},
|
||||
})
|
||||
.json<Response>();
|
||||
};
|
||||
|
||||
export const sendEmailPasscode = async (email: string) => {
|
||||
return ky
|
||||
.post('/session/register/passwordless/email/send-passcode', {
|
||||
json: {
|
||||
email,
|
||||
},
|
||||
})
|
||||
.json();
|
||||
};
|
||||
|
||||
export const verifyEmailPasscode = async (email: string, passcode: string) => {
|
||||
type Response = {
|
||||
redirectTo: string;
|
||||
};
|
||||
|
||||
return ky
|
||||
.post('/session/register/passwordless/email/verify-passcode', {
|
||||
json: {
|
||||
email,
|
||||
passcode,
|
||||
},
|
||||
})
|
||||
.json<Response>();
|
||||
};
|
||||
|
|
|
@ -14,3 +14,53 @@ export const signInBasic = async (username: string, password: string) => {
|
|||
})
|
||||
.json<Response>();
|
||||
};
|
||||
|
||||
export const sendPhonePasscode = async (phone: string) => {
|
||||
return ky
|
||||
.post('/session/sign-in/passwordless/phone/send-passcode', {
|
||||
json: {
|
||||
phone,
|
||||
},
|
||||
})
|
||||
.json();
|
||||
};
|
||||
|
||||
export const verifyPhonePasscode = async (phone: string, passcode: string) => {
|
||||
type Response = {
|
||||
redirectTo: string;
|
||||
};
|
||||
|
||||
return ky
|
||||
.post('/session/sign-in/passwordless/phone/verify-passcode', {
|
||||
json: {
|
||||
phone,
|
||||
passcode,
|
||||
},
|
||||
})
|
||||
.json<Response>();
|
||||
};
|
||||
|
||||
export const sendEmailPasscode = async (email: string) => {
|
||||
return ky
|
||||
.post('/session/sign-in/passwordless/email/send-passcode', {
|
||||
json: {
|
||||
email,
|
||||
},
|
||||
})
|
||||
.json();
|
||||
};
|
||||
|
||||
export const verifyEmailPasscode = async (email: string, passcode: string) => {
|
||||
type Response = {
|
||||
redirectTo: string;
|
||||
};
|
||||
|
||||
return ky
|
||||
.post('/session/sign-in/passwordless/email/verify-passcode', {
|
||||
json: {
|
||||
email,
|
||||
passcode,
|
||||
},
|
||||
})
|
||||
.json<Response>();
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue