Initial Commit
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* GitHub-shaped userinfo payload.
|
||||
*
|
||||
* Mirrors the documented response of `GET https://api.github.com/user`
|
||||
* closely enough that Better-Auth / next-auth / passport adapters that
|
||||
* accept GitHub IdP responses can run unchanged against the mock.
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
|
||||
export interface GithubUser {
|
||||
readonly id: number;
|
||||
readonly login: string;
|
||||
readonly email: string;
|
||||
readonly avatar_url: string;
|
||||
readonly name: string | null;
|
||||
readonly node_id: string;
|
||||
readonly type: "User";
|
||||
readonly site_admin: boolean;
|
||||
readonly [key: string]: unknown;
|
||||
}
|
||||
|
||||
export interface PrimedGithubInput {
|
||||
readonly id?: number | string;
|
||||
readonly login?: string;
|
||||
readonly email?: string;
|
||||
readonly avatar_url?: string;
|
||||
readonly name?: string | null;
|
||||
readonly node_id?: string;
|
||||
readonly site_admin?: boolean;
|
||||
readonly [key: string]: unknown;
|
||||
}
|
||||
|
||||
export function buildGithubUser(input: PrimedGithubInput = {}): GithubUser {
|
||||
const id =
|
||||
input.id === undefined
|
||||
? 1
|
||||
: typeof input.id === "string"
|
||||
? Number.parseInt(input.id, 10) || 0
|
||||
: input.id;
|
||||
const login = input.login ?? `mock-user-${id}`;
|
||||
const email = input.email ?? `${login}@example.test`;
|
||||
const avatar_url =
|
||||
input.avatar_url ?? `https://avatars.example.test/${login}.png`;
|
||||
const name = input.name === undefined ? login : input.name;
|
||||
const node_id = input.node_id ?? `MDQ6VXNlcjAwMDA${id}`;
|
||||
const site_admin = input.site_admin ?? false;
|
||||
|
||||
const out: GithubUser = {
|
||||
...input,
|
||||
id,
|
||||
login,
|
||||
email,
|
||||
avatar_url,
|
||||
name,
|
||||
node_id,
|
||||
type: "User",
|
||||
site_admin,
|
||||
};
|
||||
return Object.freeze(out);
|
||||
}
|
||||
Reference in New Issue
Block a user