mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor: 🚨 Turn every linter rule on and fix issues (there were a LOT :3)
This commit is contained in:
parent
2e98859153
commit
a1e02d0d78
177 changed files with 1826 additions and 1248 deletions
|
|
@ -2,7 +2,7 @@ import { afterAll, describe, expect, test } from "bun:test";
|
|||
import { config } from "config-manager";
|
||||
import { getTestUsers, sendTestRequest, wrapRelativeUrl } from "./utils";
|
||||
|
||||
const base_url = config.http.base_url;
|
||||
const baseUrl = config.http.base_url;
|
||||
|
||||
const { tokens, deleteUsers } = await getTestUsers(1);
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ describe("API Tests", () => {
|
|||
|
||||
const response = await sendTestRequest(
|
||||
new Request(
|
||||
wrapRelativeUrl(`${base_url}/api/v1/statuses`, base_url),
|
||||
wrapRelativeUrl(`${baseUrl}/api/v1/statuses`, baseUrl),
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@
|
|||
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 { Account as apiAccount } from "~/types/mastodon/account";
|
||||
import type { Relationship as apiRelationship } from "~/types/mastodon/relationship";
|
||||
|
||||
const base_url = config.http.base_url;
|
||||
const baseUrl = config.http.base_url;
|
||||
|
||||
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
||||
const user = users[0];
|
||||
|
|
@ -31,7 +31,7 @@ describe("API Tests", () => {
|
|||
new Request(
|
||||
wrapRelativeUrl(
|
||||
"/api/v1/accounts/update_credentials",
|
||||
base_url,
|
||||
baseUrl,
|
||||
),
|
||||
{
|
||||
method: "PATCH",
|
||||
|
|
@ -50,7 +50,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const user = (await response.json()) as APIAccount;
|
||||
const user = (await response.json()) as apiAccount;
|
||||
|
||||
expect(user.display_name).toBe("New Display Name");
|
||||
});
|
||||
|
|
@ -62,7 +62,7 @@ describe("API Tests", () => {
|
|||
new Request(
|
||||
wrapRelativeUrl(
|
||||
"/api/v1/accounts/verify_credentials",
|
||||
base_url,
|
||||
baseUrl,
|
||||
),
|
||||
{
|
||||
headers: {
|
||||
|
|
@ -77,7 +77,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const account = (await response.json()) as APIAccount;
|
||||
const account = (await response.json()) as apiAccount;
|
||||
|
||||
expect(account.username).toBe(user.data.username);
|
||||
expect(account.bot).toBe(false);
|
||||
|
|
@ -113,7 +113,7 @@ describe("API Tests", () => {
|
|||
new Request(
|
||||
wrapRelativeUrl(
|
||||
`/api/v1/accounts/${user2.id}/remove_from_followers`,
|
||||
base_url,
|
||||
baseUrl,
|
||||
),
|
||||
{
|
||||
method: "POST",
|
||||
|
|
@ -131,7 +131,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const account = (await response.json()) as APIRelationship;
|
||||
const account = (await response.json()) as apiRelationship;
|
||||
|
||||
expect(account.id).toBe(user2.id);
|
||||
expect(account.followed_by).toBe(false);
|
||||
|
|
@ -144,7 +144,7 @@ describe("API Tests", () => {
|
|||
new Request(
|
||||
wrapRelativeUrl(
|
||||
`/api/v1/accounts/${user2.id}/block`,
|
||||
base_url,
|
||||
baseUrl,
|
||||
),
|
||||
{
|
||||
method: "POST",
|
||||
|
|
@ -162,7 +162,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const account = (await response.json()) as APIRelationship;
|
||||
const account = (await response.json()) as apiRelationship;
|
||||
|
||||
expect(account.id).toBe(user2.id);
|
||||
expect(account.blocking).toBe(true);
|
||||
|
|
@ -172,7 +172,7 @@ describe("API Tests", () => {
|
|||
describe("GET /api/v1/blocks", () => {
|
||||
test("should return an array of APIAccount objects for the user's blocked accounts", async () => {
|
||||
const response = await sendTestRequest(
|
||||
new Request(wrapRelativeUrl("/api/v1/blocks", base_url), {
|
||||
new Request(wrapRelativeUrl("/api/v1/blocks", baseUrl), {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `Bearer ${token.accessToken}`,
|
||||
|
|
@ -184,7 +184,7 @@ describe("API Tests", () => {
|
|||
expect(response.headers.get("content-type")).toBe(
|
||||
"application/json",
|
||||
);
|
||||
const body = (await response.json()) as APIAccount[];
|
||||
const body = (await response.json()) as apiAccount[];
|
||||
|
||||
expect(Array.isArray(body)).toBe(true);
|
||||
expect(body.length).toBe(1);
|
||||
|
|
@ -198,7 +198,7 @@ describe("API Tests", () => {
|
|||
new Request(
|
||||
wrapRelativeUrl(
|
||||
`/api/v1/accounts/${user2.id}/unblock`,
|
||||
base_url,
|
||||
baseUrl,
|
||||
),
|
||||
{
|
||||
method: "POST",
|
||||
|
|
@ -216,7 +216,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const account = (await response.json()) as APIRelationship;
|
||||
const account = (await response.json()) as apiRelationship;
|
||||
|
||||
expect(account.id).toBe(user2.id);
|
||||
expect(account.blocking).toBe(false);
|
||||
|
|
@ -229,7 +229,7 @@ describe("API Tests", () => {
|
|||
new Request(
|
||||
wrapRelativeUrl(
|
||||
`/api/v1/accounts/${user2.id}/pin`,
|
||||
base_url,
|
||||
baseUrl,
|
||||
),
|
||||
{
|
||||
method: "POST",
|
||||
|
|
@ -247,7 +247,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const account = (await response.json()) as APIRelationship;
|
||||
const account = (await response.json()) as apiRelationship;
|
||||
|
||||
expect(account.id).toBe(user2.id);
|
||||
expect(account.endorsed).toBe(true);
|
||||
|
|
@ -260,7 +260,7 @@ describe("API Tests", () => {
|
|||
new Request(
|
||||
wrapRelativeUrl(
|
||||
`/api/v1/accounts/${user2.id}/unpin`,
|
||||
base_url,
|
||||
baseUrl,
|
||||
),
|
||||
{
|
||||
method: "POST",
|
||||
|
|
@ -278,7 +278,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const account = (await response.json()) as APIRelationship;
|
||||
const account = (await response.json()) as apiRelationship;
|
||||
|
||||
expect(account.id).toBe(user2.id);
|
||||
expect(account.endorsed).toBe(false);
|
||||
|
|
@ -291,7 +291,7 @@ describe("API Tests", () => {
|
|||
new Request(
|
||||
wrapRelativeUrl(
|
||||
`/api/v1/accounts/${user2.id}/note`,
|
||||
base_url,
|
||||
baseUrl,
|
||||
),
|
||||
{
|
||||
method: "POST",
|
||||
|
|
@ -309,7 +309,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const account = (await response.json()) as APIAccount;
|
||||
const account = (await response.json()) as apiAccount;
|
||||
|
||||
expect(account.id).toBe(user2.id);
|
||||
expect(account.note).toBe("This is a new note");
|
||||
|
|
@ -322,7 +322,7 @@ describe("API Tests", () => {
|
|||
new Request(
|
||||
wrapRelativeUrl(
|
||||
`/api/v1/accounts/relationships?id[]=${user2.id}`,
|
||||
base_url,
|
||||
baseUrl,
|
||||
),
|
||||
{
|
||||
method: "GET",
|
||||
|
|
@ -338,7 +338,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const relationships = (await response.json()) as APIRelationship[];
|
||||
const relationships = (await response.json()) as apiRelationship[];
|
||||
|
||||
expect(Array.isArray(relationships)).toBe(true);
|
||||
expect(relationships.length).toBeGreaterThan(0);
|
||||
|
|
@ -358,7 +358,7 @@ describe("API Tests", () => {
|
|||
test("should delete the avatar of the authenticated user and return the updated account object", async () => {
|
||||
const response = await sendTestRequest(
|
||||
new Request(
|
||||
wrapRelativeUrl("/api/v1/profile/avatar", base_url),
|
||||
wrapRelativeUrl("/api/v1/profile/avatar", baseUrl),
|
||||
{
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
|
|
@ -373,7 +373,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const account = (await response.json()) as APIAccount;
|
||||
const account = (await response.json()) as apiAccount;
|
||||
|
||||
expect(account.id).toBeDefined();
|
||||
expect(account.avatar).toBeDefined();
|
||||
|
|
@ -384,7 +384,7 @@ describe("API Tests", () => {
|
|||
test("should delete the header of the authenticated user and return the updated account object", async () => {
|
||||
const response = await sendTestRequest(
|
||||
new Request(
|
||||
wrapRelativeUrl("/api/v1/profile/header", base_url),
|
||||
wrapRelativeUrl("/api/v1/profile/header", baseUrl),
|
||||
{
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
|
|
@ -399,7 +399,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const account = (await response.json()) as APIAccount;
|
||||
const account = (await response.json()) as apiAccount;
|
||||
|
||||
expect(account.id).toBeDefined();
|
||||
expect(account.header).toBe("");
|
||||
|
|
@ -412,7 +412,7 @@ describe("API Tests", () => {
|
|||
new Request(
|
||||
wrapRelativeUrl(
|
||||
`/api/v1/accounts/${user2.id}/follow`,
|
||||
base_url,
|
||||
baseUrl,
|
||||
),
|
||||
{
|
||||
method: "POST",
|
||||
|
|
@ -436,7 +436,7 @@ describe("API Tests", () => {
|
|||
new Request(
|
||||
wrapRelativeUrl(
|
||||
`/api/v1/accounts/familiar_followers?id[]=${user2.id}`,
|
||||
base_url,
|
||||
baseUrl,
|
||||
),
|
||||
{
|
||||
method: "GET",
|
||||
|
|
@ -454,7 +454,7 @@ describe("API Tests", () => {
|
|||
|
||||
const familiarFollowers = (await response.json()) as {
|
||||
id: string;
|
||||
accounts: APIAccount[];
|
||||
accounts: apiAccount[];
|
||||
}[];
|
||||
|
||||
expect(Array.isArray(familiarFollowers)).toBe(true);
|
||||
|
|
|
|||
|
|
@ -4,18 +4,18 @@
|
|||
import { afterAll, describe, expect, test } from "bun:test";
|
||||
import { config } from "config-manager";
|
||||
import { getTestUsers, sendTestRequest, wrapRelativeUrl } from "~/tests/utils";
|
||||
import type { AsyncAttachment as APIAsyncAttachment } from "~/types/mastodon/async_attachment";
|
||||
import type { Context as APIContext } from "~/types/mastodon/context";
|
||||
import type { Status as APIStatus } from "~/types/mastodon/status";
|
||||
import type { AsyncAttachment as apiAsyncAttachment } from "~/types/mastodon/async_attachment";
|
||||
import type { Context as apiContext } from "~/types/mastodon/context";
|
||||
import type { Status as apiStatus } from "~/types/mastodon/status";
|
||||
|
||||
const base_url = config.http.base_url;
|
||||
const baseUrl = config.http.base_url;
|
||||
|
||||
const { users, tokens, deleteUsers } = await getTestUsers(1);
|
||||
const user = users[0];
|
||||
const token = tokens[0];
|
||||
let status: APIStatus | null = null;
|
||||
let status2: APIStatus | null = null;
|
||||
let media1: APIAsyncAttachment | null = null;
|
||||
let status: apiStatus | null = null;
|
||||
let status2: apiStatus | null = null;
|
||||
let media1: apiAsyncAttachment | null = null;
|
||||
|
||||
describe("API Tests", () => {
|
||||
afterAll(async () => {
|
||||
|
|
@ -29,7 +29,7 @@ describe("API Tests", () => {
|
|||
|
||||
const response = await sendTestRequest(
|
||||
new Request(
|
||||
wrapRelativeUrl(`${base_url}/api/v2/media`, base_url),
|
||||
wrapRelativeUrl(`${baseUrl}/api/v2/media`, baseUrl),
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
|
@ -45,7 +45,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
media1 = (await response.json()) as APIAsyncAttachment;
|
||||
media1 = (await response.json()) as apiAsyncAttachment;
|
||||
|
||||
expect(media1.id).toBeDefined();
|
||||
expect(media1.type).toBe("unknown");
|
||||
|
|
@ -57,7 +57,7 @@ describe("API Tests", () => {
|
|||
test("should create a new status and return an APIStatus object", async () => {
|
||||
const response = await sendTestRequest(
|
||||
new Request(
|
||||
wrapRelativeUrl(`${base_url}/api/v1/statuses`, base_url),
|
||||
wrapRelativeUrl(`${baseUrl}/api/v1/statuses`, baseUrl),
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
|
@ -78,7 +78,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
status = (await response.json()) as APIStatus;
|
||||
status = (await response.json()) as apiStatus;
|
||||
expect(status.content).toContain("Hello, world!");
|
||||
expect(status.visibility).toBe("public");
|
||||
expect(status.account.id).toBe(user.id);
|
||||
|
|
@ -104,7 +104,7 @@ describe("API Tests", () => {
|
|||
test("should create a new status in reply to the previous one", async () => {
|
||||
const response = await sendTestRequest(
|
||||
new Request(
|
||||
wrapRelativeUrl(`${base_url}/api/v1/statuses`, base_url),
|
||||
wrapRelativeUrl(`${baseUrl}/api/v1/statuses`, baseUrl),
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
|
@ -125,7 +125,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
status2 = (await response.json()) as APIStatus;
|
||||
status2 = (await response.json()) as apiStatus;
|
||||
expect(status2.content).toContain("This is a reply!");
|
||||
expect(status2.visibility).toBe("public");
|
||||
expect(status2.account.id).toBe(user.id);
|
||||
|
|
@ -154,8 +154,8 @@ describe("API Tests", () => {
|
|||
const response = await sendTestRequest(
|
||||
new Request(
|
||||
wrapRelativeUrl(
|
||||
`${base_url}/api/v1/statuses/${status?.id}`,
|
||||
base_url,
|
||||
`${baseUrl}/api/v1/statuses/${status?.id}`,
|
||||
baseUrl,
|
||||
),
|
||||
{
|
||||
headers: {
|
||||
|
|
@ -170,7 +170,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const statusJson = (await response.json()) as APIStatus;
|
||||
const statusJson = (await response.json()) as apiStatus;
|
||||
|
||||
expect(statusJson.id).toBe(status?.id || "");
|
||||
expect(statusJson.content).toBeDefined();
|
||||
|
|
@ -203,8 +203,8 @@ describe("API Tests", () => {
|
|||
const response = await sendTestRequest(
|
||||
new Request(
|
||||
wrapRelativeUrl(
|
||||
`${base_url}/api/v1/statuses/${status?.id}/reblog`,
|
||||
base_url,
|
||||
`${baseUrl}/api/v1/statuses/${status?.id}/reblog`,
|
||||
baseUrl,
|
||||
),
|
||||
{
|
||||
method: "POST",
|
||||
|
|
@ -220,7 +220,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const rebloggedStatus = (await response.json()) as APIStatus;
|
||||
const rebloggedStatus = (await response.json()) as apiStatus;
|
||||
|
||||
expect(rebloggedStatus.id).toBeDefined();
|
||||
expect(rebloggedStatus.reblog?.id).toEqual(status?.id ?? "");
|
||||
|
|
@ -233,8 +233,8 @@ describe("API Tests", () => {
|
|||
const response = await sendTestRequest(
|
||||
new Request(
|
||||
wrapRelativeUrl(
|
||||
`${base_url}/api/v1/statuses/${status?.id}/unreblog`,
|
||||
base_url,
|
||||
`${baseUrl}/api/v1/statuses/${status?.id}/unreblog`,
|
||||
baseUrl,
|
||||
),
|
||||
{
|
||||
method: "POST",
|
||||
|
|
@ -250,7 +250,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const unrebloggedStatus = (await response.json()) as APIStatus;
|
||||
const unrebloggedStatus = (await response.json()) as apiStatus;
|
||||
|
||||
expect(unrebloggedStatus.id).toBeDefined();
|
||||
expect(unrebloggedStatus.reblogged).toBe(false);
|
||||
|
|
@ -262,8 +262,8 @@ describe("API Tests", () => {
|
|||
const response = await sendTestRequest(
|
||||
new Request(
|
||||
wrapRelativeUrl(
|
||||
`${base_url}/api/v1/statuses/${status?.id}/context`,
|
||||
base_url,
|
||||
`${baseUrl}/api/v1/statuses/${status?.id}/context`,
|
||||
baseUrl,
|
||||
),
|
||||
{
|
||||
headers: {
|
||||
|
|
@ -278,7 +278,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const context = (await response.json()) as APIContext;
|
||||
const context = (await response.json()) as apiContext;
|
||||
|
||||
expect(context.ancestors.length).toBe(0);
|
||||
expect(context.descendants.length).toBe(1);
|
||||
|
|
@ -293,8 +293,8 @@ describe("API Tests", () => {
|
|||
const response = await sendTestRequest(
|
||||
new Request(
|
||||
wrapRelativeUrl(
|
||||
`${base_url}/api/v1/accounts/${user.id}/statuses`,
|
||||
base_url,
|
||||
`${baseUrl}/api/v1/accounts/${user.id}/statuses`,
|
||||
baseUrl,
|
||||
),
|
||||
{
|
||||
method: "GET",
|
||||
|
|
@ -310,7 +310,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const statuses = (await response.json()) as APIStatus[];
|
||||
const statuses = (await response.json()) as apiStatus[];
|
||||
|
||||
expect(statuses.length).toBe(2);
|
||||
|
||||
|
|
@ -328,8 +328,8 @@ describe("API Tests", () => {
|
|||
const response = await sendTestRequest(
|
||||
new Request(
|
||||
wrapRelativeUrl(
|
||||
`${base_url}/api/v1/statuses/${status?.id}/favourite`,
|
||||
base_url,
|
||||
`${baseUrl}/api/v1/statuses/${status?.id}/favourite`,
|
||||
baseUrl,
|
||||
),
|
||||
{
|
||||
method: "POST",
|
||||
|
|
@ -350,8 +350,8 @@ describe("API Tests", () => {
|
|||
const response = await sendTestRequest(
|
||||
new Request(
|
||||
wrapRelativeUrl(
|
||||
`${base_url}/api/v1/statuses/${status?.id}/unfavourite`,
|
||||
base_url,
|
||||
`${baseUrl}/api/v1/statuses/${status?.id}/unfavourite`,
|
||||
baseUrl,
|
||||
),
|
||||
{
|
||||
method: "POST",
|
||||
|
|
@ -367,7 +367,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const updatedStatus = (await response.json()) as APIStatus;
|
||||
const updatedStatus = (await response.json()) as apiStatus;
|
||||
|
||||
expect(updatedStatus.favourited).toBe(false);
|
||||
expect(updatedStatus.favourites_count).toBe(0);
|
||||
|
|
@ -379,8 +379,8 @@ describe("API Tests", () => {
|
|||
const response = await sendTestRequest(
|
||||
new Request(
|
||||
wrapRelativeUrl(
|
||||
`${base_url}/api/v1/statuses/${status?.id}`,
|
||||
base_url,
|
||||
`${baseUrl}/api/v1/statuses/${status?.id}`,
|
||||
baseUrl,
|
||||
),
|
||||
{
|
||||
method: "DELETE",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { describe, expect, it } from "bun:test";
|
||||
import { checkIfOauthIsValid } from "@/oauth";
|
||||
import type { Application } from "~/database/entities/Application";
|
||||
import type { Application } from "~/database/entities/application";
|
||||
|
||||
describe("checkIfOauthIsValid", () => {
|
||||
it("should return true when routeScopes and application.scopes are empty", () => {
|
||||
|
|
|
|||
|
|
@ -3,17 +3,17 @@
|
|||
*/
|
||||
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 type { Application as apiApplication } from "~/types/mastodon/application";
|
||||
import type { Token as apiToken } from "~/types/mastodon/token";
|
||||
import { getTestUsers, sendTestRequest, wrapRelativeUrl } from "./utils";
|
||||
|
||||
const base_url = config.http.base_url;
|
||||
const baseUrl = config.http.base_url;
|
||||
|
||||
let client_id: string;
|
||||
let client_secret: string;
|
||||
let clientId: string;
|
||||
let clientSecret: string;
|
||||
let code: string;
|
||||
let jwt: string;
|
||||
let token: APIToken;
|
||||
let token: apiToken;
|
||||
const { users, passwords, deleteUsers } = await getTestUsers(1);
|
||||
|
||||
afterAll(async () => {
|
||||
|
|
@ -59,8 +59,8 @@ describe("POST /api/v1/apps/", () => {
|
|||
vapid_link: null,
|
||||
});
|
||||
|
||||
client_id = json.client_id;
|
||||
client_secret = json.client_secret;
|
||||
clientId = json.client_id;
|
||||
clientSecret = json.client_secret;
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -74,8 +74,8 @@ describe("POST /api/auth/login/", () => {
|
|||
const response = await sendTestRequest(
|
||||
new Request(
|
||||
new URL(
|
||||
`/api/auth/login?client_id=${client_id}&redirect_uri=https://example.com&response_type=code&scope=read+write`,
|
||||
base_url,
|
||||
`/api/auth/login?client_id=${clientId}&redirect_uri=https://example.com&response_type=code&scope=read+write`,
|
||||
baseUrl,
|
||||
),
|
||||
{
|
||||
method: "POST",
|
||||
|
|
@ -95,14 +95,14 @@ describe("POST /api/auth/login/", () => {
|
|||
describe("GET /oauth/authorize/", () => {
|
||||
test("should get a code", async () => {
|
||||
const response = await sendTestRequest(
|
||||
new Request(new URL("/oauth/authorize", base_url), {
|
||||
new Request(new URL("/oauth/authorize", baseUrl), {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Cookie: `jwt=${jwt}`,
|
||||
},
|
||||
body: new URLSearchParams({
|
||||
client_id,
|
||||
client_secret,
|
||||
client_id: clientId,
|
||||
client_secret: clientSecret,
|
||||
redirect_uri: "https://example.com",
|
||||
response_type: "code",
|
||||
scope: "read write",
|
||||
|
|
@ -127,7 +127,7 @@ describe("GET /oauth/authorize/", () => {
|
|||
describe("POST /oauth/token/", () => {
|
||||
test("should get an access token", async () => {
|
||||
const response = await sendTestRequest(
|
||||
new Request(wrapRelativeUrl("/oauth/token", base_url), {
|
||||
new Request(wrapRelativeUrl("/oauth/token", baseUrl), {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${jwt}`,
|
||||
|
|
@ -137,8 +137,8 @@ describe("POST /oauth/token/", () => {
|
|||
grant_type: "authorization_code",
|
||||
code,
|
||||
redirect_uri: "https://example.com",
|
||||
client_id,
|
||||
client_secret,
|
||||
client_id: clientId,
|
||||
client_secret: clientSecret,
|
||||
scope: "read write",
|
||||
}),
|
||||
}),
|
||||
|
|
@ -166,7 +166,7 @@ describe("GET /api/v1/apps/verify_credentials", () => {
|
|||
test("should return the authenticated application's credentials", async () => {
|
||||
const response = await sendTestRequest(
|
||||
new Request(
|
||||
wrapRelativeUrl("/api/v1/apps/verify_credentials", base_url),
|
||||
wrapRelativeUrl("/api/v1/apps/verify_credentials", baseUrl),
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token.access_token}`,
|
||||
|
|
@ -178,7 +178,7 @@ describe("GET /api/v1/apps/verify_credentials", () => {
|
|||
expect(response.status).toBe(200);
|
||||
expect(response.headers.get("content-type")).toBe("application/json");
|
||||
|
||||
const credentials = (await response.json()) as Partial<APIApplication>;
|
||||
const credentials = (await response.json()) as Partial<apiApplication>;
|
||||
|
||||
expect(credentials.name).toBe("Test Application");
|
||||
expect(credentials.website).toBe("https://example.com");
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { randomBytes } from "node:crypto";
|
||||
import { consoleLogger } from "@/loggers";
|
||||
import { asc, inArray, like } from "drizzle-orm";
|
||||
import type { Status } from "~/database/entities/Status";
|
||||
import type { Status } from "~/database/entities/status";
|
||||
import { db } from "~/drizzle/db";
|
||||
import { setupDatabase } from "~/drizzle/db";
|
||||
import { Notes, Tokens, Users } from "~/drizzle/schema";
|
||||
|
|
@ -16,13 +16,13 @@ await setupDatabase(consoleLogger);
|
|||
* @param req Request to send
|
||||
* @returns Response from the server
|
||||
*/
|
||||
export async function sendTestRequest(req: Request) {
|
||||
export function sendTestRequest(req: Request): Promise<Response> {
|
||||
// return fetch(req);
|
||||
return app.fetch(req);
|
||||
return Promise.resolve(app.fetch(req));
|
||||
}
|
||||
|
||||
export function wrapRelativeUrl(url: string, base_url: string) {
|
||||
return new URL(url, base_url);
|
||||
export function wrapRelativeUrl(url: string, baseUrl: string) {
|
||||
return new URL(url, baseUrl);
|
||||
}
|
||||
|
||||
export const deleteOldTestUsers = async () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue