mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
feat(test): add password identifier sign-in flow integration test (#2625)
This commit is contained in:
parent
7b9aaa0b08
commit
d111e5d407
4 changed files with 42 additions and 2 deletions
|
@ -3,10 +3,11 @@ import type { User } from '@logto/schemas';
|
|||
import { authedAdminApi } from './api.js';
|
||||
|
||||
type CreateUserPayload = {
|
||||
primaryPhone?: string;
|
||||
primaryEmail?: string;
|
||||
username: string;
|
||||
username?: string;
|
||||
password: string;
|
||||
name: string;
|
||||
name?: string;
|
||||
};
|
||||
|
||||
export const createUser = (payload: CreateUserPayload) =>
|
||||
|
|
|
@ -8,5 +8,6 @@ export * from './logs.js';
|
|||
export * from './dashboard.js';
|
||||
export * from './me.js';
|
||||
export * from './wellknown.js';
|
||||
export * from './interaction.js';
|
||||
|
||||
export { default as api, authedAdminApi } from './api.js';
|
||||
|
|
37
packages/integration-tests/src/api/interaction.ts
Normal file
37
packages/integration-tests/src/api/interaction.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
import { Event } from '@logto/schemas';
|
||||
import type {
|
||||
IdentifierPayload,
|
||||
PhonePasswordPayload,
|
||||
EmailPasswordPayload,
|
||||
Profile,
|
||||
UsernamePasswordPayload,
|
||||
} from '@logto/schemas';
|
||||
|
||||
import api from './api.js';
|
||||
|
||||
export type RedirectResponse = {
|
||||
redirectTo: string;
|
||||
};
|
||||
|
||||
export type interactionPayload = {
|
||||
event: Event;
|
||||
identifier?: IdentifierPayload;
|
||||
profile?: Profile;
|
||||
};
|
||||
|
||||
export const signInWithPasswordIdentifiers = async (
|
||||
identifier: UsernamePasswordPayload | EmailPasswordPayload | PhonePasswordPayload,
|
||||
cookie: string
|
||||
) =>
|
||||
api
|
||||
.put('interaction', {
|
||||
headers: {
|
||||
cookie,
|
||||
},
|
||||
json: {
|
||||
event: Event.SignIn,
|
||||
identifier,
|
||||
},
|
||||
followRedirect: false,
|
||||
})
|
||||
.json<RedirectResponse>();
|
|
@ -6,6 +6,7 @@ export const extractCookie = (response: Response) => {
|
|||
return headers['set-cookie']?.join('; ') ?? '';
|
||||
};
|
||||
|
||||
export const generateName = () => crypto.randomUUID();
|
||||
export const generateUsername = () => `usr_${crypto.randomUUID().replaceAll('-', '_')}`;
|
||||
export const generatePassword = () => `pwd_${crypto.randomUUID()}`;
|
||||
|
||||
|
|
Loading…
Reference in a new issue