refactor: 🚨 Turn every linter rule on and fix issues (there were a LOT :3)

This commit is contained in:
Jesse Wierzbinski 2024-06-12 16:26:43 -10:00
parent 2e98859153
commit a1e02d0d78
No known key found for this signature in database
177 changed files with 1826 additions and 1248 deletions

View file

@ -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);

View file

@ -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",