Begin moving project to use Drizzle instead of prisma

This commit is contained in:
Jesse Wierzbinski 2024-04-11 01:39:07 -10:00
parent b107bed935
commit f7abe06a60
No known key found for this signature in database
49 changed files with 7602 additions and 1267 deletions

View file

@ -10,22 +10,34 @@ import {
import type { APIEmoji } from "~types/entities/emoji";
import type { APIInstance } from "~types/entities/instance";
import { sendTestRequest, wrapRelativeUrl } from "./utils";
import { db } from "~drizzle/db";
import { inArray } from "drizzle-orm";
import { application, user } from "~drizzle/schema";
const base_url = config.http.base_url;
let token: Token;
let user: UserWithRelations;
let dummyUser: UserWithRelations;
describe("API Tests", () => {
beforeAll(async () => {
await db.delete(user).where(inArray(user.username, ["test", "test2"]));
await db
.delete(application)
.where(inArray(application.clientId, ["test"]));
// Initialize test user
user = await createNewLocalUser({
dummyUser = await createNewLocalUser({
email: "test@test.com",
username: "test",
password: "test",
display_name: "",
});
if (!dummyUser) {
throw new Error("Failed to create test user");
}
token = await client.token.create({
data: {
access_token: "test",
@ -45,7 +57,7 @@ describe("API Tests", () => {
token_type: TokenType.BEARER,
user: {
connect: {
id: user.id,
id: dummyUser.id,
},
},
},
@ -53,19 +65,10 @@ describe("API Tests", () => {
});
afterAll(async () => {
await client.user.deleteMany({
where: {
username: {
in: ["test", "test2"],
},
},
});
await client.application.deleteMany({
where: {
client_id: "test",
},
});
await db.delete(user).where(inArray(user.username, ["test", "test2"]));
await db
.delete(application)
.where(inArray(application.clientId, ["test"]));
});
describe("GET /api/v1/instance", () => {
@ -89,7 +92,7 @@ describe("API Tests", () => {
const instance = (await response.json()) as APIInstance;
expect(instance.uri).toBe(new URL(config.http.base_url).hostname);
expect(instance.uri).toBe(config.http.base_url);
expect(instance.title).toBeDefined();
expect(instance.description).toBeDefined();
expect(instance.email).toBeDefined();

View file

@ -126,6 +126,7 @@ describe("API Tests", () => {
status: "Hello, world!",
visibility: "public",
media_ids: [media1?.id],
federate: false,
}),
},
),
@ -173,6 +174,7 @@ describe("API Tests", () => {
status: "This is a reply!",
visibility: "public",
in_reply_to_id: status?.id,
federate: false,
}),
},
),

View file

@ -1,4 +1,4 @@
import { server } from "~index";
// import { server } from "~index";
/**
* This allows us to send a test request to the server even when it isnt running
@ -7,7 +7,9 @@ import { server } from "~index";
* @returns Response from the server
*/
export async function sendTestRequest(req: Request) {
return server.fetch(req);
console.log(req);
return fetch(req);
// return server.fetch(req);
}
export function wrapRelativeUrl(url: string, base_url: string) {