mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
Finish rewrite of everything with Prisma
This commit is contained in:
parent
5eed8374cd
commit
dc0ec47543
47 changed files with 1283 additions and 1036 deletions
|
|
@ -1,11 +1,11 @@
|
|||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { getConfig } from "@config";
|
||||
import { Token } from "@prisma/client";
|
||||
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||
import { AppDataSource } from "~database/datasource";
|
||||
import { ApplicationAction } from "~database/entities/Application";
|
||||
import { Token, TokenType } from "~database/entities/Token";
|
||||
import { UserAction } from "~database/entities/User";
|
||||
import { client } from "~database/datasource";
|
||||
import { TokenType } from "~database/entities/Token";
|
||||
import { UserWithRelations, createNewLocalUser } from "~database/entities/User";
|
||||
import { APIAccount } from "~types/entities/account";
|
||||
import { APIRelationship } from "~types/entities/relationship";
|
||||
import { APIStatus } from "~types/entities/status";
|
||||
|
|
@ -13,59 +13,59 @@ import { APIStatus } from "~types/entities/status";
|
|||
const config = getConfig();
|
||||
|
||||
let token: Token;
|
||||
let user: UserAction;
|
||||
let user2: UserAction;
|
||||
let user: UserWithRelations;
|
||||
let user2: UserWithRelations;
|
||||
|
||||
describe("API Tests", () => {
|
||||
beforeAll(async () => {
|
||||
if (!AppDataSource.isInitialized) await AppDataSource.initialize();
|
||||
|
||||
// Initialize test user
|
||||
user = await UserAction.createNewLocal({
|
||||
user = await createNewLocalUser({
|
||||
email: "test@test.com",
|
||||
username: "test",
|
||||
password: "test",
|
||||
display_name: "",
|
||||
});
|
||||
|
||||
// Initialize second test user
|
||||
user2 = await UserAction.createNewLocal({
|
||||
user2 = await createNewLocalUser({
|
||||
email: "test2@test.com",
|
||||
username: "test2",
|
||||
password: "test2",
|
||||
display_name: "",
|
||||
});
|
||||
|
||||
const app = new ApplicationAction();
|
||||
|
||||
app.name = "Test Application";
|
||||
app.website = "https://example.com";
|
||||
app.client_id = "test";
|
||||
app.redirect_uris = "https://example.com";
|
||||
app.scopes = "read write";
|
||||
app.secret = "test";
|
||||
app.vapid_key = null;
|
||||
|
||||
await app.save();
|
||||
|
||||
// Initialize test token
|
||||
token = new Token();
|
||||
|
||||
token.access_token = "test";
|
||||
token.application = app;
|
||||
token.code = "test";
|
||||
token.scope = "read write";
|
||||
token.token_type = TokenType.BEARER;
|
||||
token.user = user;
|
||||
|
||||
token = await token.save();
|
||||
token = await client.token.create({
|
||||
data: {
|
||||
access_token: "test",
|
||||
application: {
|
||||
create: {
|
||||
client_id: "test",
|
||||
name: "Test Application",
|
||||
redirect_uris: "https://example.com",
|
||||
scopes: "read write",
|
||||
secret: "test",
|
||||
website: "https://example.com",
|
||||
vapid_key: null,
|
||||
},
|
||||
},
|
||||
code: "test",
|
||||
scope: "read write",
|
||||
token_type: TokenType.BEARER,
|
||||
user: {
|
||||
connect: {
|
||||
id: user.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await user.remove();
|
||||
await user2.remove();
|
||||
|
||||
await AppDataSource.destroy();
|
||||
await client.user.deleteMany({
|
||||
where: {
|
||||
username: {
|
||||
in: ["test", "test2"],
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
describe("POST /api/v1/accounts/:id", () => {
|
||||
|
|
|
|||
|
|
@ -1,72 +1,65 @@
|
|||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { getConfig } from "@config";
|
||||
import { Token } from "@prisma/client";
|
||||
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||
import { AppDataSource } from "~database/datasource";
|
||||
import { ApplicationAction } from "~database/entities/Application";
|
||||
import { Token, TokenType } from "~database/entities/Token";
|
||||
import { UserAction } from "~database/entities/User";
|
||||
import { client } from "~database/datasource";
|
||||
import { TokenType } from "~database/entities/Token";
|
||||
import { UserWithRelations, createNewLocalUser } from "~database/entities/User";
|
||||
import { APIAccount } from "~types/entities/account";
|
||||
import { APIContext } from "~types/entities/context";
|
||||
import { APIStatus } from "~types/entities/status";
|
||||
|
||||
const config = getConfig();
|
||||
|
||||
let token: Token;
|
||||
let user: UserAction;
|
||||
let user2: UserAction;
|
||||
let user: UserWithRelations;
|
||||
let status: APIStatus | null = null;
|
||||
let status2: APIStatus | null = null;
|
||||
|
||||
describe("API Tests", () => {
|
||||
beforeAll(async () => {
|
||||
if (!AppDataSource.isInitialized) await AppDataSource.initialize();
|
||||
|
||||
// Initialize test user
|
||||
user = await UserAction.createNewLocal({
|
||||
user = await createNewLocalUser({
|
||||
email: "test@test.com",
|
||||
username: "test",
|
||||
password: "test",
|
||||
display_name: "",
|
||||
});
|
||||
|
||||
// Initialize second test user
|
||||
user2 = await UserAction.createNewLocal({
|
||||
email: "test2@test.com",
|
||||
username: "test2",
|
||||
password: "test2",
|
||||
display_name: "",
|
||||
token = await client.token.create({
|
||||
data: {
|
||||
access_token: "test",
|
||||
application: {
|
||||
create: {
|
||||
client_id: "test",
|
||||
name: "Test Application",
|
||||
redirect_uris: "https://example.com",
|
||||
scopes: "read write",
|
||||
secret: "test",
|
||||
website: "https://example.com",
|
||||
vapid_key: null,
|
||||
},
|
||||
},
|
||||
code: "test",
|
||||
scope: "read write",
|
||||
token_type: TokenType.BEARER,
|
||||
user: {
|
||||
connect: {
|
||||
id: user.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const app = new ApplicationAction();
|
||||
|
||||
app.name = "Test Application";
|
||||
app.website = "https://example.com";
|
||||
app.client_id = "test";
|
||||
app.redirect_uris = "https://example.com";
|
||||
app.scopes = "read write";
|
||||
app.secret = "test";
|
||||
app.vapid_key = null;
|
||||
|
||||
await app.save();
|
||||
|
||||
// Initialize test token
|
||||
token = new Token();
|
||||
|
||||
token.access_token = "test";
|
||||
token.application = app;
|
||||
token.code = "test";
|
||||
token.scope = "read write";
|
||||
token.token_type = TokenType.BEARER;
|
||||
token.user = user;
|
||||
|
||||
token = await token.save();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await user.remove();
|
||||
await user2.remove();
|
||||
|
||||
await AppDataSource.destroy();
|
||||
await client.user.deleteMany({
|
||||
where: {
|
||||
username: {
|
||||
in: ["test", "test2"],
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
describe("POST /api/v1/statuses", () => {
|
||||
|
|
@ -322,7 +315,7 @@ describe("API Tests", () => {
|
|||
"application/json"
|
||||
);
|
||||
|
||||
const users = (await response.json()) as UserAction[];
|
||||
const users = (await response.json()) as APIAccount[];
|
||||
|
||||
expect(users.length).toBe(1);
|
||||
expect(users[0].id).toBe(user.id);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue