feat(api): 🎨 Allow login with either username or email

This commit is contained in:
Jesse Wierzbinski 2024-05-08 08:02:05 +00:00
parent 47c88dd7dd
commit f9c9a7d527
No known key found for this signature in database
7 changed files with 260 additions and 62 deletions

View file

@ -1,3 +1,6 @@
/**
* @deprecated
*/
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import { eq } from "drizzle-orm";

View file

@ -1,9 +1,11 @@
/**
* @deprecated
*/
import { afterAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import { getTestUsers, sendTestRequest, wrapRelativeUrl } from "~tests/utils";
import type { Account as APIAccount } from "~types/mastodon/account";
import type { Relationship as APIRelationship } from "~types/mastodon/relationship";
import type { Status as APIStatus } from "~types/mastodon/status";
const base_url = config.http.base_url;
@ -105,33 +107,6 @@ describe("API Tests", () => {
});
});
describe("GET /api/v1/accounts/:id/statuses", () => {
test("should return the statuses of the specified user", async () => {
const response = await sendTestRequest(
new Request(
wrapRelativeUrl(
`/api/v1/accounts/${user.id}/statuses`,
base_url,
),
{
headers: {
Authorization: `Bearer ${token.accessToken}`,
},
},
),
);
expect(response.status).toBe(200);
expect(response.headers.get("content-type")).toBe(
"application/json",
);
const statuses = (await response.json()) as APIStatus[];
expect(statuses.length).toBe(0);
});
});
describe("POST /api/v1/accounts/:id/remove_from_followers", () => {
test("should remove the specified user from the authenticated user's followers and return an APIRelationship object", async () => {
const response = await sendTestRequest(

View file

@ -1,3 +1,6 @@
/**
* @deprecated
*/
import { afterAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import { getTestUsers, sendTestRequest, wrapRelativeUrl } from "~tests/utils";

View file

@ -1,13 +1,11 @@
/**
* @deprecated
*/
import { afterAll, describe, expect, test } from "bun:test";
import { config } from "~packages/config-manager";
import type { Application as APIApplication } from "~types/mastodon/application";
import type { Token as APIToken } from "~types/mastodon/token";
import {
deleteOldTestUsers,
getTestUsers,
sendTestRequest,
wrapRelativeUrl,
} from "./utils";
import { getTestUsers, sendTestRequest, wrapRelativeUrl } from "./utils";
const base_url = config.http.base_url;
@ -70,7 +68,7 @@ describe("POST /api/auth/login/", () => {
test("should get a JWT", async () => {
const formData = new FormData();
formData.append("email", users[0]?.getUser().email ?? "");
formData.append("identifier", users[0]?.getUser().email ?? "");
formData.append("password", passwords[0]);
const response = await sendTestRequest(
@ -87,21 +85,6 @@ describe("POST /api/auth/login/", () => {
);
expect(response.status).toBe(302);
expect(response.headers.get("location")).toBeDefined();
const locationHeader = new URL(
response.headers.get("Location") ?? "",
"",
);
expect(locationHeader.pathname).toBe("/oauth/consent");
expect(locationHeader.searchParams.get("client_id")).toBe(client_id);
expect(locationHeader.searchParams.get("redirect_uri")).toBe(
"https://example.com",
);
expect(locationHeader.searchParams.get("response_type")).toBe("code");
expect(locationHeader.searchParams.get("scope")).toBe("read write");
expect(response.headers.get("Set-Cookie")).toMatch(/jwt=[^;]+;/);
jwt =
response.headers.get("Set-Cookie")?.match(/jwt=([^;]+);/)?.[1] ??