mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 16:38:19 +01:00
refactor: ♻️ Refactor tests to use a simpler syntax
This commit is contained in:
parent
6ed1bd747f
commit
47c666894c
|
|
@ -4,7 +4,7 @@ import { eq } from "drizzle-orm";
|
||||||
import { db } from "~/drizzle/db";
|
import { db } from "~/drizzle/db";
|
||||||
import { Applications } from "~/drizzle/schema";
|
import { Applications } from "~/drizzle/schema";
|
||||||
import { config } from "~/packages/config-manager";
|
import { config } from "~/packages/config-manager";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
const { users, deleteUsers, passwords } = await getTestUsers(1);
|
const { users, deleteUsers, passwords } = await getTestUsers(1);
|
||||||
|
|
@ -36,17 +36,12 @@ describe(meta.route, () => {
|
||||||
formData.append("identifier", users[0]?.data.email ?? "");
|
formData.append("identifier", users[0]?.data.email ?? "");
|
||||||
formData.append("password", passwords[0]);
|
formData.append("password", passwords[0]);
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/auth/login?client_id=${application.clientId}&redirect_uri=https://example.com&response_type=code&scope=read+write`,
|
`/api/auth/login?client_id=${application.clientId}&redirect_uri=https://example.com&response_type=code&scope=read+write`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
body: formData,
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(302);
|
expect(response.status).toBe(302);
|
||||||
|
|
@ -75,17 +70,12 @@ describe(meta.route, () => {
|
||||||
formData.append("identifier", users[0]?.data.username ?? "");
|
formData.append("identifier", users[0]?.data.username ?? "");
|
||||||
formData.append("password", passwords[0]);
|
formData.append("password", passwords[0]);
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/auth/login?client_id=${application.clientId}&redirect_uri=https://example.com&response_type=code&scope=read+write`,
|
`/api/auth/login?client_id=${application.clientId}&redirect_uri=https://example.com&response_type=code&scope=read+write`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
body: formData,
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(302);
|
expect(response.status).toBe(302);
|
||||||
|
|
@ -114,17 +104,12 @@ describe(meta.route, () => {
|
||||||
formData.append("identifier", users[0]?.data.email ?? "");
|
formData.append("identifier", users[0]?.data.email ?? "");
|
||||||
formData.append("password", passwords[0]);
|
formData.append("password", passwords[0]);
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/auth/login?client_id=${application.clientId}&redirect_uri=https://example.com&response_type=code&scope=read+write&state=abc`,
|
`/api/auth/login?client_id=${application.clientId}&redirect_uri=https://example.com&response_type=code&scope=read+write&state=abc`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
body: formData,
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(302);
|
expect(response.status).toBe(302);
|
||||||
|
|
@ -156,17 +141,13 @@ describe(meta.route, () => {
|
||||||
formData.append("identifier", "ababa@gmail.com");
|
formData.append("identifier", "ababa@gmail.com");
|
||||||
formData.append("password", "password");
|
formData.append("password", "password");
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/auth/login?client_id=${application.clientId}&redirect_uri=https://example.com&response_type=code&scope=read+write`,
|
`/api/auth/login?client_id=${application.clientId}&redirect_uri=https://example.com&response_type=code&scope=read+write`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
body: formData,
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(302);
|
expect(response.status).toBe(302);
|
||||||
|
|
@ -193,17 +174,12 @@ describe(meta.route, () => {
|
||||||
formData.append("identifier", "ababa");
|
formData.append("identifier", "ababa");
|
||||||
formData.append("password", "password");
|
formData.append("password", "password");
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/auth/login?client_id=${application.clientId}&redirect_uri=https://example.com&response_type=code&scope=read+write`,
|
`/api/auth/login?client_id=${application.clientId}&redirect_uri=https://example.com&response_type=code&scope=read+write`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
body: formData,
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(302);
|
expect(response.status).toBe(302);
|
||||||
|
|
@ -230,17 +206,12 @@ describe(meta.route, () => {
|
||||||
formData.append("identifier", users[0]?.data.email ?? "");
|
formData.append("identifier", users[0]?.data.email ?? "");
|
||||||
formData.append("password", "password");
|
formData.append("password", "password");
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/auth/login?client_id=${application.clientId}&redirect_uri=https://example.com&response_type=code&scope=read+write`,
|
`/api/auth/login?client_id=${application.clientId}&redirect_uri=https://example.com&response_type=code&scope=read+write`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
body: formData,
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(302);
|
expect(response.status).toBe(302);
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { eq } from "drizzle-orm";
|
||||||
import { db } from "~/drizzle/db";
|
import { db } from "~/drizzle/db";
|
||||||
import { Applications } from "~/drizzle/schema";
|
import { Applications } from "~/drizzle/schema";
|
||||||
import { config } from "~/packages/config-manager";
|
import { config } from "~/packages/config-manager";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
const { users, deleteUsers, passwords } = await getTestUsers(1);
|
const { users, deleteUsers, passwords } = await getTestUsers(1);
|
||||||
|
|
@ -38,17 +38,13 @@ describe(meta.route, () => {
|
||||||
formData.append("identifier", users[0]?.data.username ?? "");
|
formData.append("identifier", users[0]?.data.username ?? "");
|
||||||
formData.append("password", passwords[0]);
|
formData.append("password", passwords[0]);
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/auth/login?client_id=${application.clientId}&redirect_uri=https://example.com&response_type=code&scope=read+write`,
|
`/api/auth/login?client_id=${application.clientId}&redirect_uri=https://example.com&response_type=code&scope=read+write`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
body: formData,
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(302);
|
expect(response.status).toBe(302);
|
||||||
|
|
@ -65,17 +61,12 @@ describe(meta.route, () => {
|
||||||
formData.append("identifier", users[0]?.data.username ?? "");
|
formData.append("identifier", users[0]?.data.username ?? "");
|
||||||
formData.append("password", passwords[0]);
|
formData.append("password", passwords[0]);
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/auth/login?client_id=${application.clientId}&redirect_uri=https://example.com&response_type=code&scope=read+write`,
|
`/api/auth/login?client_id=${application.clientId}&redirect_uri=https://example.com&response_type=code&scope=read+write`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
body: formData,
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(302);
|
expect(response.status).toBe(302);
|
||||||
|
|
@ -96,12 +87,10 @@ describe(meta.route, () => {
|
||||||
formData.append("password", newPassword);
|
formData.append("password", newPassword);
|
||||||
formData.append("password2", newPassword);
|
formData.append("password2", newPassword);
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest("/api/auth/reset", {
|
||||||
new Request(new URL("/api/auth/reset", config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
body: formData,
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(302);
|
expect(response.status).toBe(302);
|
||||||
expect(response.headers.get("location")).toBeDefined();
|
expect(response.headers.get("location")).toBeDefined();
|
||||||
|
|
@ -111,17 +100,12 @@ describe(meta.route, () => {
|
||||||
loginFormData.append("identifier", users[0]?.data.username ?? "");
|
loginFormData.append("identifier", users[0]?.data.username ?? "");
|
||||||
loginFormData.append("password", newPassword);
|
loginFormData.append("password", newPassword);
|
||||||
|
|
||||||
const loginResponse = await sendTestRequest(
|
const loginResponse = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/auth/login?client_id=${application.clientId}&redirect_uri=https://example.com&response_type=code&scope=read+write`,
|
`/api/auth/login?client_id=${application.clientId}&redirect_uri=https://example.com&response_type=code&scope=read+write`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: loginFormData,
|
body: loginFormData,
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(loginResponse.status).toBe(302);
|
expect(loginResponse.status).toBe(302);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { afterAll, describe, expect, test } from "bun:test";
|
import { afterAll, describe, expect, test } from "bun:test";
|
||||||
import type { Relationship as ApiRelationship } from "@versia/client/types";
|
import type { Relationship as ApiRelationship } from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./block";
|
import { meta } from "./block";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
||||||
|
|
@ -13,55 +12,37 @@ afterAll(async () => {
|
||||||
// /api/v1/accounts/:id/block
|
// /api/v1/accounts/:id/block
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 401 if not authenticated", async () => {
|
test("should return 401 if not authenticated", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", users[1].id),
|
meta.route.replace(":id", users[1].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
expect(response.status).toBe(401);
|
expect(response.status).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 404 if user not found", async () => {
|
test("should return 404 if user not found", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
meta.route.replace(":id", "00000000-0000-0000-0000-000000000000"),
|
||||||
new URL(
|
|
||||||
meta.route.replace(
|
|
||||||
":id",
|
|
||||||
"00000000-0000-0000-0000-000000000000",
|
|
||||||
),
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
expect(response.status).toBe(404);
|
expect(response.status).toBe(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should block user", async () => {
|
test("should block user", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", users[1].id),
|
meta.route.replace(":id", users[1].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
|
|
@ -70,19 +51,14 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 200 if user already blocked", async () => {
|
test("should return 200 if user already blocked", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", users[1].id),
|
meta.route.replace(":id", users[1].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { afterAll, describe, expect, test } from "bun:test";
|
import { afterAll, describe, expect, test } from "bun:test";
|
||||||
import type { Relationship as ApiRelationship } from "@versia/client/types";
|
import type { Relationship as ApiRelationship } from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./follow";
|
import { meta } from "./follow";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
||||||
|
|
@ -13,12 +12,8 @@ afterAll(async () => {
|
||||||
// /api/v1/accounts/:id/follow
|
// /api/v1/accounts/:id/follow
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 401 if not authenticated", async () => {
|
test("should return 401 if not authenticated", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", users[1].id),
|
meta.route.replace(":id", users[1].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -26,21 +21,13 @@ describe(meta.route, () => {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
expect(response.status).toBe(401);
|
expect(response.status).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 404 if user not found", async () => {
|
test("should return 404 if user not found", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
meta.route.replace(":id", "00000000-0000-0000-0000-000000000000"),
|
||||||
new URL(
|
|
||||||
meta.route.replace(
|
|
||||||
":id",
|
|
||||||
"00000000-0000-0000-0000-000000000000",
|
|
||||||
),
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -49,18 +36,13 @@ describe(meta.route, () => {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
expect(response.status).toBe(404);
|
expect(response.status).toBe(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should follow user", async () => {
|
test("should follow user", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", users[1].id),
|
meta.route.replace(":id", users[1].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -69,7 +51,6 @@ describe(meta.route, () => {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
|
|
@ -78,12 +59,8 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 200 if user already followed", async () => {
|
test("should return 200 if user already followed", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", users[1].id),
|
meta.route.replace(":id", users[1].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -92,7 +69,6 @@ describe(meta.route, () => {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||||
import type { Account as ApiAccount } from "@versia/client/types";
|
import type { Account as ApiAccount } from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./followers";
|
import { meta } from "./followers";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
||||||
|
|
@ -12,12 +11,8 @@ afterAll(async () => {
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
// Follow user
|
// Follow user
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/accounts/${users[1].id}/follow`,
|
`/api/v1/accounts/${users[1].id}/follow`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -26,7 +21,6 @@ beforeAll(async () => {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -35,18 +29,13 @@ beforeAll(async () => {
|
||||||
// /api/v1/accounts/:id/followers
|
// /api/v1/accounts/:id/followers
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 200 with followers", async () => {
|
test("should return 200 with followers", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", users[1].id),
|
meta.route.replace(":id", users[1].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -60,35 +49,25 @@ describe(meta.route, () => {
|
||||||
|
|
||||||
test("should return no followers after unfollowing", async () => {
|
test("should return no followers after unfollowing", async () => {
|
||||||
// Unfollow user
|
// Unfollow user
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/accounts/${users[1].id}/unfollow`,
|
`/api/v1/accounts/${users[1].id}/unfollow`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
const response2 = await sendTestRequest(
|
const response2 = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", users[1].id),
|
meta.route.replace(":id", users[1].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response2.status).toBe(200);
|
expect(response2.status).toBe(200);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||||
import type { Account as ApiAccount } from "@versia/client/types";
|
import type { Account as ApiAccount } from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./following";
|
import { meta } from "./following";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
||||||
|
|
@ -12,12 +11,8 @@ afterAll(async () => {
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
// Follow user
|
// Follow user
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/accounts/${users[1].id}/follow`,
|
`/api/v1/accounts/${users[1].id}/follow`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -26,7 +21,6 @@ beforeAll(async () => {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -35,18 +29,13 @@ beforeAll(async () => {
|
||||||
// /api/v1/accounts/:id/following
|
// /api/v1/accounts/:id/following
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 200 with following", async () => {
|
test("should return 200 with following", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", users[0].id),
|
meta.route.replace(":id", users[0].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -60,35 +49,25 @@ describe(meta.route, () => {
|
||||||
|
|
||||||
test("should return no following after unfollowing", async () => {
|
test("should return no following after unfollowing", async () => {
|
||||||
// Unfollow user
|
// Unfollow user
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/accounts/${users[1].id}/unfollow`,
|
`/api/v1/accounts/${users[1].id}/unfollow`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
const response2 = await sendTestRequest(
|
const response2 = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", users[0].id),
|
meta.route.replace(":id", users[0].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response2.status).toBe(200);
|
expect(response2.status).toBe(200);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||||
import type { Account as ApiAccount } from "@versia/client/types";
|
import type { Account as ApiAccount } from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestStatuses, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestStatuses, getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
||||||
|
|
@ -13,47 +12,29 @@ afterAll(async () => {
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
for (const status of timeline) {
|
for (const status of timeline) {
|
||||||
await sendTestRequest(
|
await fakeRequest(`/api/v1/statuses/${status.id}/favourite`, {
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/statuses/${status.id}/favourite`,
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// /api/v1/accounts/:id
|
// /api/v1/accounts/:id
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 404 if ID is invalid", async () => {
|
test("should return 404 if ID is invalid", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", "invalid"),
|
meta.route.replace(":id", "invalid"),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
expect(response.status).toBe(422);
|
expect(response.status).toBe(422);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return user", async () => {
|
test("should return user", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", users[0].id),
|
meta.route.replace(":id", users[0].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { afterAll, describe, expect, test } from "bun:test";
|
import { afterAll, describe, expect, test } from "bun:test";
|
||||||
import type { Relationship as ApiRelationship } from "@versia/client/types";
|
import type { Relationship as ApiRelationship } from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./mute";
|
import { meta } from "./mute";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
||||||
|
|
@ -13,12 +12,8 @@ afterAll(async () => {
|
||||||
// /api/v1/accounts/:id/mute
|
// /api/v1/accounts/:id/mute
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 401 if not authenticated", async () => {
|
test("should return 401 if not authenticated", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", users[1].id),
|
meta.route.replace(":id", users[1].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -26,21 +21,13 @@ describe(meta.route, () => {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
expect(response.status).toBe(401);
|
expect(response.status).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 404 if user not found", async () => {
|
test("should return 404 if user not found", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
meta.route.replace(":id", "00000000-0000-0000-0000-000000000000"),
|
||||||
new URL(
|
|
||||||
meta.route.replace(
|
|
||||||
":id",
|
|
||||||
"00000000-0000-0000-0000-000000000000",
|
|
||||||
),
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -49,18 +36,13 @@ describe(meta.route, () => {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
expect(response.status).toBe(404);
|
expect(response.status).toBe(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should mute user", async () => {
|
test("should mute user", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", users[1].id),
|
meta.route.replace(":id", users[1].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -69,7 +51,6 @@ describe(meta.route, () => {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
|
|
@ -78,12 +59,8 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 200 if user already muted", async () => {
|
test("should return 200 if user already muted", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", users[1].id),
|
meta.route.replace(":id", users[1].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -92,7 +69,6 @@ describe(meta.route, () => {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||||
import type { Status as ApiStatus } from "@versia/client/types";
|
import type { Status as ApiStatus } from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestStatuses, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestStatuses, getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./statuses";
|
import { meta } from "./statuses";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
||||||
|
|
@ -13,19 +12,14 @@ afterAll(async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/statuses/${timeline2[0].id}/reblog`,
|
`/api/v1/statuses/${timeline2[0].id}/reblog`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -34,18 +28,14 @@ beforeAll(async () => {
|
||||||
// /api/v1/accounts/:id/statuses
|
// /api/v1/accounts/:id/statuses
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 200 with statuses", async () => {
|
test("should return 200 with statuses", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", users[1].id),
|
meta.route.replace(":id", users[1].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -58,21 +48,14 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should exclude reblogs", async () => {
|
test("should exclude reblogs", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
`${meta.route.replace(":id", users[1].id)}?exclude_reblogs=true`,
|
||||||
new URL(
|
|
||||||
`${meta.route.replace(
|
|
||||||
":id",
|
|
||||||
users[1].id,
|
|
||||||
)}?exclude_reblogs=true`,
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -86,8 +69,7 @@ describe(meta.route, () => {
|
||||||
|
|
||||||
test("should exclude replies", async () => {
|
test("should exclude replies", async () => {
|
||||||
// Create reply
|
// Create reply
|
||||||
const replyResponse = await sendTestRequest(
|
const replyResponse = await fakeRequest("/api/v1/statuses", {
|
||||||
new Request(new URL("/api/v1/statuses", config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
|
|
@ -97,26 +79,18 @@ describe(meta.route, () => {
|
||||||
in_reply_to_id: timeline[0].id,
|
in_reply_to_id: timeline[0].id,
|
||||||
local_only: "true",
|
local_only: "true",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(replyResponse.status).toBe(200);
|
expect(replyResponse.status).toBe(200);
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
`${meta.route.replace(":id", users[1].id)}?exclude_replies=true`,
|
||||||
new URL(
|
|
||||||
`${meta.route.replace(
|
|
||||||
":id",
|
|
||||||
users[1].id,
|
|
||||||
)}?exclude_replies=true`,
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -129,18 +103,14 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should only include pins", async () => {
|
test("should only include pins", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`${meta.route.replace(":id", users[1].id)}?pinned=true`,
|
`${meta.route.replace(":id", users[1].id)}?pinned=true`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -150,35 +120,27 @@ describe(meta.route, () => {
|
||||||
expect(data.length).toBe(0);
|
expect(data.length).toBe(0);
|
||||||
|
|
||||||
// Create pin
|
// Create pin
|
||||||
const pinResponse = await sendTestRequest(
|
const pinResponse = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/statuses/${timeline[3].id}/pin`,
|
`/api/v1/statuses/${timeline[3].id}/pin`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(pinResponse.status).toBe(200);
|
expect(pinResponse.status).toBe(200);
|
||||||
|
|
||||||
const response2 = await sendTestRequest(
|
const response2 = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`${meta.route.replace(":id", users[1].id)}?pinned=true`,
|
`${meta.route.replace(":id", users[1].id)}?pinned=true`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response2.status).toBe(200);
|
expect(response2.status).toBe(200);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||||
import type { Relationship as ApiRelationship } from "@versia/client/types";
|
import type { Relationship as ApiRelationship } from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./unmute";
|
import { meta } from "./unmute";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
||||||
|
|
@ -11,74 +10,48 @@ afterAll(async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await sendTestRequest(
|
await fakeRequest(`/api/v1/accounts/${users[0].id}/mute`, {
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/accounts/${users[0].id}/mute`,
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// /api/v1/accounts/:id/unmute
|
// /api/v1/accounts/:id/unmute
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 401 if not authenticated", async () => {
|
test("should return 401 if not authenticated", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", users[1].id),
|
meta.route.replace(":id", users[1].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
expect(response.status).toBe(401);
|
expect(response.status).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 404 if user not found", async () => {
|
test("should return 404 if user not found", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
meta.route.replace(":id", "00000000-0000-0000-0000-000000000000"),
|
||||||
new URL(
|
|
||||||
meta.route.replace(
|
|
||||||
":id",
|
|
||||||
"00000000-0000-0000-0000-000000000000",
|
|
||||||
),
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
expect(response.status).toBe(404);
|
expect(response.status).toBe(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should unmute user", async () => {
|
test("should unmute user", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", users[1].id),
|
meta.route.replace(":id", users[1].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
|
|
@ -87,19 +60,14 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 200 if user already unmuted", async () => {
|
test("should return 200 if user already unmuted", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", users[1].id),
|
meta.route.replace(":id", users[1].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { afterAll, describe, expect, test } from "bun:test";
|
import { afterAll, describe, expect, test } from "bun:test";
|
||||||
import type { Account as ApiAccount } from "@versia/client/types";
|
import type { Account as ApiAccount } from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
const { users, deleteUsers } = await getTestUsers(5);
|
const { users, deleteUsers } = await getTestUsers(5);
|
||||||
|
|
@ -13,13 +12,8 @@ afterAll(async () => {
|
||||||
// /api/v1/accounts/id
|
// /api/v1/accounts/id
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should correctly get user from username", async () => {
|
test("should correctly get user from username", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`${meta.route}?username=${users[0].data.username}`,
|
`${meta.route}?username=${users[0].data.username}`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -30,13 +24,8 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 404 for non-existent user", async () => {
|
test("should return 404 for non-existent user", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`${meta.route}?username=${users[0].data.username}-nonexistent`,
|
`${meta.route}?username=${users[0].data.username}-nonexistent`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(404);
|
expect(response.status).toBe(404);
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,7 @@ import { randomString } from "@/math";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
import { db } from "~/drizzle/db";
|
import { db } from "~/drizzle/db";
|
||||||
import { Users } from "~/drizzle/schema";
|
import { Users } from "~/drizzle/schema";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getSolvedChallenge } from "~/tests/utils";
|
||||||
import { getSolvedChallenge, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
const username = randomString(10, "hex");
|
const username = randomString(10, "hex");
|
||||||
|
|
@ -18,8 +17,7 @@ afterEach(async () => {
|
||||||
// /api/v1/statuses
|
// /api/v1/statuses
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should create a new account", async () => {
|
test("should create a new account", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
@ -33,15 +31,13 @@ describe(meta.route, () => {
|
||||||
locale: "en",
|
locale: "en",
|
||||||
reason: "testing",
|
reason: "testing",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.ok).toBe(true);
|
expect(response.ok).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should refuse invalid emails", async () => {
|
test("should refuse invalid emails", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
@ -55,15 +51,13 @@ describe(meta.route, () => {
|
||||||
locale: "en",
|
locale: "en",
|
||||||
reason: "testing",
|
reason: "testing",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(422);
|
expect(response.status).toBe(422);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should require a password", async () => {
|
test("should require a password", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
@ -76,15 +70,13 @@ describe(meta.route, () => {
|
||||||
locale: "en",
|
locale: "en",
|
||||||
reason: "testing",
|
reason: "testing",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(422);
|
expect(response.status).toBe(422);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should not allow a previously registered email", async () => {
|
test("should not allow a previously registered email", async () => {
|
||||||
await sendTestRequest(
|
await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
@ -98,11 +90,9 @@ describe(meta.route, () => {
|
||||||
locale: "en",
|
locale: "en",
|
||||||
reason: "testing",
|
reason: "testing",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
@ -116,15 +106,13 @@ describe(meta.route, () => {
|
||||||
locale: "en",
|
locale: "en",
|
||||||
reason: "testing",
|
reason: "testing",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(422);
|
expect(response.status).toBe(422);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should not allow a previously registered email (case insensitive)", async () => {
|
test("should not allow a previously registered email (case insensitive)", async () => {
|
||||||
await sendTestRequest(
|
await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
@ -138,11 +126,9 @@ describe(meta.route, () => {
|
||||||
locale: "en",
|
locale: "en",
|
||||||
reason: "testing",
|
reason: "testing",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
@ -156,15 +142,13 @@ describe(meta.route, () => {
|
||||||
locale: "en",
|
locale: "en",
|
||||||
reason: "testing",
|
reason: "testing",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(422);
|
expect(response.status).toBe(422);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should not allow invalid usernames (not a-z_0-9)", async () => {
|
test("should not allow invalid usernames (not a-z_0-9)", async () => {
|
||||||
const response1 = await sendTestRequest(
|
const response1 = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
@ -178,13 +162,11 @@ describe(meta.route, () => {
|
||||||
locale: "en",
|
locale: "en",
|
||||||
reason: "testing",
|
reason: "testing",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response1.status).toBe(422);
|
expect(response1.status).toBe(422);
|
||||||
|
|
||||||
const response2 = await sendTestRequest(
|
const response2 = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
@ -198,13 +180,11 @@ describe(meta.route, () => {
|
||||||
locale: "en",
|
locale: "en",
|
||||||
reason: "testing",
|
reason: "testing",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response2.status).toBe(422);
|
expect(response2.status).toBe(422);
|
||||||
|
|
||||||
const response3 = await sendTestRequest(
|
const response3 = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
@ -218,13 +198,11 @@ describe(meta.route, () => {
|
||||||
locale: "en",
|
locale: "en",
|
||||||
reason: "testing",
|
reason: "testing",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response3.status).toBe(422);
|
expect(response3.status).toBe(422);
|
||||||
|
|
||||||
const response4 = await sendTestRequest(
|
const response4 = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
@ -238,8 +216,7 @@ describe(meta.route, () => {
|
||||||
locale: "en",
|
locale: "en",
|
||||||
reason: "testing",
|
reason: "testing",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response4.status).toBe(422);
|
expect(response4.status).toBe(422);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { afterAll, describe, expect, test } from "bun:test";
|
import { afterAll, describe, expect, test } from "bun:test";
|
||||||
import type { Account as ApiAccount } from "@versia/client/types";
|
import type { Account as ApiAccount } from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
||||||
|
|
@ -13,18 +12,13 @@ afterAll(async () => {
|
||||||
// /api/v1/accounts/lookup
|
// /api/v1/accounts/lookup
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 200 with users", async () => {
|
test("should return 200 with users", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`${meta.route}?acct=${users[0].data.username}`,
|
`${meta.route}?acct=${users[0].data.username}`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,7 @@ import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
import { db } from "~/drizzle/db";
|
import { db } from "~/drizzle/db";
|
||||||
import { Users } from "~/drizzle/schema";
|
import { Users } from "~/drizzle/schema";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
||||||
|
|
@ -17,41 +16,25 @@ beforeAll(async () => {
|
||||||
.set({ isLocked: true })
|
.set({ isLocked: true })
|
||||||
.where(eq(Users.id, users[0].id));
|
.where(eq(Users.id, users[0].id));
|
||||||
|
|
||||||
const res1 = await sendTestRequest(
|
const res1 = await fakeRequest(`/api/v1/accounts/${users[0].id}/follow`, {
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/accounts/${users[0].id}/follow`,
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(res1.ok).toBe(true);
|
expect(res1.ok).toBe(true);
|
||||||
|
|
||||||
const res2 = await sendTestRequest(
|
const res2 = await fakeRequest(`/api/v1/accounts/${users[2].id}/follow`, {
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/accounts/${users[2].id}/follow`,
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(res2.ok).toBe(true);
|
expect(res2.ok).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
@ -63,31 +46,19 @@ afterAll(async () => {
|
||||||
// /api/v1/accounts/relationships
|
// /api/v1/accounts/relationships
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 401 if not authenticated", async () => {
|
test("should return 401 if not authenticated", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(`${meta.route}?id[]=${users[2].id}`);
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`${meta.route}?id[]=${users[2].id}`,
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(401);
|
expect(response.status).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return relationships", async () => {
|
test("should return relationships", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`${meta.route}?id[]=${users[2].id}`,
|
`${meta.route}?id[]=${users[2].id}`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -111,18 +82,13 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should be requested_by user1", async () => {
|
test("should be requested_by user1", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`${meta.route}?id[]=${users[1].id}`,
|
`${meta.route}?id[]=${users[1].id}`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { afterAll, describe, expect, test } from "bun:test";
|
import { afterAll, describe, expect, test } from "bun:test";
|
||||||
import type { Account as ApiAccount } from "@versia/client/types";
|
import type { Account as ApiAccount } from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
||||||
|
|
@ -13,18 +12,13 @@ afterAll(async () => {
|
||||||
// /api/v1/accounts/search
|
// /api/v1/accounts/search
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 200 with users", async () => {
|
test("should return 200 with users", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`${meta.route}?q=${users[0].data.username}`,
|
`${meta.route}?q=${users[0].data.username}`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,13 @@
|
||||||
import { describe, expect, test } from "bun:test";
|
import { describe, expect, test } from "bun:test";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest } from "~/tests/utils";
|
||||||
import { sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
// /api/v1/challenges
|
// /api/v1/challenges
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should get a challenge", async () => {
|
test("should get a challenge", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,7 @@ import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||||
import { inArray } from "drizzle-orm";
|
import { inArray } from "drizzle-orm";
|
||||||
import { db } from "~/drizzle/db";
|
import { db } from "~/drizzle/db";
|
||||||
import { Emojis } from "~/drizzle/schema";
|
import { Emojis } from "~/drizzle/schema";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
||||||
|
|
@ -13,8 +12,7 @@ beforeAll(async () => {
|
||||||
await users[1].update({ isAdmin: true });
|
await users[1].update({ isAdmin: true });
|
||||||
|
|
||||||
// Upload one emoji as admin, then one as each user
|
// Upload one emoji as admin, then one as each user
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest("/api/v1/emojis", {
|
||||||
new Request(new URL("/api/v1/emojis", config.http.base_url), {
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
@ -25,13 +23,11 @@ beforeAll(async () => {
|
||||||
element: "https://cdn.versia.social/logo.webp",
|
element: "https://cdn.versia.social/logo.webp",
|
||||||
global: true,
|
global: true,
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
await sendTestRequest(
|
await fakeRequest("/api/v1/emojis", {
|
||||||
new Request(new URL("/api/v1/emojis", config.http.base_url), {
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
@ -41,11 +37,9 @@ beforeAll(async () => {
|
||||||
shortcode: "test2",
|
shortcode: "test2",
|
||||||
element: "https://cdn.versia.social/logo.webp",
|
element: "https://cdn.versia.social/logo.webp",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
await sendTestRequest(
|
await fakeRequest("/api/v1/emojis", {
|
||||||
new Request(new URL("/api/v1/emojis", config.http.base_url), {
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
@ -55,8 +49,7 @@ beforeAll(async () => {
|
||||||
shortcode: "test3",
|
shortcode: "test3",
|
||||||
element: "https://cdn.versia.social/logo.webp",
|
element: "https://cdn.versia.social/logo.webp",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
|
|
@ -69,13 +62,11 @@ afterAll(async () => {
|
||||||
|
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return all global emojis", async () => {
|
test("should return all global emojis", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
},
|
},
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
@ -103,13 +94,11 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return all user emojis", async () => {
|
test("should return all user emojis", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
@ -137,9 +126,7 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return all global emojis when signed out", async () => {
|
test("should return all global emojis when signed out", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route);
|
||||||
new Request(new URL(meta.route, config.http.base_url)),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,7 @@ import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||||
import { inArray } from "drizzle-orm";
|
import { inArray } from "drizzle-orm";
|
||||||
import { db } from "~/drizzle/db";
|
import { db } from "~/drizzle/db";
|
||||||
import { Emojis } from "~/drizzle/schema";
|
import { Emojis } from "~/drizzle/schema";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
||||||
|
|
@ -14,8 +13,7 @@ beforeAll(async () => {
|
||||||
await users[1].update({ isAdmin: true });
|
await users[1].update({ isAdmin: true });
|
||||||
|
|
||||||
// Create an emoji
|
// Create an emoji
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest("/api/v1/emojis", {
|
||||||
new Request(new URL("/api/v1/emojis", config.http.base_url), {
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
@ -26,8 +24,7 @@ beforeAll(async () => {
|
||||||
element: "https://cdn.versia.social/logo.webp",
|
element: "https://cdn.versia.social/logo.webp",
|
||||||
global: true,
|
global: true,
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.ok).toBe(true);
|
expect(response.ok).toBe(true);
|
||||||
const emoji = await response.json();
|
const emoji = await response.json();
|
||||||
|
|
@ -45,45 +42,30 @@ afterAll(async () => {
|
||||||
// /api/v1/emojis/:id (PATCH, DELETE, GET)
|
// /api/v1/emojis/:id (PATCH, DELETE, GET)
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 401 if not authenticated", async () => {
|
test("should return 401 if not authenticated", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route.replace(":id", id), {
|
||||||
new Request(
|
|
||||||
new URL(meta.route.replace(":id", id), config.http.base_url),
|
|
||||||
{
|
|
||||||
method: "GET",
|
method: "GET",
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(401);
|
expect(response.status).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 404 if emoji does not exist", async () => {
|
test("should return 404 if emoji does not exist", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
meta.route.replace(":id", "00000000-0000-0000-0000-000000000000"),
|
||||||
new URL(
|
|
||||||
meta.route.replace(
|
|
||||||
":id",
|
|
||||||
"00000000-0000-0000-0000-000000000000",
|
|
||||||
),
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
},
|
},
|
||||||
method: "GET",
|
method: "GET",
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(404);
|
expect(response.status).toBe(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should not work if the user is trying to update an emoji they don't own", async () => {
|
test("should not work if the user is trying to update an emoji they don't own", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route.replace(":id", id), {
|
||||||
new Request(
|
|
||||||
new URL(meta.route.replace(":id", id), config.http.base_url),
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
@ -92,25 +74,18 @@ describe(meta.route, () => {
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
shortcode: "test2",
|
shortcode: "test2",
|
||||||
}),
|
}),
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(403);
|
expect(response.status).toBe(403);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return the emoji", async () => {
|
test("should return the emoji", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route.replace(":id", id), {
|
||||||
new Request(
|
|
||||||
new URL(meta.route.replace(":id", id), config.http.base_url),
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
},
|
},
|
||||||
method: "GET",
|
method: "GET",
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.ok).toBe(true);
|
expect(response.ok).toBe(true);
|
||||||
const emoji = await response.json();
|
const emoji = await response.json();
|
||||||
|
|
@ -118,10 +93,7 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should update the emoji", async () => {
|
test("should update the emoji", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route.replace(":id", id), {
|
||||||
new Request(
|
|
||||||
new URL(meta.route.replace(":id", id), config.http.base_url),
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
@ -130,9 +102,7 @@ describe(meta.route, () => {
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
shortcode: "test2",
|
shortcode: "test2",
|
||||||
}),
|
}),
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.ok).toBe(true);
|
expect(response.ok).toBe(true);
|
||||||
const emoji = await response.json();
|
const emoji = await response.json();
|
||||||
|
|
@ -140,22 +110,16 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should update the emoji with another url, but keep the shortcode", async () => {
|
test("should update the emoji with another url, but keep the shortcode", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route.replace(":id", id), {
|
||||||
new Request(
|
|
||||||
new URL(meta.route.replace(":id", id), config.http.base_url),
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
element:
|
element: "https://avatars.githubusercontent.com/u/30842467?v=4",
|
||||||
"https://avatars.githubusercontent.com/u/30842467?v=4",
|
|
||||||
}),
|
}),
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.ok).toBe(true);
|
expect(response.ok).toBe(true);
|
||||||
const emoji = await response.json();
|
const emoji = await response.json();
|
||||||
|
|
@ -163,10 +127,7 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should update the emoji to be non-global", async () => {
|
test("should update the emoji to be non-global", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route.replace(":id", id), {
|
||||||
new Request(
|
|
||||||
new URL(meta.route.replace(":id", id), config.http.base_url),
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
@ -175,24 +136,17 @@ describe(meta.route, () => {
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
global: false,
|
global: false,
|
||||||
}),
|
}),
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.ok).toBe(true);
|
expect(response.ok).toBe(true);
|
||||||
|
|
||||||
// Check if the other user can see it
|
// Check if the other user can see it
|
||||||
const response2 = await sendTestRequest(
|
const response2 = await fakeRequest("/api/v1/custom_emojis", {
|
||||||
new Request(
|
|
||||||
new URL("/api/v1/custom_emojis", config.http.base_url),
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
method: "GET",
|
method: "GET",
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response2.ok).toBe(true);
|
expect(response2.ok).toBe(true);
|
||||||
const emojis = await response2.json();
|
const emojis = await response2.json();
|
||||||
|
|
@ -200,17 +154,12 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should delete the emoji", async () => {
|
test("should delete the emoji", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route.replace(":id", id), {
|
||||||
new Request(
|
|
||||||
new URL(meta.route.replace(":id", id), config.http.base_url),
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
},
|
},
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(204);
|
expect(response.status).toBe(204);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,7 @@ import { inArray } from "drizzle-orm";
|
||||||
import sharp from "sharp";
|
import sharp from "sharp";
|
||||||
import { db } from "~/drizzle/db";
|
import { db } from "~/drizzle/db";
|
||||||
import { Emojis } from "~/drizzle/schema";
|
import { Emojis } from "~/drizzle/schema";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(3);
|
const { users, tokens, deleteUsers } = await getTestUsers(3);
|
||||||
|
|
@ -41,8 +40,7 @@ const createImage = async (name: string): Promise<File> => {
|
||||||
|
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 401 if not authenticated", async () => {
|
test("should return 401 if not authenticated", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
@ -51,8 +49,7 @@ describe(meta.route, () => {
|
||||||
shortcode: "test",
|
shortcode: "test",
|
||||||
element: "https://cdn.versia.social/logo.webp",
|
element: "https://cdn.versia.social/logo.webp",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(401);
|
expect(response.status).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
@ -64,15 +61,13 @@ describe(meta.route, () => {
|
||||||
formData.append("element", await createImage("test.png"));
|
formData.append("element", await createImage("test.png"));
|
||||||
formData.append("global", "true");
|
formData.append("global", "true");
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
},
|
},
|
||||||
body: formData,
|
body: formData,
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.ok).toBe(true);
|
expect(response.ok).toBe(true);
|
||||||
const emoji = await response.json();
|
const emoji = await response.json();
|
||||||
|
|
@ -85,22 +80,19 @@ describe(meta.route, () => {
|
||||||
formData.append("shortcode", "test2");
|
formData.append("shortcode", "test2");
|
||||||
formData.append("element", new File(["test"], "test.txt"));
|
formData.append("element", new File(["test"], "test.txt"));
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
},
|
},
|
||||||
body: formData,
|
body: formData,
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(422);
|
expect(response.status).toBe(422);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should upload an emoji by url", async () => {
|
test("should upload an emoji by url", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
|
|
@ -110,8 +102,7 @@ describe(meta.route, () => {
|
||||||
shortcode: "test3",
|
shortcode: "test3",
|
||||||
element: "https://cdn.versia.social/logo.webp",
|
element: "https://cdn.versia.social/logo.webp",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.ok).toBe(true);
|
expect(response.ok).toBe(true);
|
||||||
const emoji = await response.json();
|
const emoji = await response.json();
|
||||||
|
|
@ -124,15 +115,13 @@ describe(meta.route, () => {
|
||||||
formData.append("shortcode", "test1");
|
formData.append("shortcode", "test1");
|
||||||
formData.append("element", await createImage("test-image.png"));
|
formData.append("element", await createImage("test-image.png"));
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
},
|
},
|
||||||
body: formData,
|
body: formData,
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(422);
|
expect(response.status).toBe(422);
|
||||||
});
|
});
|
||||||
|
|
@ -144,15 +133,13 @@ describe(meta.route, () => {
|
||||||
formData.append("shortcode", "test4");
|
formData.append("shortcode", "test4");
|
||||||
formData.append("element", await createImage("test-image.png"));
|
formData.append("element", await createImage("test-image.png"));
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
body: formData,
|
body: formData,
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.ok).toBe(true);
|
expect(response.ok).toBe(true);
|
||||||
const emoji = await response.json();
|
const emoji = await response.json();
|
||||||
|
|
@ -165,15 +152,13 @@ describe(meta.route, () => {
|
||||||
formData.append("shortcode", "test1");
|
formData.append("shortcode", "test1");
|
||||||
formData.append("element", await createImage("test-image.png"));
|
formData.append("element", await createImage("test-image.png"));
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
body: formData,
|
body: formData,
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(422);
|
expect(response.status).toBe(422);
|
||||||
});
|
});
|
||||||
|
|
@ -183,15 +168,13 @@ describe(meta.route, () => {
|
||||||
formData.append("shortcode", "test4");
|
formData.append("shortcode", "test4");
|
||||||
formData.append("element", await createImage("test-image.png"));
|
formData.append("element", await createImage("test-image.png"));
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[2].accessToken}`,
|
Authorization: `Bearer ${tokens[2].accessToken}`,
|
||||||
},
|
},
|
||||||
body: formData,
|
body: formData,
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.ok).toBe(true);
|
expect(response.ok).toBe(true);
|
||||||
const emoji = await response.json();
|
const emoji = await response.json();
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,11 @@
|
||||||
import { describe, expect, test } from "bun:test";
|
import { describe, expect, test } from "bun:test";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest } from "~/tests/utils";
|
||||||
import { sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./extended_description";
|
import { meta } from "./extended_description";
|
||||||
|
|
||||||
// /api/v1/instance/extended_description
|
// /api/v1/instance/extended_description
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return extended description", async () => {
|
test("should return extended description", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route);
|
||||||
new Request(new URL(meta.route, config.http.base_url)),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,11 @@
|
||||||
import { describe, expect, test } from "bun:test";
|
import { describe, expect, test } from "bun:test";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest } from "~/tests/utils";
|
||||||
import { sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./privacy_policy";
|
import { meta } from "./privacy_policy";
|
||||||
|
|
||||||
// /api/v1/instance/privacy_policy
|
// /api/v1/instance/privacy_policy
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return privacy policy", async () => {
|
test("should return privacy policy", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route);
|
||||||
new Request(new URL(meta.route, config.http.base_url)),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,12 @@
|
||||||
import { describe, expect, test } from "bun:test";
|
import { describe, expect, test } from "bun:test";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { config } from "~/packages/config-manager/index";
|
||||||
import { sendTestRequest } from "~/tests/utils";
|
import { fakeRequest } from "~/tests/utils";
|
||||||
import { meta } from "./rules";
|
import { meta } from "./rules";
|
||||||
|
|
||||||
// /api/v1/instance/rules
|
// /api/v1/instance/rules
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return rules", async () => {
|
test("should return rules", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route);
|
||||||
new Request(new URL(meta.route, config.http.base_url)),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,11 @@
|
||||||
import { describe, expect, test } from "bun:test";
|
import { describe, expect, test } from "bun:test";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest } from "~/tests/utils";
|
||||||
import { sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./tos";
|
import { meta } from "./tos";
|
||||||
|
|
||||||
// /api/v1/instance/tos
|
// /api/v1/instance/tos
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return terms of service", async () => {
|
test("should return terms of service", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route);
|
||||||
new Request(new URL(meta.route, config.http.base_url)),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import { afterAll, describe, expect, test } from "bun:test";
|
import { afterAll, describe, expect, test } from "bun:test";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestStatuses, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestStatuses, getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(1);
|
const { users, tokens, deleteUsers } = await getTestUsers(1);
|
||||||
|
|
@ -13,21 +12,15 @@ afterAll(async () => {
|
||||||
// /api/v1/markers
|
// /api/v1/markers
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 401 if not authenticated", async () => {
|
test("should return 401 if not authenticated", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "GET",
|
method: "GET",
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
expect(response.status).toBe(401);
|
expect(response.status).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return empty markers", async () => {
|
test("should return empty markers", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
`${meta.route}?${new URLSearchParams([
|
||||||
`${new URL(
|
|
||||||
meta.route,
|
|
||||||
config.http.base_url,
|
|
||||||
)}?${new URLSearchParams([
|
|
||||||
["timeline[]", "home"],
|
["timeline[]", "home"],
|
||||||
["timeline[]", "notifications"],
|
["timeline[]", "notifications"],
|
||||||
])}`,
|
])}`,
|
||||||
|
|
@ -37,7 +30,6 @@ describe(meta.route, () => {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -45,21 +37,17 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should create markers", async () => {
|
test("should create markers", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`${meta.route}?${new URLSearchParams({
|
`${meta.route}?${new URLSearchParams({
|
||||||
"home[last_read_id]": timeline[0].id,
|
"home[last_read_id]": timeline[0].id,
|
||||||
})}`,
|
})}`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -73,12 +61,8 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return markers", async () => {
|
test("should return markers", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
`${meta.route}?${new URLSearchParams([
|
||||||
`${new URL(
|
|
||||||
meta.route,
|
|
||||||
config.http.base_url,
|
|
||||||
)}?${new URLSearchParams([
|
|
||||||
["timeline[]", "home"],
|
["timeline[]", "home"],
|
||||||
["timeline[]", "notifications"],
|
["timeline[]", "notifications"],
|
||||||
])}`,
|
])}`,
|
||||||
|
|
@ -88,7 +72,6 @@ describe(meta.route, () => {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(3);
|
const { users, tokens, deleteUsers } = await getTestUsers(3);
|
||||||
|
|
@ -10,12 +9,9 @@ afterAll(async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/accounts/${users[1].id}/mute`,
|
`/api/v1/accounts/${users[1].id}/mute`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -24,7 +20,6 @@ beforeAll(async () => {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
});
|
});
|
||||||
|
|
@ -32,29 +27,23 @@ beforeAll(async () => {
|
||||||
// /api/v1/mutes
|
// /api/v1/mutes
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 401 if not authenticated", async () => {
|
test("should return 401 if not authenticated", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", users[1].id),
|
meta.route.replace(":id", users[1].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "GET",
|
method: "GET",
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
expect(response.status).toBe(401);
|
expect(response.status).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return mutes", async () => {
|
test("should return mutes", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
const body = await response.json();
|
const body = await response.json();
|
||||||
expect(body).toEqual(
|
expect(body).toEqual(
|
||||||
|
|
@ -67,12 +56,9 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return mutes after unmute", async () => {
|
test("should return mutes after unmute", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/accounts/${users[1].id}/unmute`,
|
`/api/v1/accounts/${users[1].id}/unmute`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -81,18 +67,15 @@ describe(meta.route, () => {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
const response2 = await sendTestRequest(
|
const response2 = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
expect(response2.status).toBe(200);
|
expect(response2.status).toBe(200);
|
||||||
const body = await response2.json();
|
const body = await response2.json();
|
||||||
expect(body).toEqual([]);
|
expect(body).toEqual([]);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||||
import type { Notification as ApiNotification } from "@versia/client/types";
|
import type { Notification as ApiNotification } from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./dismiss";
|
import { meta } from "./dismiss";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
||||||
|
|
@ -9,30 +8,20 @@ let notifications: ApiNotification[] = [];
|
||||||
|
|
||||||
// Create some test notifications: follow, favourite, reblog, mention
|
// Create some test notifications: follow, favourite, reblog, mention
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await sendTestRequest(
|
await fakeRequest(`/api/v1/accounts/${users[0].id}/follow`, {
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/accounts/${users[0].id}/follow`,
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
notifications = await sendTestRequest(
|
notifications = await fakeRequest("/api/v1/notifications", {
|
||||||
new Request(new URL("/api/v1/notifications", config.http.base_url), {
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
}),
|
}).then((r) => r.json());
|
||||||
).then((r) => r.json());
|
|
||||||
|
|
||||||
expect(notifications.length).toBe(1);
|
expect(notifications.length).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
@ -44,51 +33,36 @@ afterAll(async () => {
|
||||||
// /api/v1/notifications/:id/dismiss
|
// /api/v1/notifications/:id/dismiss
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 401 if not authenticated", async () => {
|
test("should return 401 if not authenticated", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", notifications[0].id),
|
meta.route.replace(":id", notifications[0].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(401);
|
expect(response.status).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should dismiss notification", async () => {
|
test("should dismiss notification", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", notifications[0].id),
|
meta.route.replace(":id", notifications[0].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should not display dismissed notification", async () => {
|
test("should not display dismissed notification", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest("/api/v1/notifications", {
|
||||||
new Request(
|
|
||||||
new URL("/api/v1/notifications", config.http.base_url),
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||||
import type { Notification as ApiNotification } from "@versia/client/types";
|
import type { Notification as ApiNotification } from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
||||||
|
|
@ -9,30 +8,20 @@ let notifications: ApiNotification[] = [];
|
||||||
|
|
||||||
// Create some test notifications: follow, favourite, reblog, mention
|
// Create some test notifications: follow, favourite, reblog, mention
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await sendTestRequest(
|
await fakeRequest(`/api/v1/accounts/${users[0].id}/follow`, {
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/accounts/${users[0].id}/follow`,
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
notifications = await sendTestRequest(
|
notifications = await fakeRequest("/api/v1/notifications", {
|
||||||
new Request(new URL("/api/v1/notifications", config.http.base_url), {
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
}),
|
}).then((r) => r.json());
|
||||||
).then((r) => r.json());
|
|
||||||
|
|
||||||
expect(notifications.length).toBe(1);
|
expect(notifications.length).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
@ -44,72 +33,46 @@ afterAll(async () => {
|
||||||
// /api/v1/notifications/:id
|
// /api/v1/notifications/:id
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 401 if not authenticated", async () => {
|
test("should return 401 if not authenticated", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
meta.route.replace(":id", "00000000-0000-0000-0000-000000000000"),
|
||||||
new URL(
|
|
||||||
meta.route.replace(
|
|
||||||
":id",
|
|
||||||
"00000000-0000-0000-0000-000000000000",
|
|
||||||
),
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(401);
|
expect(response.status).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 422 if ID is invalid", async () => {
|
test("should return 422 if ID is invalid", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", "invalid"),
|
meta.route.replace(":id", "invalid"),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
expect(response.status).toBe(422);
|
expect(response.status).toBe(422);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 404 if notification not found", async () => {
|
test("should return 404 if notification not found", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
meta.route.replace(":id", "00000000-0000-0000-0000-000000000000"),
|
||||||
new URL(
|
|
||||||
meta.route.replace(
|
|
||||||
":id",
|
|
||||||
"00000000-0000-0000-0000-000000000000",
|
|
||||||
),
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(404);
|
expect(response.status).toBe(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return notification", async () => {
|
test("should return notification", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", notifications[0].id),
|
meta.route.replace(":id", notifications[0].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||||
import type { Notification as ApiNotification } from "@versia/client/types";
|
import type { Notification as ApiNotification } from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
||||||
|
|
@ -9,30 +8,20 @@ let notifications: ApiNotification[] = [];
|
||||||
|
|
||||||
// Create some test notifications: follow, favourite, reblog, mention
|
// Create some test notifications: follow, favourite, reblog, mention
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await sendTestRequest(
|
await fakeRequest(`/api/v1/accounts/${users[0].id}/follow`, {
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/accounts/${users[0].id}/follow`,
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
notifications = await sendTestRequest(
|
notifications = await fakeRequest("/api/v1/notifications", {
|
||||||
new Request(new URL("/api/v1/notifications", config.http.base_url), {
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
}),
|
}).then((r) => r.json());
|
||||||
).then((r) => r.json());
|
|
||||||
|
|
||||||
expect(notifications.length).toBe(1);
|
expect(notifications.length).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
@ -44,37 +33,28 @@ afterAll(async () => {
|
||||||
// /api/v1/notifications/clear
|
// /api/v1/notifications/clear
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 401 if not authenticated", async () => {
|
test("should return 401 if not authenticated", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(401);
|
expect(response.status).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should clear notifications", async () => {
|
test("should clear notifications", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
const newNotifications = await sendTestRequest(
|
const newNotifications = await fakeRequest("/api/v1/notifications", {
|
||||||
new Request(
|
|
||||||
new URL("/api/v1/notifications", config.http.base_url),
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
}).then((r) => r.json());
|
||||||
),
|
|
||||||
).then((r) => r.json());
|
|
||||||
|
|
||||||
expect(newNotifications.length).toBe(0);
|
expect(newNotifications.length).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||||
import type { Notification as ApiNotification } from "@versia/client/types";
|
import type { Notification as ApiNotification } from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestStatuses, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestStatuses, getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
||||||
|
|
@ -10,49 +9,31 @@ let notifications: ApiNotification[] = [];
|
||||||
|
|
||||||
// Create some test notifications
|
// Create some test notifications
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await sendTestRequest(
|
await fakeRequest(`/api/v1/accounts/${users[0].id}/follow`, {
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/accounts/${users[0].id}/follow`,
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const i of [0, 1, 2, 3]) {
|
for (const i of [0, 1, 2, 3]) {
|
||||||
await sendTestRequest(
|
await fakeRequest(`/api/v1/statuses/${statuses[i].id}/favourite`, {
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/statuses/${statuses[i].id}/favourite`,
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
notifications = await sendTestRequest(
|
notifications = await fakeRequest("/api/v1/notifications", {
|
||||||
new Request(new URL("/api/v1/notifications", config.http.base_url), {
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
}),
|
}).then((r) => r.json());
|
||||||
).then((r) => r.json());
|
|
||||||
|
|
||||||
expect(notifications.length).toBe(5);
|
expect(notifications.length).toBe(5);
|
||||||
});
|
});
|
||||||
|
|
@ -64,55 +45,40 @@ afterAll(async () => {
|
||||||
// /api/v1/notifications/destroy_multiple
|
// /api/v1/notifications/destroy_multiple
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 401 if not authenticated", async () => {
|
test("should return 401 if not authenticated", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`${meta.route}?${new URLSearchParams(
|
`${meta.route}?${new URLSearchParams(
|
||||||
notifications.slice(1).map((n) => ["ids[]", n.id]),
|
notifications.slice(1).map((n) => ["ids[]", n.id]),
|
||||||
).toString()}`,
|
).toString()}`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(401);
|
expect(response.status).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should dismiss notifications", async () => {
|
test("should dismiss notifications", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`${meta.route}?${new URLSearchParams(
|
`${meta.route}?${new URLSearchParams(
|
||||||
notifications.slice(1).map((n) => ["ids[]", n.id]),
|
notifications.slice(1).map((n) => ["ids[]", n.id]),
|
||||||
).toString()}`,
|
).toString()}`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should not display dismissed notification", async () => {
|
test("should not display dismissed notification", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest("/api/v1/notifications", {
|
||||||
new Request(
|
|
||||||
new URL("/api/v1/notifications", config.http.base_url),
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||||
import type { Notification as ApiNotification } from "@versia/client/types";
|
import type { Notification as ApiNotification } from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestStatuses, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestStatuses, getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
const getFormData = (object: Record<string, string | number | boolean>) =>
|
const getFormData = (object: Record<string, string | number | boolean>) =>
|
||||||
|
|
@ -14,31 +13,19 @@ const { users, tokens, deleteUsers } = await getTestUsers(2);
|
||||||
const timeline = (await getTestStatuses(40, users[0])).toReversed();
|
const timeline = (await getTestStatuses(40, users[0])).toReversed();
|
||||||
// Create some test notifications: follow, favourite, reblog, mention
|
// Create some test notifications: follow, favourite, reblog, mention
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const res1 = await sendTestRequest(
|
const res1 = await fakeRequest(`/api/v1/accounts/${users[0].id}/follow`, {
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/accounts/${users[0].id}/follow`,
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(res1.status).toBe(200);
|
expect(res1.status).toBe(200);
|
||||||
|
|
||||||
const res2 = await sendTestRequest(
|
const res2 = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/statuses/${timeline[0].id}/favourite`,
|
`/api/v1/statuses/${timeline[0].id}/favourite`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -47,17 +34,12 @@ beforeAll(async () => {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(res2.status).toBe(200);
|
expect(res2.status).toBe(200);
|
||||||
|
|
||||||
const res3 = await sendTestRequest(
|
const res3 = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/statuses/${timeline[0].id}/reblog`,
|
`/api/v1/statuses/${timeline[0].id}/reblog`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -65,13 +47,11 @@ beforeAll(async () => {
|
||||||
},
|
},
|
||||||
body: getFormData({}),
|
body: getFormData({}),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(res3.status).toBe(200);
|
expect(res3.status).toBe(200);
|
||||||
|
|
||||||
const res4 = await sendTestRequest(
|
const res4 = await fakeRequest("/api/v1/statuses", {
|
||||||
new Request(new URL("/api/v1/statuses", config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
|
|
@ -81,8 +61,7 @@ beforeAll(async () => {
|
||||||
visibility: "direct",
|
visibility: "direct",
|
||||||
local_only: "true",
|
local_only: "true",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(res4.status).toBe(200);
|
expect(res4.status).toBe(200);
|
||||||
});
|
});
|
||||||
|
|
@ -94,21 +73,17 @@ afterAll(async () => {
|
||||||
// /api/v1/notifications
|
// /api/v1/notifications
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 401 if not authenticated", async () => {
|
test("should return 401 if not authenticated", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route);
|
||||||
new Request(new URL(meta.route, config.http.base_url)),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(401);
|
expect(response.status).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 200 with notifications", async () => {
|
test("should return 200 with notifications", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
@ -133,8 +108,7 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should not return notifications with filtered keywords", async () => {
|
test("should not return notifications with filtered keywords", async () => {
|
||||||
const filterResponse = await sendTestRequest(
|
const filterResponse = await fakeRequest("/api/v2/filters", {
|
||||||
new Request(new URL("/api/v2/filters", config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
|
|
@ -144,25 +118,21 @@ describe(meta.route, () => {
|
||||||
title: "Test Filter",
|
title: "Test Filter",
|
||||||
"context[]": "notifications",
|
"context[]": "notifications",
|
||||||
filter_action: "hide",
|
filter_action: "hide",
|
||||||
"keywords_attributes[0][keyword]":
|
"keywords_attributes[0][keyword]": timeline[0].content.slice(
|
||||||
timeline[0].content.slice(4, 20),
|
4,
|
||||||
|
20,
|
||||||
|
),
|
||||||
"keywords_attributes[0][whole_word]": "false",
|
"keywords_attributes[0][whole_word]": "false",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(filterResponse.status).toBe(200);
|
expect(filterResponse.status).toBe(200);
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(`${meta.route}?limit=20`, {
|
||||||
new Request(
|
|
||||||
new URL(`${meta.route}?limit=20`, config.http.base_url),
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
@ -180,19 +150,14 @@ describe(meta.route, () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Delete filter
|
// Delete filter
|
||||||
const filterDeleteResponse = await sendTestRequest(
|
const filterDeleteResponse = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v2/filters/${(await filterResponse.json()).id}`,
|
`/api/v2/filters/${(await filterResponse.json()).id}`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(filterDeleteResponse.status).toBe(200);
|
expect(filterDeleteResponse.status).toBe(200);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||||
import { ADMIN_ROLES, DEFAULT_ROLES, RolePermissions } from "~/drizzle/schema";
|
import { ADMIN_ROLES, DEFAULT_ROLES, RolePermissions } from "~/drizzle/schema";
|
||||||
import { config } from "~/packages/config-manager/index";
|
|
||||||
import { Role } from "~/packages/database-interface/role";
|
import { Role } from "~/packages/database-interface/role";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(1);
|
const { users, tokens, deleteUsers } = await getTestUsers(1);
|
||||||
|
|
@ -61,58 +60,34 @@ afterAll(async () => {
|
||||||
// /api/v1/roles/:id
|
// /api/v1/roles/:id
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 401 if not authenticated", async () => {
|
test("should return 401 if not authenticated", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route.replace(":id", role.id), {
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", role.id),
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
|
||||||
method: "GET",
|
method: "GET",
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(401);
|
expect(response.status).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 404 if role does not exist", async () => {
|
test("should return 404 if role does not exist", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
meta.route.replace(":id", "00000000-0000-0000-0000-000000000000"),
|
||||||
new URL(
|
|
||||||
meta.route.replace(
|
|
||||||
":id",
|
|
||||||
"00000000-0000-0000-0000-000000000000",
|
|
||||||
),
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(404);
|
expect(response.status).toBe(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return the role", async () => {
|
test("should return the role", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route.replace(":id", role.id), {
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", role.id),
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.ok).toBe(true);
|
expect(response.ok).toBe(true);
|
||||||
const output = await response.json();
|
const output = await response.json();
|
||||||
|
|
@ -127,19 +102,14 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 403 if user does not have MANAGE_ROLES permission", async () => {
|
test("should return 403 if user does not have MANAGE_ROLES permission", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", roleNotLinked.id),
|
meta.route.replace(":id", roleNotLinked.id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(403);
|
expect(response.status).toBe(403);
|
||||||
|
|
@ -154,32 +124,25 @@ describe(meta.route, () => {
|
||||||
permissions: [RolePermissions.ManageRoles],
|
permissions: [RolePermissions.ManageRoles],
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", roleNotLinked.id),
|
meta.route.replace(":id", roleNotLinked.id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(204);
|
expect(response.status).toBe(204);
|
||||||
|
|
||||||
// Check if role was assigned
|
// Check if role was assigned
|
||||||
const response2 = await sendTestRequest(
|
const response2 = await fakeRequest("/api/v1/roles", {
|
||||||
new Request(new URL("/api/v1/roles", config.http.base_url), {
|
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response2.ok).toBe(true);
|
expect(response2.ok).toBe(true);
|
||||||
const roles = await response2.json();
|
const roles = await response2.json();
|
||||||
|
|
@ -201,32 +164,22 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should unassign role", async () => {
|
test("should unassign role", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route.replace(":id", role.id), {
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", role.id),
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(204);
|
expect(response.status).toBe(204);
|
||||||
|
|
||||||
// Check if role was unassigned
|
// Check if role was unassigned
|
||||||
const response2 = await sendTestRequest(
|
const response2 = await fakeRequest("/api/v1/roles", {
|
||||||
new Request(new URL("/api/v1/roles", config.http.base_url), {
|
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response2.ok).toBe(true);
|
expect(response2.ok).toBe(true);
|
||||||
const roles = await response2.json();
|
const roles = await response2.json();
|
||||||
|
|
@ -248,19 +201,14 @@ describe(meta.route, () => {
|
||||||
permissions: [RolePermissions.ManageRoles],
|
permissions: [RolePermissions.ManageRoles],
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", higherPriorityRole.id),
|
meta.route.replace(":id", higherPriorityRole.id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(403);
|
expect(response.status).toBe(403);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||||
import { ADMIN_ROLES } from "~/drizzle/schema";
|
import { ADMIN_ROLES } from "~/drizzle/schema";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { config } from "~/packages/config-manager/index";
|
||||||
import { Role } from "~/packages/database-interface/role";
|
import { Role } from "~/packages/database-interface/role";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
const { users, deleteUsers, tokens } = await getTestUsers(1);
|
const { users, deleteUsers, tokens } = await getTestUsers(1);
|
||||||
|
|
@ -32,24 +32,20 @@ afterAll(async () => {
|
||||||
// /api/v1/roles
|
// /api/v1/roles
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 401 if not authenticated", async () => {
|
test("should return 401 if not authenticated", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "GET",
|
method: "GET",
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(401);
|
expect(response.status).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return a list of roles", async () => {
|
test("should return a list of roles", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.ok).toBe(true);
|
expect(response.ok).toBe(true);
|
||||||
const roles = await response.json();
|
const roles = await response.json();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import { afterAll, describe, expect, test } from "bun:test";
|
import { afterAll, describe, expect, test } from "bun:test";
|
||||||
import { config } from "~/packages/config-manager";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
const { deleteUsers, tokens } = await getTestUsers(1);
|
const { deleteUsers, tokens } = await getTestUsers(1);
|
||||||
|
|
@ -12,19 +11,14 @@ afterAll(async () => {
|
||||||
// /api/v1/sso/:id
|
// /api/v1/sso/:id
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should not find unknown issuer", async () => {
|
test("should not find unknown issuer", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", "unknown"),
|
meta.route.replace(":id", "unknown"),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0]?.accessToken}`,
|
Authorization: `Bearer ${tokens[0]?.accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(404);
|
expect(response.status).toBe(404);
|
||||||
|
|
@ -32,12 +26,8 @@ describe(meta.route, () => {
|
||||||
error: "Issuer not found",
|
error: "Issuer not found",
|
||||||
});
|
});
|
||||||
|
|
||||||
const response2 = await sendTestRequest(
|
const response2 = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", "unknown"),
|
meta.route.replace(":id", "unknown"),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -45,7 +35,6 @@ describe(meta.route, () => {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response2.status).toBe(404);
|
expect(response2.status).toBe(404);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import { afterAll, describe, expect, test } from "bun:test";
|
import { afterAll, describe, expect, test } from "bun:test";
|
||||||
import { config } from "~/packages/config-manager";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
const { deleteUsers, tokens } = await getTestUsers(1);
|
const { deleteUsers, tokens } = await getTestUsers(1);
|
||||||
|
|
@ -12,22 +11,19 @@ afterAll(async () => {
|
||||||
// /api/v1/sso
|
// /api/v1/sso
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return empty list", async () => {
|
test("should return empty list", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0]?.accessToken}`,
|
Authorization: `Bearer ${tokens[0]?.accessToken}`,
|
||||||
},
|
},
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(await response.json()).toMatchObject([]);
|
expect(await response.json()).toMatchObject([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return an error if provider doesn't exist", async () => {
|
test("should return an error if provider doesn't exist", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0]?.accessToken}`,
|
Authorization: `Bearer ${tokens[0]?.accessToken}`,
|
||||||
|
|
@ -36,8 +32,7 @@ describe(meta.route, () => {
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
issuer: "unknown",
|
issuer: "unknown",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(404);
|
expect(response.status).toBe(404);
|
||||||
expect(await response.json()).toMatchObject({
|
expect(await response.json()).toMatchObject({
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { afterAll, describe, expect, test } from "bun:test";
|
import { afterAll, describe, expect, test } from "bun:test";
|
||||||
import type { Status as ApiStatus } from "@versia/client/types";
|
import type { Status as ApiStatus } from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestStatuses, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestStatuses, getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./favourite";
|
import { meta } from "./favourite";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
||||||
|
|
@ -14,35 +13,25 @@ afterAll(async () => {
|
||||||
// /api/v1/statuses/:id/favourite
|
// /api/v1/statuses/:id/favourite
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 401 if not authenticated", async () => {
|
test("should return 401 if not authenticated", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", timeline[0].id),
|
meta.route.replace(":id", timeline[0].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(401);
|
expect(response.status).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should favourite post", async () => {
|
test("should favourite post", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", timeline[0].id),
|
meta.route.replace(":id", timeline[0].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -54,18 +43,13 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("post should be favourited when fetched", async () => {
|
test("post should be favourited when fetched", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/statuses/${timeline[0].id}`,
|
`/api/v1/statuses/${timeline[0].id}`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||||
import type { Account as ApiAccount } from "@versia/client/types";
|
import type { Account as ApiAccount } from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestStatuses, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestStatuses, getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./favourited_by";
|
import { meta } from "./favourited_by";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
||||||
|
|
@ -13,51 +12,33 @@ afterAll(async () => {
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
for (const status of timeline) {
|
for (const status of timeline) {
|
||||||
await sendTestRequest(
|
await fakeRequest(`/api/v1/statuses/${status.id}/favourite`, {
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/statuses/${status.id}/favourite`,
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// /api/v1/statuses/:id/favourited_by
|
// /api/v1/statuses/:id/favourited_by
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 401 if not authenticated", async () => {
|
test("should return 401 if not authenticated", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", timeline[0].id),
|
meta.route.replace(":id", timeline[0].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(401);
|
expect(response.status).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 200 with users", async () => {
|
test("should return 200 with users", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", timeline[0].id),
|
meta.route.replace(":id", timeline[0].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||||
import type { Account as ApiAccount } from "@versia/client/types";
|
import type { Account as ApiAccount } from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestStatuses, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestStatuses, getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./reblogged_by";
|
import { meta } from "./reblogged_by";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
||||||
|
|
@ -13,51 +12,33 @@ afterAll(async () => {
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
for (const status of timeline) {
|
for (const status of timeline) {
|
||||||
await sendTestRequest(
|
await fakeRequest(`/api/v1/statuses/${status.id}/reblog`, {
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/statuses/${status.id}/reblog`,
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// /api/v1/statuses/:id/reblogged_by
|
// /api/v1/statuses/:id/reblogged_by
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 401 if not authenticated", async () => {
|
test("should return 401 if not authenticated", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", timeline[0].id),
|
meta.route.replace(":id", timeline[0].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(401);
|
expect(response.status).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 200 with users", async () => {
|
test("should return 200 with users", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", timeline[0].id),
|
meta.route.replace(":id", timeline[0].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
||||||
import type { Status as ApiStatus } from "@versia/client/types";
|
import type { Status as ApiStatus } from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestStatuses, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestStatuses, getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./unfavourite";
|
import { meta } from "./unfavourite";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
||||||
|
|
@ -14,35 +13,25 @@ afterAll(async () => {
|
||||||
// /api/v1/statuses/:id/unfavourite
|
// /api/v1/statuses/:id/unfavourite
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 401 if not authenticated", async () => {
|
test("should return 401 if not authenticated", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", timeline[0].id),
|
meta.route.replace(":id", timeline[0].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(401);
|
expect(response.status).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should be able to unfavourite post that is not favourited", async () => {
|
test("should be able to unfavourite post that is not favourited", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", timeline[0].id),
|
meta.route.replace(":id", timeline[0].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -50,35 +39,22 @@ describe(meta.route, () => {
|
||||||
|
|
||||||
test("should unfavourite post", async () => {
|
test("should unfavourite post", async () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await sendTestRequest(
|
await fakeRequest(`/api/v1/statuses/${timeline[1].id}/favourite`, {
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/statuses/${timeline[1].id}/favourite`,
|
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", timeline[1].id),
|
meta.route.replace(":id", timeline[1].id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -90,18 +66,13 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("post should not be favourited when fetched", async () => {
|
test("post should not be favourited when fetched", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v1/statuses/${timeline[1].id}`,
|
`/api/v1/statuses/${timeline[1].id}`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[1].accessToken}`,
|
Authorization: `Bearer ${tokens[1].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { eq } from "drizzle-orm";
|
||||||
import { db } from "~/drizzle/db";
|
import { db } from "~/drizzle/db";
|
||||||
import { Emojis } from "~/drizzle/schema";
|
import { Emojis } from "~/drizzle/schema";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { config } from "~/packages/config-manager/index";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
||||||
|
|
@ -25,35 +25,30 @@ beforeAll(async () => {
|
||||||
|
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 401 if not authenticated", async () => {
|
test("should return 401 if not authenticated", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: new URLSearchParams({
|
body: new URLSearchParams({
|
||||||
status: "Hello, world!",
|
status: "Hello, world!",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(401);
|
expect(response.status).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 422 is status is empty", async () => {
|
test("should return 422 is status is empty", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
body: new URLSearchParams(),
|
body: new URLSearchParams(),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(422);
|
expect(response.status).toBe(422);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 422 is status is too long", async () => {
|
test("should return 422 is status is too long", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
|
|
@ -62,15 +57,13 @@ describe(meta.route, () => {
|
||||||
status: "a".repeat(config.validation.max_note_size + 1),
|
status: "a".repeat(config.validation.max_note_size + 1),
|
||||||
local_only: "true",
|
local_only: "true",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(422);
|
expect(response.status).toBe(422);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 422 is visibility is invalid", async () => {
|
test("should return 422 is visibility is invalid", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
|
|
@ -80,15 +73,13 @@ describe(meta.route, () => {
|
||||||
visibility: "invalid",
|
visibility: "invalid",
|
||||||
local_only: "true",
|
local_only: "true",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(422);
|
expect(response.status).toBe(422);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 422 if scheduled_at is invalid", async () => {
|
test("should return 422 if scheduled_at is invalid", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
|
|
@ -98,15 +89,13 @@ describe(meta.route, () => {
|
||||||
scheduled_at: "invalid",
|
scheduled_at: "invalid",
|
||||||
local_only: "true",
|
local_only: "true",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(422);
|
expect(response.status).toBe(422);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 422 is in_reply_to_id is invalid", async () => {
|
test("should return 422 is in_reply_to_id is invalid", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
|
|
@ -116,15 +105,13 @@ describe(meta.route, () => {
|
||||||
in_reply_to_id: "invalid",
|
in_reply_to_id: "invalid",
|
||||||
local_only: "true",
|
local_only: "true",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(422);
|
expect(response.status).toBe(422);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 422 is quote_id is invalid", async () => {
|
test("should return 422 is quote_id is invalid", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
|
|
@ -134,15 +121,13 @@ describe(meta.route, () => {
|
||||||
quote_id: "invalid",
|
quote_id: "invalid",
|
||||||
local_only: "true",
|
local_only: "true",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(422);
|
expect(response.status).toBe(422);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 422 is media_ids is invalid", async () => {
|
test("should return 422 is media_ids is invalid", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
|
|
@ -152,15 +137,13 @@ describe(meta.route, () => {
|
||||||
"media_ids[]": "invalid",
|
"media_ids[]": "invalid",
|
||||||
local_only: "true",
|
local_only: "true",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(422);
|
expect(response.status).toBe(422);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should create a post", async () => {
|
test("should create a post", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
|
|
@ -169,8 +152,7 @@ describe(meta.route, () => {
|
||||||
status: "Hello, world!",
|
status: "Hello, world!",
|
||||||
local_only: "true",
|
local_only: "true",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
@ -184,8 +166,7 @@ describe(meta.route, () => {
|
||||||
|
|
||||||
test("should create a post with visibility", async () => {
|
test("should create a post with visibility", async () => {
|
||||||
// This one uses JSON to test the interop
|
// This one uses JSON to test the interop
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
|
|
@ -196,8 +177,7 @@ describe(meta.route, () => {
|
||||||
visibility: "unlisted",
|
visibility: "unlisted",
|
||||||
local_only: "true",
|
local_only: "true",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
@ -211,8 +191,7 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should create a post with a reply", async () => {
|
test("should create a post with a reply", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
|
|
@ -221,13 +200,11 @@ describe(meta.route, () => {
|
||||||
status: "Hello, world!",
|
status: "Hello, world!",
|
||||||
local_only: "true",
|
local_only: "true",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
const object = (await response.json()) as ApiStatus;
|
const object = (await response.json()) as ApiStatus;
|
||||||
|
|
||||||
const response2 = await sendTestRequest(
|
const response2 = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
|
|
@ -237,8 +214,7 @@ describe(meta.route, () => {
|
||||||
in_reply_to_id: object.id,
|
in_reply_to_id: object.id,
|
||||||
local_only: "true",
|
local_only: "true",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response2.status).toBe(200);
|
expect(response2.status).toBe(200);
|
||||||
expect(response2.headers.get("content-type")).toContain(
|
expect(response2.headers.get("content-type")).toContain(
|
||||||
|
|
@ -252,8 +228,7 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should create a post with a quote", async () => {
|
test("should create a post with a quote", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
|
|
@ -262,13 +237,11 @@ describe(meta.route, () => {
|
||||||
status: "Hello, world!",
|
status: "Hello, world!",
|
||||||
local_only: "true",
|
local_only: "true",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
const object = (await response.json()) as ApiStatus;
|
const object = (await response.json()) as ApiStatus;
|
||||||
|
|
||||||
const response2 = await sendTestRequest(
|
const response2 = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
|
|
@ -278,8 +251,7 @@ describe(meta.route, () => {
|
||||||
quote_id: object.id,
|
quote_id: object.id,
|
||||||
local_only: "true",
|
local_only: "true",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response2.status).toBe(200);
|
expect(response2.status).toBe(200);
|
||||||
expect(response2.headers.get("content-type")).toContain(
|
expect(response2.headers.get("content-type")).toContain(
|
||||||
|
|
@ -293,8 +265,7 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should correctly parse emojis", async () => {
|
test("should correctly parse emojis", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
|
|
@ -303,8 +274,7 @@ describe(meta.route, () => {
|
||||||
status: "Hello, :test:!",
|
status: "Hello, :test:!",
|
||||||
local_only: "true",
|
local_only: "true",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
@ -322,8 +292,7 @@ describe(meta.route, () => {
|
||||||
|
|
||||||
describe("mentions testing", () => {
|
describe("mentions testing", () => {
|
||||||
test("should correctly parse @mentions", async () => {
|
test("should correctly parse @mentions", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
|
|
@ -332,8 +301,7 @@ describe(meta.route, () => {
|
||||||
status: `Hello, @${users[1].data.username}!`,
|
status: `Hello, @${users[1].data.username}!`,
|
||||||
local_only: "true",
|
local_only: "true",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
@ -351,8 +319,7 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should correctly parse @mentions@domain", async () => {
|
test("should correctly parse @mentions@domain", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
|
|
@ -363,8 +330,7 @@ describe(meta.route, () => {
|
||||||
}!`,
|
}!`,
|
||||||
local_only: "true",
|
local_only: "true",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
@ -384,8 +350,7 @@ describe(meta.route, () => {
|
||||||
|
|
||||||
describe("HTML injection testing", () => {
|
describe("HTML injection testing", () => {
|
||||||
test("should not allow HTML injection", async () => {
|
test("should not allow HTML injection", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
|
|
@ -394,8 +359,7 @@ describe(meta.route, () => {
|
||||||
status: "Hi! <script>alert('Hello, world!');</script>",
|
status: "Hi! <script>alert('Hello, world!');</script>",
|
||||||
local_only: "true",
|
local_only: "true",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
@ -410,8 +374,7 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should not allow HTML injection in spoiler_text", async () => {
|
test("should not allow HTML injection in spoiler_text", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
|
|
@ -422,8 +385,7 @@ describe(meta.route, () => {
|
||||||
"uwu <script>alert('Hello, world!');</script>",
|
"uwu <script>alert('Hello, world!');</script>",
|
||||||
local_only: "true",
|
local_only: "true",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
@ -438,8 +400,7 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should rewrite all image and video src to go through proxy", async () => {
|
test("should rewrite all image and video src to go through proxy", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
|
|
@ -448,8 +409,7 @@ describe(meta.route, () => {
|
||||||
status: "<img src='https://example.com/image.jpg'> <video src='https://example.com/video.mp4'> Test!",
|
status: "<img src='https://example.com/image.jpg'> <video src='https://example.com/video.mp4'> Test!",
|
||||||
local_only: "true",
|
local_only: "true",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { afterAll, describe, expect, test } from "bun:test";
|
import { afterAll, describe, expect, test } from "bun:test";
|
||||||
import type { Status as ApiStatus } from "@versia/client/types";
|
import type { Status as ApiStatus } from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { config } from "~/packages/config-manager/index";
|
||||||
import { getTestStatuses, getTestUsers, sendTestRequest } from "~/tests/utils";
|
import { fakeRequest, getTestStatuses, getTestUsers } from "~/tests/utils";
|
||||||
import { meta } from "./home";
|
import { meta } from "./home";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
||||||
|
|
@ -13,24 +13,17 @@ afterAll(async () => {
|
||||||
|
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 401 if not authenticated", async () => {
|
test("should return 401 if not authenticated", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route);
|
||||||
new Request(new URL(meta.route, config.http.base_url)),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(401);
|
expect(response.status).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should correctly parse limit", async () => {
|
test("should correctly parse limit", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(`${meta.route}?limit=5`, {
|
||||||
new Request(
|
|
||||||
new URL(`${meta.route}?limit=5`, config.http.base_url),
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
@ -43,13 +36,11 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 200 with statuses", async () => {
|
test("should return 200 with statuses", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
@ -70,16 +61,11 @@ describe(meta.route, () => {
|
||||||
|
|
||||||
describe("should paginate properly", () => {
|
describe("should paginate properly", () => {
|
||||||
test("should send correct Link header", async () => {
|
test("should send correct Link header", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(`${meta.route}?limit=20`, {
|
||||||
new Request(
|
|
||||||
new URL(`${meta.route}?limit=20`, config.http.base_url),
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.headers.get("link")).toBe(
|
expect(response.headers.get("link")).toBe(
|
||||||
`<${config.http.base_url}/api/v1/timelines/home?limit=20&max_id=${timeline[19].id}>; rel="next"`,
|
`<${config.http.base_url}/api/v1/timelines/home?limit=20&max_id=${timeline[19].id}>; rel="next"`,
|
||||||
|
|
@ -87,18 +73,13 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should correct statuses with max", async () => {
|
test("should correct statuses with max", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`${meta.route}?limit=20&max_id=${timeline[19].id}`,
|
`${meta.route}?limit=20&max_id=${timeline[19].id}`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -119,18 +100,13 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should send correct Link prev header", async () => {
|
test("should send correct Link prev header", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`${meta.route}?limit=20&max_id=${timeline[19].id}`,
|
`${meta.route}?limit=20&max_id=${timeline[19].id}`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.headers.get("link")).toInclude(
|
expect(response.headers.get("link")).toInclude(
|
||||||
|
|
@ -139,18 +115,13 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should correct statuses with min_id", async () => {
|
test("should correct statuses with min_id", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`${meta.route}?limit=20&min_id=${timeline[20].id}`,
|
`${meta.route}?limit=20&min_id=${timeline[20].id}`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -171,8 +142,7 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should not return statuses with filtered keywords", async () => {
|
test("should not return statuses with filtered keywords", async () => {
|
||||||
const filterResponse = await sendTestRequest(
|
const filterResponse = await fakeRequest("/api/v2/filters", {
|
||||||
new Request(new URL("/api/v2/filters", config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
|
|
@ -186,21 +156,15 @@ describe(meta.route, () => {
|
||||||
timeline[0].content.slice(4, 20),
|
timeline[0].content.slice(4, 20),
|
||||||
"keywords_attributes[0][whole_word]": "false",
|
"keywords_attributes[0][whole_word]": "false",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(filterResponse.status).toBe(200);
|
expect(filterResponse.status).toBe(200);
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(`${meta.route}?limit=20`, {
|
||||||
new Request(
|
|
||||||
new URL(`${meta.route}?limit=20`, config.http.base_url),
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
@ -216,19 +180,14 @@ describe(meta.route, () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Delete filter
|
// Delete filter
|
||||||
const filterDeleteResponse = await sendTestRequest(
|
const filterDeleteResponse = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v2/filters/${(await filterResponse.json()).id}`,
|
`/api/v2/filters/${(await filterResponse.json()).id}`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(filterDeleteResponse.status).toBe(200);
|
expect(filterDeleteResponse.status).toBe(200);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { afterAll, describe, expect, test } from "bun:test";
|
import { afterAll, describe, expect, test } from "bun:test";
|
||||||
import type { Status as ApiStatus } from "@versia/client/types";
|
import type { Status as ApiStatus } from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { config } from "~/packages/config-manager/index";
|
||||||
import { getTestStatuses, getTestUsers, sendTestRequest } from "~/tests/utils";
|
import { fakeRequest, getTestStatuses, getTestUsers } from "~/tests/utils";
|
||||||
import { meta } from "./public";
|
import { meta } from "./public";
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
||||||
|
|
@ -13,16 +13,11 @@ afterAll(async () => {
|
||||||
|
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should correctly parse limit", async () => {
|
test("should correctly parse limit", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(`${meta.route}?limit=5`, {
|
||||||
new Request(
|
|
||||||
new URL(`${meta.route}?limit=5`, config.http.base_url),
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
@ -35,13 +30,11 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return 200 with statuses", async () => {
|
test("should return 200 with statuses", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
@ -61,18 +54,13 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should only fetch local statuses", async () => {
|
test("should only fetch local statuses", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`${meta.route}?limit=20&local=true`,
|
`${meta.route}?limit=20&local=true`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -93,18 +81,13 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should only fetch remote statuses", async () => {
|
test("should only fetch remote statuses", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`${meta.route}?remote=true&allow_local_only=false&only_media=false`,
|
`${meta.route}?remote=true&allow_local_only=false&only_media=false`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -119,16 +102,11 @@ describe(meta.route, () => {
|
||||||
|
|
||||||
describe("should paginate properly", () => {
|
describe("should paginate properly", () => {
|
||||||
test("should send correct Link header", async () => {
|
test("should send correct Link header", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(`${meta.route}?limit=20`, {
|
||||||
new Request(
|
|
||||||
new URL(`${meta.route}?limit=20`, config.http.base_url),
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.headers.get("link")).toBe(
|
expect(response.headers.get("link")).toBe(
|
||||||
`<${config.http.base_url}/api/v1/timelines/public?limit=20&max_id=${timeline[19].id}>; rel="next"`,
|
`<${config.http.base_url}/api/v1/timelines/public?limit=20&max_id=${timeline[19].id}>; rel="next"`,
|
||||||
|
|
@ -136,18 +114,13 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should correct statuses with max", async () => {
|
test("should correct statuses with max", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`${meta.route}?limit=20&max_id=${timeline[19].id}`,
|
`${meta.route}?limit=20&max_id=${timeline[19].id}`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -168,18 +141,13 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should send correct Link prev header", async () => {
|
test("should send correct Link prev header", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`${meta.route}?limit=20&max_id=${timeline[19].id}`,
|
`${meta.route}?limit=20&max_id=${timeline[19].id}`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.headers.get("link")).toInclude(
|
expect(response.headers.get("link")).toInclude(
|
||||||
|
|
@ -188,18 +156,13 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should correct statuses with min_id", async () => {
|
test("should correct statuses with min_id", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`${meta.route}?limit=20&min_id=${timeline[20].id}`,
|
`${meta.route}?limit=20&min_id=${timeline[20].id}`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -221,8 +184,7 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should not return statuses with filtered keywords", async () => {
|
test("should not return statuses with filtered keywords", async () => {
|
||||||
const filterResponse = await sendTestRequest(
|
const filterResponse = await fakeRequest("/api/v2/filters", {
|
||||||
new Request(new URL("/api/v2/filters", config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
|
|
@ -232,25 +194,21 @@ describe(meta.route, () => {
|
||||||
title: "Test Filter",
|
title: "Test Filter",
|
||||||
"context[]": "public",
|
"context[]": "public",
|
||||||
filter_action: "hide",
|
filter_action: "hide",
|
||||||
"keywords_attributes[0][keyword]":
|
"keywords_attributes[0][keyword]": timeline[0].content.slice(
|
||||||
timeline[0].content.slice(4, 20),
|
4,
|
||||||
|
20,
|
||||||
|
),
|
||||||
"keywords_attributes[0][whole_word]": "false",
|
"keywords_attributes[0][whole_word]": "false",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(filterResponse.status).toBe(200);
|
expect(filterResponse.status).toBe(200);
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(`${meta.route}?limit=20`, {
|
||||||
new Request(
|
|
||||||
new URL(`${meta.route}?limit=20`, config.http.base_url),
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
@ -266,19 +224,14 @@ describe(meta.route, () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Delete filter
|
// Delete filter
|
||||||
const filterDeleteResponse = await sendTestRequest(
|
const filterDeleteResponse = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/v2/filters/${(await filterResponse.json()).id}`,
|
`/api/v2/filters/${(await filterResponse.json()).id}`,
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(filterDeleteResponse.status).toBe(200);
|
expect(filterDeleteResponse.status).toBe(200);
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
import { afterAll, describe, expect, test } from "bun:test";
|
import { afterAll, describe, expect, test } from "bun:test";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
const { tokens, deleteUsers } = await getTestUsers(2);
|
const { tokens, deleteUsers } = await getTestUsers(2);
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest("/api/v2/filters", {
|
||||||
new Request(new URL("/api/v2/filters", config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
|
|
@ -20,8 +18,7 @@ const response = await sendTestRequest(
|
||||||
"keywords_attributes[0][keyword]": "test",
|
"keywords_attributes[0][keyword]": "test",
|
||||||
"keywords_attributes[0][whole_word]": "true",
|
"keywords_attributes[0][whole_word]": "true",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
|
|
@ -35,36 +32,26 @@ afterAll(async () => {
|
||||||
// /api/v2/filters/:id
|
// /api/v2/filters/:id
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 401 if not authenticated", async () => {
|
test("should return 401 if not authenticated", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", filter.id),
|
meta.route.replace(":id", filter.id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/x-www-form-urlencoded",
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(401);
|
expect(response.status).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should get that filter", async () => {
|
test("should get that filter", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", filter.id),
|
meta.route.replace(":id", filter.id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -83,12 +70,8 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should edit that filter", async () => {
|
test("should edit that filter", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", filter.id),
|
meta.route.replace(":id", filter.id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -105,7 +88,6 @@ describe(meta.route, () => {
|
||||||
"keywords_attributes[0][whole_word]": "false",
|
"keywords_attributes[0][whole_word]": "false",
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -124,12 +106,8 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should delete keyword", async () => {
|
test("should delete keyword", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", filter.id),
|
meta.route.replace(":id", filter.id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -140,7 +118,6 @@ describe(meta.route, () => {
|
||||||
"keywords_attributes[0][_destroy]": "true",
|
"keywords_attributes[0][_destroy]": "true",
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -150,18 +127,13 @@ describe(meta.route, () => {
|
||||||
expect(json.keywords).toBeEmpty();
|
expect(json.keywords).toBeEmpty();
|
||||||
|
|
||||||
// Get the filter again and check
|
// Get the filter again and check
|
||||||
const getResponse = await sendTestRequest(
|
const getResponse = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", filter.id),
|
meta.route.replace(":id", filter.id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(getResponse.status).toBe(200);
|
expect(getResponse.status).toBe(200);
|
||||||
|
|
@ -171,12 +143,8 @@ describe(meta.route, () => {
|
||||||
test("should delete filter", async () => {
|
test("should delete filter", async () => {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", filter.id),
|
meta.route.replace(":id", filter.id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -184,24 +152,18 @@ describe(meta.route, () => {
|
||||||
},
|
},
|
||||||
body: formData,
|
body: formData,
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
// Try to GET the filter again
|
// Try to GET the filter again
|
||||||
const getResponse = await sendTestRequest(
|
const getResponse = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
meta.route.replace(":id", filter.id),
|
meta.route.replace(":id", filter.id),
|
||||||
config.http.base_url,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(getResponse.status).toBe(404);
|
expect(getResponse.status).toBe(404);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import { afterAll, describe, expect, test } from "bun:test";
|
import { afterAll, describe, expect, test } from "bun:test";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestUsers, sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
const { tokens, deleteUsers } = await getTestUsers(2);
|
const { tokens, deleteUsers } = await getTestUsers(2);
|
||||||
|
|
@ -12,21 +11,17 @@ afterAll(async () => {
|
||||||
// /api/v2/filters
|
// /api/v2/filters
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return 401 if not authenticated", async () => {
|
test("should return 401 if not authenticated", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route);
|
||||||
new Request(new URL(meta.route, config.http.base_url)),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(401);
|
expect(response.status).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return user filters (none)", async () => {
|
test("should return user filters (none)", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
},
|
},
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
|
|
@ -45,8 +40,7 @@ describe(meta.route, () => {
|
||||||
formData.append("keywords_attributes[0][keyword]", "test");
|
formData.append("keywords_attributes[0][keyword]", "test");
|
||||||
formData.append("keywords_attributes[0][whole_word]", "true");
|
formData.append("keywords_attributes[0][whole_word]", "true");
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route, {
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
|
|
@ -60,8 +54,7 @@ describe(meta.route, () => {
|
||||||
"keywords_attributes[0][keyword]": "test",
|
"keywords_attributes[0][keyword]": "test",
|
||||||
"keywords_attributes[0][whole_word]": "true",
|
"keywords_attributes[0][whole_word]": "true",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,11 @@
|
||||||
import { describe, expect, test } from "bun:test";
|
import { describe, expect, test } from "bun:test";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest } from "~/tests/utils";
|
||||||
import { sendTestRequest } from "~/tests/utils";
|
|
||||||
import { meta } from "./index";
|
import { meta } from "./index";
|
||||||
|
|
||||||
// /api/v2/instance
|
// /api/v2/instance
|
||||||
describe(meta.route, () => {
|
describe(meta.route, () => {
|
||||||
test("should return instance information", async () => {
|
test("should return instance information", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(meta.route);
|
||||||
new Request(new URL(meta.route, config.http.base_url)),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
import { afterAll, describe, expect, test } from "bun:test";
|
import { afterAll, describe, expect, test } from "bun:test";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestUsers } from "./utils";
|
||||||
import { getTestUsers, sendTestRequest, wrapRelativeUrl } from "./utils";
|
|
||||||
|
|
||||||
const baseUrl = config.http.base_url;
|
|
||||||
|
|
||||||
const { tokens, deleteUsers } = await getTestUsers(1);
|
const { tokens, deleteUsers } = await getTestUsers(1);
|
||||||
|
|
||||||
|
|
@ -15,19 +12,14 @@ describe("API Tests", () => {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("test", "test");
|
formData.append("test", "test");
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest("/api/v1/statuses", {
|
||||||
new Request(
|
|
||||||
wrapRelativeUrl(`${baseUrl}/api/v1/statuses`, baseUrl),
|
|
||||||
{
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
"Content-Type": "multipart/form-data",
|
"Content-Type": "multipart/form-data",
|
||||||
},
|
},
|
||||||
body: formData,
|
body: formData,
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(400);
|
expect(response.status).toBe(400);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
@ -42,9 +34,8 @@ describe("API Tests", () => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
"/api/v1/instance",
|
"/api/v1/instance",
|
||||||
base_url.replace("https://", "http://"),
|
base_url.replace("https://", "http://"),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,7 @@ import type {
|
||||||
Relationship as ApiRelationship,
|
Relationship as ApiRelationship,
|
||||||
} from "@versia/client/types";
|
} from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { config } from "~/packages/config-manager/index";
|
||||||
import { getTestUsers, sendTestRequest, wrapRelativeUrl } from "~/tests/utils";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
|
|
||||||
const baseUrl = config.http.base_url;
|
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
||||||
const user = users[0];
|
const user = users[0];
|
||||||
|
|
@ -29,12 +27,8 @@ const getFormData = (object: Record<string, string | number | boolean>) =>
|
||||||
describe("API Tests", () => {
|
describe("API Tests", () => {
|
||||||
describe("PATCH /api/v1/accounts/update_credentials", () => {
|
describe("PATCH /api/v1/accounts/update_credentials", () => {
|
||||||
test("should update the authenticated user's display name", async () => {
|
test("should update the authenticated user's display name", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
wrapRelativeUrl(
|
|
||||||
"/api/v1/accounts/update_credentials",
|
"/api/v1/accounts/update_credentials",
|
||||||
baseUrl,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -44,7 +38,6 @@ describe("API Tests", () => {
|
||||||
display_name: "New Display Name",
|
display_name: "New Display Name",
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -60,18 +53,13 @@ describe("API Tests", () => {
|
||||||
|
|
||||||
describe("GET /api/v1/accounts/verify_credentials", () => {
|
describe("GET /api/v1/accounts/verify_credentials", () => {
|
||||||
test("should return the authenticated user's account information", async () => {
|
test("should return the authenticated user's account information", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
wrapRelativeUrl(
|
|
||||||
"/api/v1/accounts/verify_credentials",
|
"/api/v1/accounts/verify_credentials",
|
||||||
baseUrl,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token.accessToken}`,
|
Authorization: `Bearer ${token.accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -111,12 +99,8 @@ describe("API Tests", () => {
|
||||||
|
|
||||||
describe("POST /api/v1/accounts/:id/remove_from_followers", () => {
|
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 () => {
|
test("should remove the specified user from the authenticated user's followers and return an APIRelationship object", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
wrapRelativeUrl(
|
|
||||||
`/api/v1/accounts/${user2.id}/remove_from_followers`,
|
`/api/v1/accounts/${user2.id}/remove_from_followers`,
|
||||||
baseUrl,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -125,7 +109,6 @@ describe("API Tests", () => {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -142,12 +125,8 @@ describe("API Tests", () => {
|
||||||
|
|
||||||
describe("POST /api/v1/accounts/:id/block", () => {
|
describe("POST /api/v1/accounts/:id/block", () => {
|
||||||
test("should block the specified user and return an APIRelationship object", async () => {
|
test("should block the specified user and return an APIRelationship object", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
wrapRelativeUrl(
|
|
||||||
`/api/v1/accounts/${user2.id}/block`,
|
`/api/v1/accounts/${user2.id}/block`,
|
||||||
baseUrl,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -156,7 +135,6 @@ describe("API Tests", () => {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -173,14 +151,12 @@ describe("API Tests", () => {
|
||||||
|
|
||||||
describe("GET /api/v1/blocks", () => {
|
describe("GET /api/v1/blocks", () => {
|
||||||
test("should return an array of APIAccount objects for the user's blocked accounts", async () => {
|
test("should return an array of APIAccount objects for the user's blocked accounts", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest("/api/v1/blocks", {
|
||||||
new Request(wrapRelativeUrl("/api/v1/blocks", baseUrl), {
|
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token.accessToken}`,
|
Authorization: `Bearer ${token.accessToken}`,
|
||||||
},
|
},
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
@ -196,12 +172,8 @@ describe("API Tests", () => {
|
||||||
|
|
||||||
describe("POST /api/v1/accounts/:id/unblock", () => {
|
describe("POST /api/v1/accounts/:id/unblock", () => {
|
||||||
test("should unblock the specified user and return an APIRelationship object", async () => {
|
test("should unblock the specified user and return an APIRelationship object", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
wrapRelativeUrl(
|
|
||||||
`/api/v1/accounts/${user2.id}/unblock`,
|
`/api/v1/accounts/${user2.id}/unblock`,
|
||||||
baseUrl,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -210,7 +182,6 @@ describe("API Tests", () => {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -227,12 +198,8 @@ describe("API Tests", () => {
|
||||||
|
|
||||||
describe("POST /api/v1/accounts/:id/pin", () => {
|
describe("POST /api/v1/accounts/:id/pin", () => {
|
||||||
test("should pin the specified user and return an APIRelationship object", async () => {
|
test("should pin the specified user and return an APIRelationship object", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
wrapRelativeUrl(
|
|
||||||
`/api/v1/accounts/${user2.id}/pin`,
|
`/api/v1/accounts/${user2.id}/pin`,
|
||||||
baseUrl,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -241,7 +208,6 @@ describe("API Tests", () => {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -258,12 +224,8 @@ describe("API Tests", () => {
|
||||||
|
|
||||||
describe("POST /api/v1/accounts/:id/unpin", () => {
|
describe("POST /api/v1/accounts/:id/unpin", () => {
|
||||||
test("should unpin the specified user and return an APIRelationship object", async () => {
|
test("should unpin the specified user and return an APIRelationship object", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
wrapRelativeUrl(
|
|
||||||
`/api/v1/accounts/${user2.id}/unpin`,
|
`/api/v1/accounts/${user2.id}/unpin`,
|
||||||
baseUrl,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -272,7 +234,6 @@ describe("API Tests", () => {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -289,12 +250,8 @@ describe("API Tests", () => {
|
||||||
|
|
||||||
describe("POST /api/v1/accounts/:id/note", () => {
|
describe("POST /api/v1/accounts/:id/note", () => {
|
||||||
test("should update the specified account's note and return the updated account object", async () => {
|
test("should update the specified account's note and return the updated account object", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
wrapRelativeUrl(
|
|
||||||
`/api/v1/accounts/${user2.id}/note`,
|
`/api/v1/accounts/${user2.id}/note`,
|
||||||
baseUrl,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -303,7 +260,6 @@ describe("API Tests", () => {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ comment: "This is a new note" }),
|
body: JSON.stringify({ comment: "This is a new note" }),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -320,19 +276,14 @@ describe("API Tests", () => {
|
||||||
|
|
||||||
describe("GET /api/v1/accounts/relationships", () => {
|
describe("GET /api/v1/accounts/relationships", () => {
|
||||||
test("should return an array of APIRelationship objects for the authenticated user's relationships", async () => {
|
test("should return an array of APIRelationship objects for the authenticated user's relationships", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
wrapRelativeUrl(
|
|
||||||
`/api/v1/accounts/relationships?id[]=${user2.id}`,
|
`/api/v1/accounts/relationships?id[]=${user2.id}`,
|
||||||
baseUrl,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token.accessToken}`,
|
Authorization: `Bearer ${token.accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -358,17 +309,12 @@ describe("API Tests", () => {
|
||||||
|
|
||||||
describe("DELETE /api/v1/profile/avatar", () => {
|
describe("DELETE /api/v1/profile/avatar", () => {
|
||||||
test("should delete the avatar of the authenticated user and return the updated account object", async () => {
|
test("should delete the avatar of the authenticated user and return the updated account object", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest("/api/v1/profile/avatar", {
|
||||||
new Request(
|
|
||||||
wrapRelativeUrl("/api/v1/profile/avatar", baseUrl),
|
|
||||||
{
|
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token.accessToken}`,
|
Authorization: `Bearer ${token.accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
@ -384,17 +330,12 @@ describe("API Tests", () => {
|
||||||
|
|
||||||
describe("DELETE /api/v1/profile/header", () => {
|
describe("DELETE /api/v1/profile/header", () => {
|
||||||
test("should delete the header of the authenticated user and return the updated account object", async () => {
|
test("should delete the header of the authenticated user and return the updated account object", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest("/api/v1/profile/header", {
|
||||||
new Request(
|
|
||||||
wrapRelativeUrl("/api/v1/profile/header", baseUrl),
|
|
||||||
{
|
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token.accessToken}`,
|
Authorization: `Bearer ${token.accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
@ -410,12 +351,8 @@ describe("API Tests", () => {
|
||||||
|
|
||||||
describe("GET /api/v1/accounts/familiar_followers", () => {
|
describe("GET /api/v1/accounts/familiar_followers", () => {
|
||||||
test("should follow the user", async () => {
|
test("should follow the user", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
wrapRelativeUrl(
|
|
||||||
`/api/v1/accounts/${user2.id}/follow`,
|
`/api/v1/accounts/${user2.id}/follow`,
|
||||||
baseUrl,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -424,7 +361,6 @@ describe("API Tests", () => {
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -434,19 +370,14 @@ describe("API Tests", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return an array of objects with id and accounts properties, where id is a string and accounts is an array of APIAccount objects", async () => {
|
test("should return an array of objects with id and accounts properties, where id is a string and accounts is an array of APIAccount objects", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
wrapRelativeUrl(
|
|
||||||
`/api/v1/accounts/familiar_followers?id[]=${user2.id}`,
|
`/api/v1/accounts/familiar_followers?id[]=${user2.id}`,
|
||||||
baseUrl,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token.accessToken}`,
|
Authorization: `Bearer ${token.accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,7 @@ import type {
|
||||||
Context as ApiContext,
|
Context as ApiContext,
|
||||||
Status as ApiStatus,
|
Status as ApiStatus,
|
||||||
} from "@versia/client/types";
|
} from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager/index";
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
||||||
import { getTestUsers, sendTestRequest, wrapRelativeUrl } from "~/tests/utils";
|
|
||||||
|
|
||||||
const baseUrl = config.http.base_url;
|
|
||||||
|
|
||||||
const { users, tokens, deleteUsers } = await getTestUsers(1);
|
const { users, tokens, deleteUsers } = await getTestUsers(1);
|
||||||
const user = users[0];
|
const user = users[0];
|
||||||
|
|
@ -29,18 +26,13 @@ describe("API Tests", () => {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("file", new Blob(["test"], { type: "text/plain" }));
|
formData.append("file", new Blob(["test"], { type: "text/plain" }));
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest("/api/v2/media", {
|
||||||
new Request(
|
|
||||||
wrapRelativeUrl(`${baseUrl}/api/v2/media`, baseUrl),
|
|
||||||
{
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token.accessToken}`,
|
Authorization: `Bearer ${token.accessToken}`,
|
||||||
},
|
},
|
||||||
body: formData,
|
body: formData,
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(202);
|
expect(response.status).toBe(202);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
@ -57,10 +49,7 @@ describe("API Tests", () => {
|
||||||
|
|
||||||
describe("POST /api/v1/statuses", () => {
|
describe("POST /api/v1/statuses", () => {
|
||||||
test("should create a new status and return an APIStatus object", async () => {
|
test("should create a new status and return an APIStatus object", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest("/api/v1/statuses", {
|
||||||
new Request(
|
|
||||||
wrapRelativeUrl(`${baseUrl}/api/v1/statuses`, baseUrl),
|
|
||||||
{
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token.accessToken}`,
|
Authorization: `Bearer ${token.accessToken}`,
|
||||||
|
|
@ -71,9 +60,7 @@ describe("API Tests", () => {
|
||||||
"media_ids[]": media1?.id ?? "",
|
"media_ids[]": media1?.id ?? "",
|
||||||
local_only: "true",
|
local_only: "true",
|
||||||
}),
|
}),
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
@ -104,10 +91,7 @@ describe("API Tests", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should create a new status in reply to the previous one", async () => {
|
test("should create a new status in reply to the previous one", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest("/api/v1/statuses", {
|
||||||
new Request(
|
|
||||||
wrapRelativeUrl(`${baseUrl}/api/v1/statuses`, baseUrl),
|
|
||||||
{
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token.accessToken}`,
|
Authorization: `Bearer ${token.accessToken}`,
|
||||||
|
|
@ -118,9 +102,7 @@ describe("API Tests", () => {
|
||||||
in_reply_to_id: status?.id ?? "",
|
in_reply_to_id: status?.id ?? "",
|
||||||
local_only: "true",
|
local_only: "true",
|
||||||
}),
|
}),
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
@ -153,18 +135,13 @@ describe("API Tests", () => {
|
||||||
|
|
||||||
describe("GET /api/v1/statuses/:id", () => {
|
describe("GET /api/v1/statuses/:id", () => {
|
||||||
test("should return the specified status object", async () => {
|
test("should return the specified status object", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
`/api/v1/statuses/${status?.id}`,
|
||||||
wrapRelativeUrl(
|
|
||||||
`${baseUrl}/api/v1/statuses/${status?.id}`,
|
|
||||||
baseUrl,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token.accessToken}`,
|
Authorization: `Bearer ${token.accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -202,19 +179,14 @@ describe("API Tests", () => {
|
||||||
|
|
||||||
describe("POST /api/v1/statuses/:id/reblog", () => {
|
describe("POST /api/v1/statuses/:id/reblog", () => {
|
||||||
test("should reblog the specified status and return the reblogged status object", async () => {
|
test("should reblog the specified status and return the reblogged status object", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
`/api/v1/statuses/${status?.id}/reblog`,
|
||||||
wrapRelativeUrl(
|
|
||||||
`${baseUrl}/api/v1/statuses/${status?.id}/reblog`,
|
|
||||||
baseUrl,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token.accessToken}`,
|
Authorization: `Bearer ${token.accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -232,19 +204,14 @@ describe("API Tests", () => {
|
||||||
|
|
||||||
describe("POST /api/v1/statuses/:id/unreblog", () => {
|
describe("POST /api/v1/statuses/:id/unreblog", () => {
|
||||||
test("should unreblog the specified status and return the original status object", async () => {
|
test("should unreblog the specified status and return the original status object", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
`/api/v1/statuses/${status?.id}/unreblog`,
|
||||||
wrapRelativeUrl(
|
|
||||||
`${baseUrl}/api/v1/statuses/${status?.id}/unreblog`,
|
|
||||||
baseUrl,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token.accessToken}`,
|
Authorization: `Bearer ${token.accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -261,18 +228,13 @@ describe("API Tests", () => {
|
||||||
|
|
||||||
describe("GET /api/v1/statuses/:id/context", () => {
|
describe("GET /api/v1/statuses/:id/context", () => {
|
||||||
test("should return the context of the specified status", async () => {
|
test("should return the context of the specified status", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
`/api/v1/statuses/${status?.id}/context`,
|
||||||
wrapRelativeUrl(
|
|
||||||
`${baseUrl}/api/v1/statuses/${status?.id}/context`,
|
|
||||||
baseUrl,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token.accessToken}`,
|
Authorization: `Bearer ${token.accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -292,19 +254,14 @@ describe("API Tests", () => {
|
||||||
|
|
||||||
describe("GET /api/v1/accounts/:id/statuses", () => {
|
describe("GET /api/v1/accounts/:id/statuses", () => {
|
||||||
test("should return the statuses of the specified user", async () => {
|
test("should return the statuses of the specified user", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
`/api/v1/accounts/${user.id}/statuses`,
|
||||||
wrapRelativeUrl(
|
|
||||||
`${baseUrl}/api/v1/accounts/${user.id}/statuses`,
|
|
||||||
baseUrl,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token.accessToken}`,
|
Authorization: `Bearer ${token.accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -327,19 +284,14 @@ describe("API Tests", () => {
|
||||||
|
|
||||||
describe("POST /api/v1/statuses/:id/favourite", () => {
|
describe("POST /api/v1/statuses/:id/favourite", () => {
|
||||||
test("should favourite the specified status object", async () => {
|
test("should favourite the specified status object", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
`/api/v1/statuses/${status?.id}/favourite`,
|
||||||
wrapRelativeUrl(
|
|
||||||
`${baseUrl}/api/v1/statuses/${status?.id}/favourite`,
|
|
||||||
baseUrl,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token.accessToken}`,
|
Authorization: `Bearer ${token.accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -349,19 +301,14 @@ describe("API Tests", () => {
|
||||||
describe("POST /api/v1/statuses/:id/unfavourite", () => {
|
describe("POST /api/v1/statuses/:id/unfavourite", () => {
|
||||||
test("should unfavourite the specified status object", async () => {
|
test("should unfavourite the specified status object", async () => {
|
||||||
// Unfavourite the status
|
// Unfavourite the status
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
`/api/v1/statuses/${status?.id}/unfavourite`,
|
||||||
wrapRelativeUrl(
|
|
||||||
`${baseUrl}/api/v1/statuses/${status?.id}/unfavourite`,
|
|
||||||
baseUrl,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token.accessToken}`,
|
Authorization: `Bearer ${token.accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
@ -378,19 +325,14 @@ describe("API Tests", () => {
|
||||||
|
|
||||||
describe("DELETE /api/v1/statuses/:id", () => {
|
describe("DELETE /api/v1/statuses/:id", () => {
|
||||||
test("should delete the specified status object", async () => {
|
test("should delete the specified status object", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
`/api/v1/statuses/${status?.id}`,
|
||||||
wrapRelativeUrl(
|
|
||||||
`${baseUrl}/api/v1/statuses/${status?.id}`,
|
|
||||||
baseUrl,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token.accessToken}`,
|
Authorization: `Bearer ${token.accessToken}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,7 @@ import type {
|
||||||
Application as ApiApplication,
|
Application as ApiApplication,
|
||||||
Token as ApiToken,
|
Token as ApiToken,
|
||||||
} from "@versia/client/types";
|
} from "@versia/client/types";
|
||||||
import { config } from "~/packages/config-manager";
|
import { fakeRequest, getTestUsers } from "./utils";
|
||||||
import { getTestUsers, sendTestRequest, wrapRelativeUrl } from "./utils";
|
|
||||||
|
|
||||||
const baseUrl = config.http.base_url;
|
|
||||||
|
|
||||||
let clientId: string;
|
let clientId: string;
|
||||||
let clientSecret: string;
|
let clientSecret: string;
|
||||||
|
|
@ -31,8 +28,7 @@ describe("POST /api/v1/apps/", () => {
|
||||||
formData.append("redirect_uris", "https://example.com");
|
formData.append("redirect_uris", "https://example.com");
|
||||||
formData.append("scopes", "read write");
|
formData.append("scopes", "read write");
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest("/api/v1/apps", {
|
||||||
new Request(new URL("/api/v1/apps", config.http.base_url), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
@ -43,8 +39,7 @@ describe("POST /api/v1/apps/", () => {
|
||||||
redirect_uris: "https://example.com",
|
redirect_uris: "https://example.com",
|
||||||
scopes: "read write",
|
scopes: "read write",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
@ -75,17 +70,12 @@ describe("POST /api/auth/login/", () => {
|
||||||
formData.append("identifier", users[0]?.data.email ?? "");
|
formData.append("identifier", users[0]?.data.email ?? "");
|
||||||
formData.append("password", passwords[0]);
|
formData.append("password", passwords[0]);
|
||||||
|
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest(
|
||||||
new Request(
|
|
||||||
new URL(
|
|
||||||
`/api/auth/login?client_id=${clientId}&redirect_uri=https://example.com&response_type=code&scope=read+write`,
|
`/api/auth/login?client_id=${clientId}&redirect_uri=https://example.com&response_type=code&scope=read+write`,
|
||||||
baseUrl,
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
body: formData,
|
||||||
},
|
},
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(302);
|
expect(response.status).toBe(302);
|
||||||
|
|
@ -98,8 +88,7 @@ describe("POST /api/auth/login/", () => {
|
||||||
|
|
||||||
describe("GET /oauth/authorize/", () => {
|
describe("GET /oauth/authorize/", () => {
|
||||||
test("should get a code", async () => {
|
test("should get a code", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest("/oauth/authorize", {
|
||||||
new Request(new URL("/oauth/authorize", baseUrl), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Cookie: `jwt=${jwt}`,
|
Cookie: `jwt=${jwt}`,
|
||||||
|
|
@ -112,8 +101,7 @@ describe("GET /oauth/authorize/", () => {
|
||||||
scope: "read write",
|
scope: "read write",
|
||||||
max_age: "604800",
|
max_age: "604800",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(302);
|
expect(response.status).toBe(302);
|
||||||
expect(response.headers.get("location")).toBeDefined();
|
expect(response.headers.get("location")).toBeDefined();
|
||||||
|
|
@ -130,8 +118,7 @@ describe("GET /oauth/authorize/", () => {
|
||||||
|
|
||||||
describe("POST /oauth/token/", () => {
|
describe("POST /oauth/token/", () => {
|
||||||
test("should get an access token", async () => {
|
test("should get an access token", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest("/oauth/token", {
|
||||||
new Request(wrapRelativeUrl("/oauth/token", baseUrl), {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${jwt}`,
|
Authorization: `Bearer ${jwt}`,
|
||||||
|
|
@ -145,8 +132,7 @@ describe("POST /oauth/token/", () => {
|
||||||
client_secret: clientSecret,
|
client_secret: clientSecret,
|
||||||
scope: "read write",
|
scope: "read write",
|
||||||
}),
|
}),
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
|
|
||||||
|
|
@ -170,16 +156,11 @@ describe("POST /oauth/token/", () => {
|
||||||
|
|
||||||
describe("GET /api/v1/apps/verify_credentials", () => {
|
describe("GET /api/v1/apps/verify_credentials", () => {
|
||||||
test("should return the authenticated application's credentials", async () => {
|
test("should return the authenticated application's credentials", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await fakeRequest("/api/v1/apps/verify_credentials", {
|
||||||
new Request(
|
|
||||||
wrapRelativeUrl("/api/v1/apps/verify_credentials", baseUrl),
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token.access_token}`,
|
Authorization: `Bearer ${token.access_token}`,
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toContain(
|
expect(response.headers.get("content-type")).toContain(
|
||||||
|
|
|
||||||
|
|
@ -19,18 +19,10 @@ if (config.sonic.enabled) {
|
||||||
|
|
||||||
const app = await appFactory();
|
const app = await appFactory();
|
||||||
|
|
||||||
/**
|
export function fakeRequest(url: URL | string, init?: RequestInit) {
|
||||||
* This allows us to send a test request to the server even when it isnt running
|
return Promise.resolve(
|
||||||
* @param req Request to send
|
app.fetch(new Request(new URL(url, config.http.base_url), init)),
|
||||||
* @returns Response from the server
|
);
|
||||||
*/
|
|
||||||
export function sendTestRequest(req: Request): Promise<Response> {
|
|
||||||
// return fetch(req);
|
|
||||||
return Promise.resolve(app.fetch(req));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function wrapRelativeUrl(url: string, baseUrl: string) {
|
|
||||||
return new URL(url, baseUrl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const deleteOldTestUsers = async () => {
|
export const deleteOldTestUsers = async () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue