refactor(database): 🎨 Update database and schema names to be clearer

This commit is contained in:
Jesse Wierzbinski 2024-04-16 20:36:01 -10:00
parent 9081036c6d
commit 88b3ec7b43
No known key found for this signature in database
92 changed files with 6785 additions and 1018 deletions

View file

@ -2,7 +2,7 @@ import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { config } from "config-manager";
import { eq } from "drizzle-orm";
import { db } from "~drizzle/db";
import { emoji } from "~drizzle/schema";
import { Emojis } from "~drizzle/schema";
import type { Emoji as APIEmoji } from "~types/mastodon/emoji";
import type { Instance as APIInstance } from "~types/mastodon/instance";
import { getTestUsers, sendTestRequest, wrapRelativeUrl } from "./utils";
@ -18,7 +18,7 @@ describe("API Tests", () => {
describe("GET /api/v1/custom_emojis", () => {
beforeAll(async () => {
await db.insert(emoji).values({
await db.insert(Emojis).values({
shortcode: "test",
url: "https://example.com/test.png",
contentType: "image/png",
@ -55,7 +55,7 @@ describe("API Tests", () => {
});
afterAll(async () => {
await db.delete(emoji).where(eq(emoji.shortcode, "test"));
await db.delete(Emojis).where(eq(Emojis.shortcode, "test"));
});
});
});

View file

@ -124,68 +124,6 @@ describe("API Tests", () => {
});
});
describe("POST /api/v1/accounts/:id/follow", () => {
test("should follow the specified user and return an APIRelationship object", async () => {
const response = await sendTestRequest(
new Request(
wrapRelativeUrl(
`/api/v1/accounts/${user2.id}/follow`,
base_url,
),
{
method: "POST",
headers: {
Authorization: `Bearer ${token.accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({}),
},
),
);
expect(response.status).toBe(200);
expect(response.headers.get("content-type")).toBe(
"application/json",
);
const relationship = (await response.json()) as APIRelationship;
expect(relationship.id).toBe(user2.id);
expect(relationship.following).toBe(true);
});
});
describe("POST /api/v1/accounts/:id/unfollow", () => {
test("should unfollow the specified user and return an APIRelationship object", async () => {
const response = await sendTestRequest(
new Request(
wrapRelativeUrl(
`/api/v1/accounts/${user2.id}/unfollow`,
base_url,
),
{
method: "POST",
headers: {
Authorization: `Bearer ${token.accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({}),
},
),
);
expect(response.status).toBe(200);
expect(response.headers.get("content-type")).toBe(
"application/json",
);
const account = (await response.json()) as APIRelationship;
expect(account.id).toBe(user2.id);
expect(account.following).toBe(false);
});
});
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(
@ -302,123 +240,6 @@ describe("API Tests", () => {
});
});
describe("POST /api/v1/accounts/:id/mute with notifications parameter", () => {
test("should mute the specified user and return an APIRelationship object with notifications set to false", async () => {
const response = await sendTestRequest(
new Request(
wrapRelativeUrl(
`/api/v1/accounts/${user2.id}/mute`,
base_url,
),
{
method: "POST",
headers: {
Authorization: `Bearer ${token.accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ notifications: true }),
},
),
);
expect(response.status).toBe(200);
expect(response.headers.get("content-type")).toBe(
"application/json",
);
const account = (await response.json()) as APIRelationship;
expect(account.id).toBe(user2.id);
expect(account.muting).toBe(true);
expect(account.muting_notifications).toBe(true);
});
test("should mute the specified user and return an APIRelationship object with notifications set to true", async () => {
const response = await sendTestRequest(
new Request(
wrapRelativeUrl(
`/api/v1/accounts/${user2.id}/mute`,
base_url,
),
{
method: "POST",
headers: {
Authorization: `Bearer ${token.accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ notifications: false }),
},
),
);
expect(response.status).toBe(200);
expect(response.headers.get("content-type")).toBe(
"application/json",
);
const account = (await response.json()) as APIRelationship;
expect(account.id).toBe(user2.id);
expect(account.muting).toBe(true);
expect(account.muting_notifications).toBe(true);
});
});
describe("GET /api/v1/mutes", () => {
test("should return an array of APIAccount objects for the user's muted accounts", async () => {
const response = await sendTestRequest(
new Request(wrapRelativeUrl("/api/v1/mutes", base_url), {
method: "GET",
headers: {
Authorization: `Bearer ${token.accessToken}`,
},
}),
);
expect(response.status).toBe(200);
expect(response.headers.get("content-type")).toBe(
"application/json",
);
const body = (await response.json()) as APIAccount[];
expect(Array.isArray(body)).toBe(true);
expect(body.length).toBe(1);
expect(body[0].id).toBe(user2.id);
});
});
describe("POST /api/v1/accounts/:id/unmute", () => {
test("should unmute the specified user and return an APIRelationship object", async () => {
const response = await sendTestRequest(
new Request(
wrapRelativeUrl(
`/api/v1/accounts/${user2.id}/unmute`,
base_url,
),
{
method: "POST",
headers: {
Authorization: `Bearer ${token.accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({}),
},
),
);
expect(response.status).toBe(200);
expect(response.headers.get("content-type")).toBe(
"application/json",
);
const account = (await response.json()) as APIRelationship;
expect(account.id).toBe(user2.id);
expect(account.muting).toBe(false);
});
});
describe("POST /api/v1/accounts/:id/pin", () => {
test("should pin the specified user and return an APIRelationship object", async () => {
const response = await sendTestRequest(

View file

@ -344,35 +344,6 @@ describe("API Tests", () => {
});
});
describe("GET /api/v1/statuses/:id/favourited_by", () => {
test("should return an array of User objects who favourited the specified status", async () => {
const response = await sendTestRequest(
new Request(
wrapRelativeUrl(
`${base_url}/api/v1/statuses/${status?.id}/favourited_by`,
base_url,
),
{
method: "GET",
headers: {
Authorization: `Bearer ${token.accessToken}`,
},
},
),
);
expect(response.status).toBe(200);
expect(response.headers.get("content-type")).toBe(
"application/json",
);
const users = (await response.json()) as APIAccount[];
expect(users.length).toBe(1);
expect(users[0].id).toBe(user.id);
});
});
describe("POST /api/v1/statuses/:id/unfavourite", () => {
test("should unfavourite the specified status object", async () => {
// Unfavourite the status

View file

@ -7,7 +7,7 @@ import {
createNewLocalUser,
} from "~database/entities/User";
import { db } from "~drizzle/db";
import { status, token, user } from "~drizzle/schema";
import { Notes, Tokens, Users } from "~drizzle/schema";
import { server } from "~index";
import { Note } from "~packages/database-interface/note";
/**
@ -26,7 +26,7 @@ export function wrapRelativeUrl(url: string, base_url: string) {
export const deleteOldTestUsers = async () => {
// Deletes all users that match the test username (test-<32 random characters>)
await db.delete(user).where(like(user.username, "test-%"));
await db.delete(Users).where(like(Users.username, "test-%"));
};
export const getTestUsers = async (count: number) => {
@ -51,7 +51,7 @@ export const getTestUsers = async (count: number) => {
}
const tokens = await db
.insert(token)
.insert(Tokens)
.values(
users.map((u) => ({
accessToken: randomBytes(32).toString("hex"),
@ -69,9 +69,9 @@ export const getTestUsers = async (count: number) => {
tokens,
passwords,
deleteUsers: async () => {
await db.delete(user).where(
await db.delete(Users).where(
inArray(
user.id,
Users.id,
users.map((u) => u.id),
),
);
@ -107,10 +107,10 @@ export const getTestStatuses = async (
return (
await Note.manyFromSql(
inArray(
status.id,
Notes.id,
statuses.map((s) => s.id),
),
asc(status.id),
asc(Notes.id),
)
).map((n) => n.getStatus());
};