feat(pwa): tg verified-login api (tgSession/tgPoll) + schemas
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { describe, it, expect } from "vitest";
|
import { describe, it, expect } from "vitest";
|
||||||
import { BalanceSchema, TopupSchema, PaymentsSchema, AuthRequestSchema } from "./driver";
|
import { BalanceSchema, TopupSchema, PaymentsSchema, AuthRequestSchema, TgSessionSchema, TgPollSchema } from "./driver";
|
||||||
|
|
||||||
describe("driver api schemas", () => {
|
describe("driver api schemas", () => {
|
||||||
it("parses balance", () => {
|
it("parses balance", () => {
|
||||||
@@ -24,3 +24,16 @@ describe("driver api schemas", () => {
|
|||||||
expect(v.payments[0].status).toBe("PAID");
|
expect(v.payments[0].status).toBe("PAID");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("tg verified-login schemas", () => {
|
||||||
|
it("parses tg session", () => {
|
||||||
|
const v = TgSessionSchema.parse({ pair_session: "S", deep_link: "https://t.me/x?start=S" });
|
||||||
|
expect(v.pair_session).toBe("S");
|
||||||
|
});
|
||||||
|
it("parses tg poll states", () => {
|
||||||
|
expect(TgPollSchema.parse({ status: "pending" }).status).toBe("pending");
|
||||||
|
expect(TgPollSchema.parse({ status: "expired" }).status).toBe("expired");
|
||||||
|
const a = TgPollSchema.parse({ status: "authenticated", token: "T", driver_id: 7 });
|
||||||
|
expect(a.status === "authenticated" && a.token).toBe("T");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -24,6 +24,21 @@ export const PaymentsSchema = z.object({
|
|||||||
})),
|
})),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const TgSessionSchema = z.object({
|
||||||
|
pair_session: z.string(),
|
||||||
|
deep_link: z.string().nullable(),
|
||||||
|
});
|
||||||
|
export const TgPollSchema = z.union([
|
||||||
|
z.object({ status: z.literal("pending") }),
|
||||||
|
z.object({ status: z.literal("expired") }),
|
||||||
|
z.object({ status: z.literal("authenticated"), token: z.string(), driver_id: z.number() }),
|
||||||
|
]);
|
||||||
|
|
||||||
|
export const tgSession = async () =>
|
||||||
|
TgSessionSchema.parse(await api.post("driver/auth/tg/session").json());
|
||||||
|
export const tgPoll = async (pairSession: string) =>
|
||||||
|
TgPollSchema.parse(await api.get("driver/auth/tg/poll", { searchParams: { pair_session: pairSession } }).json());
|
||||||
|
|
||||||
export const authRequest = async (phone: string) =>
|
export const authRequest = async (phone: string) =>
|
||||||
AuthRequestSchema.parse(await api.post("driver/auth/request", { json: { phone } }).json());
|
AuthRequestSchema.parse(await api.post("driver/auth/request", { json: { phone } }).json());
|
||||||
export const authVerify = async (phone: string, code: string) =>
|
export const authVerify = async (phone: string, code: string) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user