mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
Fix existing bugs in tests, refactor users
This commit is contained in:
parent
b7587f8d3f
commit
65ff53e90c
19 changed files with 385 additions and 117 deletions
|
|
@ -13,7 +13,7 @@ beforeAll(async () => {
|
|||
if (!AppDataSource.isInitialized) await AppDataSource.initialize();
|
||||
|
||||
// Initialize test user
|
||||
await User.createNew({
|
||||
await User.createNewLocal({
|
||||
email: "test@test.com",
|
||||
username: "test",
|
||||
password: "test",
|
||||
|
|
|
|||
|
|
@ -4,10 +4,12 @@ import { getConfig } from "@config";
|
|||
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||
import { AppDataSource } from "~database/datasource";
|
||||
import { Application } from "~database/entities/Application";
|
||||
import { Emoji } from "~database/entities/Emoji";
|
||||
import { RawActivity } from "~database/entities/RawActivity";
|
||||
import { Token, TokenType } from "~database/entities/Token";
|
||||
import { User } from "~database/entities/User";
|
||||
import { APIAccount } from "~types/entities/account";
|
||||
import { APIEmoji } from "~types/entities/emoji";
|
||||
import { APIInstance } from "~types/entities/instance";
|
||||
import { APIRelationship } from "~types/entities/relationship";
|
||||
import { APIStatus } from "~types/entities/status";
|
||||
|
|
@ -23,7 +25,7 @@ beforeAll(async () => {
|
|||
if (!AppDataSource.isInitialized) await AppDataSource.initialize();
|
||||
|
||||
// Initialize test user
|
||||
user = await User.createNew({
|
||||
user = await User.createNewLocal({
|
||||
email: "test@test.com",
|
||||
username: "test",
|
||||
password: "test",
|
||||
|
|
@ -31,7 +33,7 @@ beforeAll(async () => {
|
|||
});
|
||||
|
||||
// Initialize second test user
|
||||
user2 = await User.createNew({
|
||||
user2 = await User.createNewLocal({
|
||||
email: "test2@test.com",
|
||||
username: "test2",
|
||||
password: "test2",
|
||||
|
|
@ -105,7 +107,7 @@ describe("POST /api/v1/statuses", () => {
|
|||
status = (await response.json()) as APIStatus;
|
||||
expect(status.content).toBe("Hello, world!");
|
||||
expect(status.visibility).toBe("public");
|
||||
expect(status.account.id).toBe(user.actor.id);
|
||||
expect(status.account.id).toBe(user.id);
|
||||
expect(status.replies_count).toBe(0);
|
||||
expect(status.favourites_count).toBe(0);
|
||||
expect(status.reblogged).toBe(false);
|
||||
|
|
@ -238,7 +240,7 @@ describe("GET /api/v1/accounts/:id/statuses", () => {
|
|||
// Basic validation
|
||||
expect(status1.content).toBe("Hello, world!");
|
||||
expect(status1.visibility).toBe("public");
|
||||
expect(status1.account.id).toBe(user.actor.id);
|
||||
expect(status1.account.id).toBe(user.id);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -678,6 +680,42 @@ describe("GET /api/v1/instance", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("GET /api/v1/custom_emojis", () => {
|
||||
beforeAll(async () => {
|
||||
const emoji = new Emoji();
|
||||
|
||||
emoji.instance = null;
|
||||
emoji.url = "https://example.com";
|
||||
emoji.shortcode = "test";
|
||||
emoji.visible_in_picker = true;
|
||||
|
||||
await emoji.save();
|
||||
});
|
||||
test("should return an array of at least one custom emoji", async () => {
|
||||
const response = await fetch(
|
||||
`${config.http.base_url}/api/v1/custom_emojis`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `Bearer ${token.access_token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.headers.get("content-type")).toBe("application/json");
|
||||
|
||||
const emojis: APIEmoji[] = await response.json();
|
||||
|
||||
expect(emojis.length).toBeGreaterThan(0);
|
||||
expect(emojis[0].shortcode).toBe("test");
|
||||
expect(emojis[0].url).toBe("https://example.com");
|
||||
});
|
||||
afterAll(async () => {
|
||||
await Emoji.delete({ shortcode: "test" });
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
const activities = await RawActivity.createQueryBuilder("activity")
|
||||
.where("activity.data->>'actor' = :actor", {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ beforeAll(async () => {
|
|||
if (!AppDataSource.isInitialized) await AppDataSource.initialize();
|
||||
|
||||
// Initialize test user
|
||||
await User.createNew({
|
||||
await User.createNewLocal({
|
||||
email: "test@test.com",
|
||||
username: "test",
|
||||
password: "test",
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ beforeAll(async () => {
|
|||
if (!AppDataSource.isInitialized) await AppDataSource.initialize();
|
||||
|
||||
// Initialize test user
|
||||
await User.createNew({
|
||||
await User.createNewLocal({
|
||||
email: "test@test.com",
|
||||
username: "test",
|
||||
password: "test",
|
||||
|
|
@ -32,6 +32,7 @@ describe("POST /api/v1/apps/", () => {
|
|||
formData.append("website", "https://example.com");
|
||||
formData.append("redirect_uris", "https://example.com");
|
||||
formData.append("scopes", "read write");
|
||||
|
||||
const response = await fetch(`${config.http.base_url}/api/v1/apps/`, {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
|
|
@ -64,10 +65,10 @@ describe("POST /auth/login/", () => {
|
|||
test("should get a code", async () => {
|
||||
const formData = new FormData();
|
||||
|
||||
formData.append("username", "test");
|
||||
formData.append("email", "test@test.com");
|
||||
formData.append("password", "test");
|
||||
const response = await fetch(
|
||||
`${config.http.base_url}/auth/login/?client_id=${client_id}&redirect_uri=https://example.com&response_type=code&scopes=read+write`,
|
||||
`${config.http.base_url}/auth/login/?client_id=${client_id}&redirect_uri=https://example.com&response_type=code&scope=read+write`,
|
||||
{
|
||||
method: "POST",
|
||||
body: formData,
|
||||
|
|
@ -93,7 +94,7 @@ describe("POST /oauth/token/", () => {
|
|||
formData.append("redirect_uri", "https://example.com");
|
||||
formData.append("client_id", client_id);
|
||||
formData.append("client_secret", client_secret);
|
||||
formData.append("scope", "read write");
|
||||
formData.append("scope", "read+write");
|
||||
|
||||
const response = await fetch(`${config.http.base_url}/oauth/token/`, {
|
||||
method: "POST",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue