diff --git a/api/api/v1/accounts/:id/block.test.ts b/api/api/v1/accounts/:id/block.test.ts index c9680d68..bf4a16c1 100644 --- a/api/api/v1/accounts/:id/block.test.ts +++ b/api/api/v1/accounts/:id/block.test.ts @@ -1,8 +1,7 @@ import { afterAll, describe, expect, test } from "bun:test"; -import type { Relationship as ApiRelationship } from "@versia/client/types"; -import { fakeRequest, getTestUsers } from "~/tests/utils"; +import { generateClient, getTestUsers } from "~/tests/utils"; -const { users, tokens, deleteUsers } = await getTestUsers(2); +const { users, deleteUsers } = await getTestUsers(2); afterAll(async () => { await deleteUsers(); @@ -11,57 +10,40 @@ afterAll(async () => { // /api/v1/accounts/:id/block describe("/api/v1/accounts/:id/block", () => { test("should return 401 if not authenticated", async () => { - const response = await fakeRequest( - `/api/v1/accounts/${users[1].id}/block`, - { - method: "POST", - }, - ); - expect(response.status).toBe(401); + await using client = await generateClient(); + + const { ok, raw } = await client.blockAccount(users[1].id); + + expect(ok).toBe(false); + expect(raw.status).toBe(401); }); test("should return 404 if user not found", async () => { - const response = await fakeRequest( - "/api/v1/accounts/00000000-0000-0000-0000-000000000000/block", - { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, + await using client = await generateClient(users[0]); + + const { ok, raw } = await client.blockAccount( + "00000000-0000-0000-0000-000000000000", ); - expect(response.status).toBe(404); + + expect(ok).toBe(false); + expect(raw.status).toBe(404); }); test("should block user", async () => { - const response = await fakeRequest( - `/api/v1/accounts/${users[1].id}/block`, - { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, - ); - expect(response.status).toBe(200); + await using client = await generateClient(users[0]); - const relationship = (await response.json()) as ApiRelationship; - expect(relationship.blocking).toBe(true); + const { ok, data } = await client.blockAccount(users[1].id); + + expect(ok).toBe(true); + expect(data.blocking).toBe(true); }); test("should return 200 if user already blocked", async () => { - const response = await fakeRequest( - `/api/v1/accounts/${users[1].id}/block`, - { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, - ); - expect(response.status).toBe(200); + await using client = await generateClient(users[0]); - const relationship = (await response.json()) as ApiRelationship; - expect(relationship.blocking).toBe(true); + const { ok, data } = await client.blockAccount(users[1].id); + + expect(ok).toBe(true); + expect(data.blocking).toBe(true); }); }); diff --git a/api/api/v1/accounts/:id/follow.test.ts b/api/api/v1/accounts/:id/follow.test.ts index d6d828b0..e87a64a9 100644 --- a/api/api/v1/accounts/:id/follow.test.ts +++ b/api/api/v1/accounts/:id/follow.test.ts @@ -1,8 +1,7 @@ import { afterAll, describe, expect, test } from "bun:test"; -import type { Relationship as ApiRelationship } from "@versia/client/types"; -import { fakeRequest, getTestUsers } from "~/tests/utils"; +import { generateClient, getTestUsers } from "~/tests/utils"; -const { users, tokens, deleteUsers } = await getTestUsers(2); +const { users, deleteUsers } = await getTestUsers(2); afterAll(async () => { await deleteUsers(); @@ -11,67 +10,38 @@ afterAll(async () => { // /api/v1/accounts/:id/follow describe("/api/v1/accounts/:id/follow", () => { test("should return 401 if not authenticated", async () => { - const response = await fakeRequest( - `/api/v1/accounts/${users[1].id}/follow`, - { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({}), - }, - ); - expect(response.status).toBe(401); + await using client = await generateClient(); + + const { ok, raw } = await client.followAccount(users[1].id); + + expect(ok).toBe(false); + expect(raw.status).toBe(401); }); test("should return 404 if user not found", async () => { - const response = await fakeRequest( - "/api/v1/accounts/00000000-0000-0000-0000-000000000000/follow", - { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - "Content-Type": "application/json", - }, - body: JSON.stringify({}), - }, + await using client = await generateClient(users[0]); + + const { ok, raw } = await client.followAccount( + "00000000-0000-0000-0000-000000000000", ); - expect(response.status).toBe(404); + + expect(ok).toBe(false); + expect(raw.status).toBe(404); }); test("should follow user", async () => { - const response = await fakeRequest( - `/api/v1/accounts/${users[1].id}/follow`, - { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - "Content-Type": "application/json", - }, - body: JSON.stringify({}), - }, - ); - expect(response.status).toBe(200); + await using client = await generateClient(users[0]); - const relationship = (await response.json()) as ApiRelationship; - expect(relationship.following).toBe(true); + const { ok } = await client.followAccount(users[1].id); + + expect(ok).toBe(true); }); test("should return 200 if user already followed", async () => { - const response = await fakeRequest( - `/api/v1/accounts/${users[1].id}/follow`, - { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - "Content-Type": "application/json", - }, - body: JSON.stringify({}), - }, - ); - expect(response.status).toBe(200); + await using client = await generateClient(users[0]); - const relationship = (await response.json()) as ApiRelationship; - expect(relationship.following).toBe(true); + const { ok } = await client.followAccount(users[1].id); + + expect(ok).toBe(true); }); }); diff --git a/api/api/v1/accounts/:id/followers.test.ts b/api/api/v1/accounts/:id/followers.test.ts index 017c97d9..abfece0b 100644 --- a/api/api/v1/accounts/:id/followers.test.ts +++ b/api/api/v1/accounts/:id/followers.test.ts @@ -1,45 +1,30 @@ import { afterAll, beforeAll, describe, expect, test } from "bun:test"; -import type { Account as ApiAccount } from "@versia/client/types"; -import { fakeRequest, getTestUsers } from "~/tests/utils"; +import { generateClient, getTestUsers } from "~/tests/utils"; -const { users, tokens, deleteUsers } = await getTestUsers(5); +const { users, deleteUsers } = await getTestUsers(5); afterAll(async () => { await deleteUsers(); }); beforeAll(async () => { - // Follow user - const response = await fakeRequest( - `/api/v1/accounts/${users[1].id}/follow`, - { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - "Content-Type": "application/json", - }, - body: JSON.stringify({}), - }, - ); + await using client = await generateClient(users[0]); - expect(response.status).toBe(200); + // Follow user + const { ok, raw } = await client.followAccount(users[1].id); + + expect(ok).toBe(true); + expect(raw.status).toBe(200); }); // /api/v1/accounts/:id/followers describe("/api/v1/accounts/:id/followers", () => { test("should return 200 with followers", async () => { - const response = await fakeRequest( - `/api/v1/accounts/${users[1].id}/followers`, - { - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, - ); + await using client = await generateClient(users[0]); - expect(response.status).toBe(200); + const { ok, data } = await client.getAccountFollowers(users[1].id); - const data = (await response.json()) as ApiAccount[]; + expect(ok).toBe(true); expect(data).toBeInstanceOf(Array); expect(data.length).toBe(1); @@ -47,32 +32,15 @@ describe("/api/v1/accounts/:id/followers", () => { }); test("should return no followers after unfollowing", async () => { - // Unfollow user - const response = await fakeRequest( - `/api/v1/accounts/${users[1].id}/unfollow`, - { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, - ); + await using client = await generateClient(users[0]); - expect(response.status).toBe(200); + const { ok } = await client.unfollowAccount(users[1].id); - const response2 = await fakeRequest( - `/api/v1/accounts/${users[1].id}/followers`, - { - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, - ); + expect(ok).toBe(true); - expect(response2.status).toBe(200); - - const data = (await response2.json()) as ApiAccount[]; + const { ok: ok2, data } = await client.getAccountFollowers(users[1].id); + expect(ok2).toBe(true); expect(data).toBeInstanceOf(Array); expect(data.length).toBe(0); }); diff --git a/api/api/v1/accounts/:id/following.test.ts b/api/api/v1/accounts/:id/following.test.ts index a0393e5c..cea94341 100644 --- a/api/api/v1/accounts/:id/following.test.ts +++ b/api/api/v1/accounts/:id/following.test.ts @@ -1,45 +1,29 @@ import { afterAll, beforeAll, describe, expect, test } from "bun:test"; -import type { Account as ApiAccount } from "@versia/client/types"; -import { fakeRequest, getTestUsers } from "~/tests/utils"; +import { generateClient, getTestUsers } from "~/tests/utils"; -const { users, tokens, deleteUsers } = await getTestUsers(5); +const { users, deleteUsers } = await getTestUsers(5); afterAll(async () => { await deleteUsers(); }); beforeAll(async () => { - // Follow user - const response = await fakeRequest( - `/api/v1/accounts/${users[1].id}/follow`, - { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - "Content-Type": "application/json", - }, - body: JSON.stringify({}), - }, - ); + await using client = await generateClient(users[0]); - expect(response.status).toBe(200); + // Follow user + const { ok } = await client.followAccount(users[1].id); + + expect(ok).toBe(true); }); // /api/v1/accounts/:id/following describe("/api/v1/accounts/:id/following", () => { test("should return 200 with following", async () => { - const response = await fakeRequest( - `/api/v1/accounts/${users[0].id}/following`, - { - headers: { - Authorization: `Bearer ${tokens[1].data.accessToken}`, - }, - }, - ); + await using client = await generateClient(users[1]); - expect(response.status).toBe(200); + const { ok, data } = await client.getAccountFollowing(users[0].id); - const data = (await response.json()) as ApiAccount[]; + expect(ok).toBe(true); expect(data).toBeInstanceOf(Array); expect(data.length).toBe(1); @@ -47,32 +31,15 @@ describe("/api/v1/accounts/:id/following", () => { }); test("should return no following after unfollowing", async () => { - // Unfollow user - const response = await fakeRequest( - `/api/v1/accounts/${users[1].id}/unfollow`, - { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, - ); + await using client = await generateClient(users[0]); - expect(response.status).toBe(200); + const { ok } = await client.unfollowAccount(users[1].id); - const response2 = await fakeRequest( - `/api/v1/accounts/${users[0].id}/following`, - { - headers: { - Authorization: `Bearer ${tokens[1].data.accessToken}`, - }, - }, - ); + expect(ok).toBe(true); - expect(response2.status).toBe(200); - - const data = (await response2.json()) as ApiAccount[]; + const { ok: ok2, data } = await client.getAccountFollowing(users[1].id); + expect(ok2).toBe(true); expect(data).toBeInstanceOf(Array); expect(data.length).toBe(0); }); diff --git a/api/api/v1/accounts/:id/index.test.ts b/api/api/v1/accounts/:id/index.test.ts index aa42b7cd..a3feb1f2 100644 --- a/api/api/v1/accounts/:id/index.test.ts +++ b/api/api/v1/accounts/:id/index.test.ts @@ -1,40 +1,39 @@ import { afterAll, beforeAll, describe, expect, test } from "bun:test"; import type { Account as ApiAccount } from "@versia/client/types"; -import { fakeRequest, getTestStatuses, getTestUsers } from "~/tests/utils"; +import { generateClient, getTestStatuses, getTestUsers } from "~/tests/utils"; -const { users, tokens, deleteUsers } = await getTestUsers(5); -const timeline = (await getTestStatuses(40, users[0])).toReversed(); +const { users, deleteUsers } = await getTestUsers(5); +const timeline = (await getTestStatuses(5, users[0])).toReversed(); afterAll(async () => { await deleteUsers(); }); beforeAll(async () => { + await using client = await generateClient(users[0]); + for (const status of timeline) { - await fakeRequest(`/api/v1/statuses/${status.id}/favourite`, { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[1].data.accessToken}`, - "Content-Type": "application/json", - }, - body: JSON.stringify({}), - }); + await client.favouriteStatus(status.id); } }); // /api/v1/accounts/:id describe("/api/v1/accounts/:id", () => { test("should return 404 if ID is invalid", async () => { - const response = await fakeRequest("/api/v1/accounts/invalid-id"); - expect(response.status).toBe(422); + await using client = await generateClient(users[0]); + + const { ok, raw } = await client.getAccount("invalid-id"); + + expect(ok).toBe(false); + expect(raw.status).toBe(422); }); test("should return user", async () => { - const response = await fakeRequest(`/api/v1/accounts/${users[0].id}`); + await using client = await generateClient(users[0]); - expect(response.status).toBe(200); + const { ok, data } = await client.getAccount(users[0].id); - const data = (await response.json()) as ApiAccount; + expect(ok).toBe(true); expect(data).toMatchObject({ id: users[0].id, username: users[0].data.username, @@ -45,7 +44,7 @@ describe("/api/v1/accounts/:id", () => { created_at: new Date(users[0].data.createdAt).toISOString(), followers_count: 0, following_count: 0, - statuses_count: 40, + statuses_count: 5, note: users[0].data.note, acct: users[0].data.username, uri: expect.any(String), diff --git a/api/api/v1/accounts/:id/mute.test.ts b/api/api/v1/accounts/:id/mute.test.ts index 8a2f1cd5..1ec02ca6 100644 --- a/api/api/v1/accounts/:id/mute.test.ts +++ b/api/api/v1/accounts/:id/mute.test.ts @@ -1,8 +1,7 @@ import { afterAll, describe, expect, test } from "bun:test"; -import type { Relationship as ApiRelationship } from "@versia/client/types"; -import { fakeRequest, getTestUsers } from "~/tests/utils"; +import { generateClient, getTestUsers } from "~/tests/utils"; -const { users, tokens, deleteUsers } = await getTestUsers(2); +const { users, deleteUsers } = await getTestUsers(2); afterAll(async () => { await deleteUsers(); @@ -11,67 +10,44 @@ afterAll(async () => { // /api/v1/accounts/:id/mute describe("/api/v1/accounts/:id/mute", () => { test("should return 401 if not authenticated", async () => { - const response = await fakeRequest( - `/api/v1/accounts/${users[1].id}/mute`, - { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({}), - }, - ); - expect(response.status).toBe(401); + await using client = await generateClient(); + + const { ok, raw } = await client.muteAccount(users[1].id); + + expect(ok).toBe(false); + expect(raw.status).toBe(401); }); test("should return 404 if user not found", async () => { - const response = await fakeRequest( - "/api/v1/accounts/00000000-0000-0000-0000-000000000000/mute", - { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - "Content-Type": "application/json", - }, - body: JSON.stringify({}), - }, + await using client = await generateClient(users[0]); + + const { ok, raw } = await client.muteAccount( + "00000000-0000-0000-0000-000000000000", ); - expect(response.status).toBe(404); + + expect(ok).toBe(false); + expect(raw.status).toBe(404); }); test("should mute user", async () => { - const response = await fakeRequest( - `/api/v1/accounts/${users[1].id}/mute`, - { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - "Content-Type": "application/json", - }, - body: JSON.stringify({}), - }, - ); - expect(response.status).toBe(200); + await using client = await generateClient(users[0]); - const relationship = (await response.json()) as ApiRelationship; - expect(relationship.muting).toBe(true); + const { data, ok, raw } = await client.muteAccount(users[1].id); + + expect(ok).toBe(true); + expect(raw.status).toBe(200); + + expect(data.muting).toBe(true); }); test("should return 200 if user already muted", async () => { - const response = await fakeRequest( - `/api/v1/accounts/${users[1].id}/mute`, - { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - "Content-Type": "application/json", - }, - body: JSON.stringify({}), - }, - ); - expect(response.status).toBe(200); + await using client = await generateClient(users[0]); - const relationship = (await response.json()) as ApiRelationship; - expect(relationship.muting).toBe(true); + const { data, ok, raw } = await client.muteAccount(users[1].id); + + expect(ok).toBe(true); + expect(raw.status).toBe(200); + + expect(data.muting).toBe(true); }); }); diff --git a/api/api/v1/accounts/:id/statuses.test.ts b/api/api/v1/accounts/:id/statuses.test.ts index ff561ce7..60dce3cf 100644 --- a/api/api/v1/accounts/:id/statuses.test.ts +++ b/api/api/v1/accounts/:id/statuses.test.ts @@ -1,146 +1,109 @@ import { afterAll, beforeAll, describe, expect, test } from "bun:test"; -import type { Status as ApiStatus } from "@versia/client/types"; -import { fakeRequest, getTestStatuses, getTestUsers } from "~/tests/utils.ts"; +import { + generateClient, + getTestStatuses, + getTestUsers, +} from "~/tests/utils.ts"; -const { users, tokens, deleteUsers } = await getTestUsers(5); -const timeline = (await getTestStatuses(40, users[1])).toReversed(); -const timeline2 = (await getTestStatuses(40, users[2])).toReversed(); +const { users, deleteUsers } = await getTestUsers(5); +const timeline = (await getTestStatuses(5, users[1])).toReversed(); +const timeline2 = (await getTestStatuses(5, users[2])).toReversed(); afterAll(async () => { await deleteUsers(); }); beforeAll(async () => { - const response = await fakeRequest( - `/api/v1/statuses/${timeline2[0].id}/reblog`, - { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[1].data.accessToken}`, - }, - }, - ); + await using client = await generateClient(users[1]); - expect(response.status).toBe(200); + const { ok } = await client.reblogStatus(timeline2[0].id); + + expect(ok).toBe(true); }); // /api/v1/accounts/:id/statuses describe("/api/v1/accounts/:id/statuses", () => { test("should return 200 with statuses", async () => { - const response = await fakeRequest( - `/api/v1/accounts/${users[1].id}/statuses`, - { - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, - ); + await using client = await generateClient(users[1]); - expect(response.status).toBe(200); + const { data, ok } = await client.getAccountStatuses(users[1].id, { + limit: 5, + }); - const data = (await response.json()) as ApiStatus[]; + expect(ok).toBe(true); - expect(data.length).toBe(20); + expect(data).toBeArrayOfSize(5); // Should have reblogs expect(data[0].reblog).toBeDefined(); }); test("should exclude reblogs", async () => { - const response = await fakeRequest( - `/api/v1/accounts/${users[1].id}/statuses?exclude_reblogs=true`, - { - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, - ); + await using client = await generateClient(users[1]); - expect(response.status).toBe(200); + const { data, ok } = await client.getAccountStatuses(users[1].id, { + exclude_reblogs: true, + limit: 5, + }); - const data = (await response.json()) as ApiStatus[]; + expect(ok).toBe(true); - expect(data.length).toBe(20); + expect(data).toBeArrayOfSize(5); // Should not have reblogs expect(data[0].reblog).toBeNull(); }); test("should exclude replies", async () => { // Create reply - const replyResponse = await fakeRequest("/api/v1/statuses", { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[1].data.accessToken}`, - }, - body: new URLSearchParams({ - status: "Reply", - in_reply_to_id: timeline[0].id, - local_only: "true", - }), + await using client0 = await generateClient(users[0]); + await using client1 = await generateClient(users[1]); + + const { ok } = await client1.postStatus("Reply", { + in_reply_to_id: timeline[0].id, + local_only: true, }); - expect(replyResponse.status).toBe(200); + expect(ok).toBe(true); - const response = await fakeRequest( - `/api/v1/accounts/${users[1].id}/statuses?exclude_replies=true`, + const { data, ok: ok2 } = await client0.getAccountStatuses( + users[1].id, { - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, + exclude_replies: true, + limit: 5, }, ); - expect(response.status).toBe(200); + expect(ok2).toBe(true); - const data = (await response.json()) as ApiStatus[]; - - expect(data.length).toBe(20); + expect(data).toBeArrayOfSize(5); // Should not have replies expect(data[0].in_reply_to_id).toBeNull(); }); test("should only include pins", async () => { - const response = await fakeRequest( - `/api/v1/accounts/${users[1].id}/statuses?pinned=true`, - { - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, - ); + await using client0 = await generateClient(users[0]); + await using client1 = await generateClient(users[1]); - expect(response.status).toBe(200); + const { ok, data } = await client0.getAccountStatuses(users[1].id, { + pinned: true, + }); - const data = (await response.json()) as ApiStatus[]; - - expect(data.length).toBe(0); + expect(ok).toBe(true); + expect(data).toBeArrayOfSize(0); // Create pin - const pinResponse = await fakeRequest( - `/api/v1/statuses/${timeline[3].id}/pin`, + const { ok: ok2 } = await client1.pinStatus(timeline[3].id); + expect(ok2).toBe(true); + + const { data: data2, ok: ok3 } = await client0.getAccountStatuses( + users[1].id, { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[1].data.accessToken}`, - }, + pinned: true, }, ); - expect(pinResponse.status).toBe(200); - - const response2 = await fakeRequest( - `/api/v1/accounts/${users[1].id}/statuses?pinned=true`, - { - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, - ); - - expect(response2.status).toBe(200); - - const data2 = (await response2.json()) as ApiStatus[]; - - expect(data2.length).toBe(1); + expect(ok3).toBe(true); + expect(data2).toBeArrayOfSize(1); + expect(data2[0].id).toBe(timeline[3].id); }); }); diff --git a/api/api/v1/accounts/:id/unmute.test.ts b/api/api/v1/accounts/:id/unmute.test.ts index 9a5dde63..f4e5ce95 100644 --- a/api/api/v1/accounts/:id/unmute.test.ts +++ b/api/api/v1/accounts/:id/unmute.test.ts @@ -1,76 +1,57 @@ import { afterAll, beforeAll, describe, expect, test } from "bun:test"; -import type { Relationship as ApiRelationship } from "@versia/client/types"; -import { fakeRequest, getTestUsers } from "~/tests/utils"; +import { generateClient, getTestUsers } from "~/tests/utils"; -const { users, tokens, deleteUsers } = await getTestUsers(2); +const { users, deleteUsers } = await getTestUsers(2); afterAll(async () => { await deleteUsers(); }); beforeAll(async () => { - await fakeRequest(`/api/v1/accounts/${users[0].id}/mute`, { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[1].data.accessToken}`, - }, - }); + await using client = await generateClient(users[0]); + + const { ok } = await client.muteAccount(users[1].id); + + expect(ok).toBe(true); }); // /api/v1/accounts/:id/unmute describe("/api/v1/accounts/:id/unmute", () => { test("should return 401 if not authenticated", async () => { - const response = await fakeRequest( - `/api/v1/accounts/${users[1].id}/unmute`, - { - method: "POST", - }, - ); - expect(response.status).toBe(401); + await using client = await generateClient(); + + const { ok, raw } = await client.unmuteAccount(users[0].id); + + expect(ok).toBe(false); + expect(raw.status).toBe(401); }); test("should return 404 if user not found", async () => { - const response = await fakeRequest( - "/api/v1/accounts/00000000-0000-0000-0000-000000000000/unmute", - { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, + await using client = await generateClient(users[0]); + + const { ok, raw } = await client.unmuteAccount( + "00000000-0000-0000-0000-000000000000", ); - expect(response.status).toBe(404); + + expect(ok).toBe(false); + expect(raw.status).toBe(404); }); test("should unmute user", async () => { - const response = await fakeRequest( - `/api/v1/accounts/${users[1].id}/unmute`, - { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, - ); - expect(response.status).toBe(200); + await using client = await generateClient(users[0]); - const relationship = (await response.json()) as ApiRelationship; - expect(relationship.muting).toBe(false); + const { data, ok } = await client.unmuteAccount(users[1].id); + + expect(ok).toBe(true); + expect(data.muting).toBe(false); }); test("should return 200 if user already unmuted", async () => { - const response = await fakeRequest( - `/api/v1/accounts/${users[1].id}/unmute`, - { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, - ); - expect(response.status).toBe(200); + await using client = await generateClient(users[0]); - const relationship = (await response.json()) as ApiRelationship; - expect(relationship.muting).toBe(false); + const { data, ok } = await client.unmuteAccount(users[1].id); + + expect(ok).toBe(true); + expect(data.muting).toBe(false); }); }); diff --git a/api/api/v1/accounts/familiar_followers/index.test.ts b/api/api/v1/accounts/familiar_followers/index.test.ts index db9216da..5ee5d2f1 100644 --- a/api/api/v1/accounts/familiar_followers/index.test.ts +++ b/api/api/v1/accounts/familiar_followers/index.test.ts @@ -1,81 +1,39 @@ import { afterAll, beforeAll, describe, expect, test } from "bun:test"; -import { fakeRequest, getTestUsers } from "~/tests/utils.ts"; +import { generateClient, getTestUsers } from "~/tests/utils.ts"; -const { users, tokens, deleteUsers } = await getTestUsers(5); +const { users, deleteUsers } = await getTestUsers(5); beforeAll(async () => { // Create followers relationships - const result1 = await fakeRequest( - `/api/v1/accounts/${users[1].id}/follow`, - { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, - ); + await using client = await generateClient(users[0]); - expect(result1.status).toBe(200); + const { ok } = await client.followAccount(users[1].id); - const result2 = await fakeRequest( - `/api/v1/accounts/${users[2].id}/follow`, - { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, - ); + expect(ok).toBe(true); - expect(result2.status).toBe(200); + const { ok: ok2 } = await client.followAccount(users[2].id); - const result3 = await fakeRequest( - `/api/v1/accounts/${users[3].id}/follow`, - { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, - ); + expect(ok2).toBe(true); - expect(result3.status).toBe(200); + const { ok: ok3 } = await client.followAccount(users[3].id); - const result4 = await fakeRequest( - `/api/v1/accounts/${users[2].id}/follow`, - { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[1].data.accessToken}`, - }, - }, - ); + expect(ok3).toBe(true); - expect(result4.status).toBe(200); + await using client1 = await generateClient(users[1]); - const result5 = await fakeRequest( - `/api/v1/accounts/${users[3].id}/follow`, - { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[1].data.accessToken}`, - }, - }, - ); + const { ok: ok4 } = await client1.followAccount(users[2].id); - expect(result5.status).toBe(200); + expect(ok4).toBe(true); - const result6 = await fakeRequest( - `/api/v1/accounts/${users[3].id}/follow`, - { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[2].data.accessToken}`, - }, - }, - ); + const { ok: ok5 } = await client1.followAccount(users[3].id); - expect(result6.status).toBe(200); + expect(ok5).toBe(true); + + await using client2 = await generateClient(users[2]); + + const { ok: ok6 } = await client2.followAccount(users[3].id); + + expect(ok6).toBe(true); }); afterAll(async () => { @@ -84,55 +42,33 @@ afterAll(async () => { describe("/api/v1/accounts/familiar_followers", () => { test("should return 0 familiar followers", async () => { - const response = await fakeRequest( - `/api/v1/accounts/familiar_followers?id=${users[4].id}`, - { - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, - ); + await using client = await generateClient(users[0]); - expect(response.status).toBe(200); + const { data, ok } = await client.getFamiliarFollowers([users[4].id]); - const data = await response.json(); - expect(data.length).toBe(1); - expect(data[0].id).toBe(users[4].id); + expect(ok).toBe(true); expect(data[0].accounts).toBeArrayOfSize(0); }); test("should return 1 familiar follower", async () => { - const response = await fakeRequest( - `/api/v1/accounts/familiar_followers?id=${users[2].id}`, - { - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, - ); + await using client = await generateClient(users[0]); - expect(response.status).toBe(200); + const { data, ok } = await client.getFamiliarFollowers([users[2].id]); - const data = await response.json(); - expect(data.length).toBe(1); + expect(ok).toBe(true); + expect(data).toBeArrayOfSize(1); expect(data[0].id).toBe(users[2].id); + expect(data[0].accounts).toBeArrayOfSize(1); expect(data[0].accounts[0].id).toBe(users[1].id); }); test("should return 2 familiar followers", async () => { - const response = await fakeRequest( - `/api/v1/accounts/familiar_followers?id=${users[3].id}`, - { - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, - ); + await using client = await generateClient(users[0]); - expect(response.status).toBe(200); + const { data, ok } = await client.getFamiliarFollowers([users[3].id]); - const data = await response.json(); - expect(data.length).toBe(1); + expect(ok).toBe(true); + expect(data).toBeArrayOfSize(1); expect(data[0].id).toBe(users[3].id); expect(data[0].accounts).toBeArrayOfSize(2); expect(data[0].accounts[0].id).toBe(users[2].id); @@ -140,22 +76,21 @@ describe("/api/v1/accounts/familiar_followers", () => { }); test("should work with multiple ids", async () => { - const response = await fakeRequest( - `/api/v1/accounts/familiar_followers?id[]=${users[2].id}&id[]=${users[3].id}&id[]=${users[4].id}`, - { - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, - ); + await using client = await generateClient(users[0]); - expect(response.status).toBe(200); + const { data, ok } = await client.getFamiliarFollowers([ + users[2].id, + users[3].id, + users[4].id, + ]); - const data = await response.json(); - expect(data.length).toBe(3); + expect(ok).toBe(true); + expect(data).toBeArrayOfSize(3); expect(data[0].id).toBe(users[2].id); + expect(data[0].accounts).toBeArrayOfSize(1); expect(data[0].accounts[0].id).toBe(users[1].id); expect(data[1].id).toBe(users[3].id); + expect(data[1].accounts).toBeArrayOfSize(2); expect(data[1].accounts[0].id).toBe(users[2].id); expect(data[1].accounts[1].id).toBe(users[1].id); expect(data[2].id).toBe(users[4].id); diff --git a/api/api/v1/accounts/index.test.ts b/api/api/v1/accounts/index.test.ts index 2b3551a1..e4416f1f 100644 --- a/api/api/v1/accounts/index.test.ts +++ b/api/api/v1/accounts/index.test.ts @@ -3,7 +3,7 @@ import { randomString } from "@/math"; import { db } from "@versia/kit/db"; import { Users } from "@versia/kit/tables"; import { eq } from "drizzle-orm"; -import { fakeRequest, getSolvedChallenge } from "~/tests/utils"; +import { generateClient, getSolvedChallenge } from "~/tests/utils"; const username = randomString(10, "hex"); const username2 = randomString(10, "hex"); @@ -16,208 +16,211 @@ afterEach(async () => { // /api/v1/statuses describe("/api/v1/accounts", () => { test("should create a new account", async () => { - const response = await fakeRequest("/api/v1/accounts", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-Challenge-Solution": await getSolvedChallenge(), - }, - body: JSON.stringify({ - username, - email: "bob@gamer.com", - password: "password", - agreement: "true", - locale: "en", - reason: "testing", - }), - }); + await using client = await generateClient(); - expect(response.ok).toBe(true); - expect(response.headers.get("Content-Type")).not.toContain("json"); + const { ok, raw } = await client.registerAccount( + username, + "bob@gamer.com", + "password", + true, + "en", + "testing", + { + headers: { + "X-Challenge-Solution": await getSolvedChallenge(), + }, + }, + ); + + expect(ok).toBe(true); + expect(raw.headers.get("Content-Type")).not.toContain("json"); }); test("should refuse invalid emails", async () => { - const response = await fakeRequest("/api/v1/accounts", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-Challenge-Solution": await getSolvedChallenge(), - }, - body: JSON.stringify({ - username, - email: "bob", - password: "password", - agreement: "true", - locale: "en", - reason: "testing", - }), - }); + await using client = await generateClient(); - expect(response.status).toBe(422); + const { ok, raw } = await client.registerAccount( + username, + "bob", + "password", + true, + "en", + "testing", + { + headers: { + "X-Challenge-Solution": await getSolvedChallenge(), + }, + }, + ); + + expect(ok).toBe(false); + expect(raw.status).toBe(422); }); test("should require a password", async () => { - const response = await fakeRequest("/api/v1/accounts", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-Challenge-Solution": await getSolvedChallenge(), - }, - body: JSON.stringify({ - username, - email: "contatc@bob.com", - agreement: "true", - locale: "en", - reason: "testing", - }), - }); + await using client = await generateClient(); - expect(response.status).toBe(422); + const { ok, raw } = await client.registerAccount( + username, + "bob@gamer.com", + "", + true, + "en", + "testing", + { + headers: { + "X-Challenge-Solution": await getSolvedChallenge(), + }, + }, + ); + + expect(ok).toBe(false); + expect(raw.status).toBe(422); }); test("should not allow a previously registered email", async () => { - await fakeRequest("/api/v1/accounts", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-Challenge-Solution": await getSolvedChallenge(), - }, - body: JSON.stringify({ - username, - email: "contact@george.com", - password: "password", - agreement: "true", - locale: "en", - reason: "testing", - }), - }); + await using client = await generateClient(); - const response = await fakeRequest("/api/v1/accounts", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-Challenge-Solution": await getSolvedChallenge(), + const { ok } = await client.registerAccount( + username, + "contact@george.com", + "password", + true, + "en", + "testing", + { + headers: { + "X-Challenge-Solution": await getSolvedChallenge(), + }, }, - body: JSON.stringify({ - username: username2, - email: "contact@george.com", - password: "password", - agreement: "true", - locale: "en", - reason: "testing", - }), - }); + ); - expect(response.status).toBe(422); + expect(ok).toBe(true); + + const { ok: ok2, raw } = await client.registerAccount( + username2, + "contact@george.com", + "password", + true, + "en", + "testing", + { + headers: { + "X-Challenge-Solution": await getSolvedChallenge(), + }, + }, + ); + + expect(ok2).toBe(false); + expect(raw.status).toBe(422); }); test("should not allow a previously registered email (case insensitive)", async () => { - await fakeRequest("/api/v1/accounts", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-Challenge-Solution": await getSolvedChallenge(), - }, - body: JSON.stringify({ - username, - email: "contact@george.com", - password: "password", - agreement: "true", - locale: "en", - reason: "testing", - }), - }); + await using client = await generateClient(); - const response = await fakeRequest("/api/v1/accounts", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-Challenge-Solution": await getSolvedChallenge(), + const { ok } = await client.registerAccount( + username, + "contact@george.com", + "password", + true, + "en", + "testing", + { + headers: { + "X-Challenge-Solution": await getSolvedChallenge(), + }, }, - body: JSON.stringify({ - username: username2, - email: "CONTACT@george.CoM", - password: "password", - agreement: "true", - locale: "en", - reason: "testing", - }), - }); + ); - expect(response.status).toBe(422); + expect(ok).toBe(true); + + const { ok: ok2, raw } = await client.registerAccount( + username2, + "CONTACT@george.CoM", + "password", + true, + "en", + "testing", + { + headers: { + "X-Challenge-Solution": await getSolvedChallenge(), + }, + }, + ); + + expect(ok2).toBe(false); + expect(raw.status).toBe(422); }); test("should not allow invalid usernames (not a-z_0-9)", async () => { - const response1 = await fakeRequest("/api/v1/accounts", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-Challenge-Solution": await getSolvedChallenge(), + await using client = await generateClient(); + + const { ok: ok1, raw: raw1 } = await client.registerAccount( + "bob$", + "contact@george.com", + "password", + true, + "en", + "testing", + { + headers: { + "X-Challenge-Solution": await getSolvedChallenge(), + }, }, - body: JSON.stringify({ - username: "bob$", - email: "contact@bob.com", - password: "password", - agreement: "true", - locale: "en", - reason: "testing", - }), - }); + ); - expect(response1.status).toBe(422); + expect(ok1).toBe(false); + expect(raw1.status).toBe(422); - const response2 = await fakeRequest("/api/v1/accounts", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-Challenge-Solution": await getSolvedChallenge(), + const { ok: ok2, raw: raw2 } = await client.registerAccount( + "bob-markey", + "contact@bob.com", + "password", + true, + "en", + "testing", + { + headers: { + "X-Challenge-Solution": await getSolvedChallenge(), + }, }, - body: JSON.stringify({ - username: "bob-markey", - email: "contact@bob.com", - password: "password", - agreement: "true", - locale: "en", - reason: "testing", - }), - }); + ); - expect(response2.status).toBe(422); + expect(ok2).toBe(false); + expect(raw2.status).toBe(422); - const response3 = await fakeRequest("/api/v1/accounts", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-Challenge-Solution": await getSolvedChallenge(), + const { ok: ok3, raw: raw3 } = await client.registerAccount( + "bob markey", + "contact@bob.com", + "password", + true, + "en", + "testing", + { + headers: { + "X-Challenge-Solution": await getSolvedChallenge(), + }, }, - body: JSON.stringify({ - username: "bob markey", - email: "contact@bob.com", - password: "password", - agreement: "true", - locale: "en", - reason: "testing", - }), - }); + ); - expect(response3.status).toBe(422); + expect(ok3).toBe(false); + expect(raw3.status).toBe(422); - const response4 = await fakeRequest("/api/v1/accounts", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-Challenge-Solution": await getSolvedChallenge(), + const { ok: ok4, raw: raw4 } = await client.registerAccount( + "BOB", + "contact@bob.com", + "password", + true, + "en", + "testing", + { + headers: { + "X-Challenge-Solution": await getSolvedChallenge(), + }, }, - body: JSON.stringify({ - username: "BOB", - email: "contact@bob.com", - password: "password", - agreement: "true", - locale: "en", - reason: "testing", - }), - }); + ); - expect(response4.status).toBe(422); + expect(ok4).toBe(false); + expect(raw4.status).toBe(422); }); }); diff --git a/api/api/v1/accounts/lookup/index.test.ts b/api/api/v1/accounts/lookup/index.test.ts index cb10dcf8..ce3a69a6 100644 --- a/api/api/v1/accounts/lookup/index.test.ts +++ b/api/api/v1/accounts/lookup/index.test.ts @@ -1,8 +1,7 @@ import { afterAll, describe, expect, test } from "bun:test"; -import type { Account as ApiAccount } from "@versia/client/types"; -import { fakeRequest, getTestUsers } from "~/tests/utils"; +import { generateClient, getTestUsers } from "~/tests/utils"; -const { users, tokens, deleteUsers } = await getTestUsers(5); +const { users, deleteUsers } = await getTestUsers(5); afterAll(async () => { await deleteUsers(); @@ -11,18 +10,11 @@ afterAll(async () => { // /api/v1/accounts/lookup describe("/api/v1/accounts/lookup", () => { test("should return 200 with users", async () => { - const response = await fakeRequest( - `/api/v1/accounts/lookup?acct=${users[0].data.username}`, - { - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, - ); + await using client = await generateClient(users[0]); - expect(response.status).toBe(200); + const { data, ok } = await client.lookupAccount(users[0].data.username); - const data = (await response.json()) as ApiAccount[]; + expect(ok).toBe(true); expect(data).toEqual( expect.objectContaining({ id: users[0].id, @@ -35,15 +27,13 @@ describe("/api/v1/accounts/lookup", () => { }); test("should require exact case", async () => { - const response = await fakeRequest( - `/api/v1/accounts/lookup?acct=${users[0].data.username.toUpperCase()}`, - { - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, + await using client = await generateClient(users[0]); + + const { ok, raw } = await client.lookupAccount( + users[0].data.username.toUpperCase(), ); - expect(response.status).toBe(404); + expect(ok).toBe(false); + expect(raw.status).toBe(404); }); }); diff --git a/api/api/v1/accounts/relationships/index.test.ts b/api/api/v1/accounts/relationships/index.test.ts index 5068a895..5de24560 100644 --- a/api/api/v1/accounts/relationships/index.test.ts +++ b/api/api/v1/accounts/relationships/index.test.ts @@ -2,9 +2,9 @@ import { afterAll, beforeAll, describe, expect, test } from "bun:test"; import { db } from "@versia/kit/db"; import { Users } from "@versia/kit/tables"; import { eq } from "drizzle-orm"; -import { fakeRequest, getTestUsers } from "~/tests/utils"; +import { generateClient, getTestUsers } from "~/tests/utils"; -const { users, tokens, deleteUsers } = await getTestUsers(5); +const { users, deleteUsers } = await getTestUsers(5); beforeAll(async () => { // user0 should be `locked` @@ -15,27 +15,17 @@ beforeAll(async () => { .set({ isLocked: true }) .where(eq(Users.id, users[0].id)); - const res1 = await fakeRequest(`/api/v1/accounts/${users[0].id}/follow`, { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[1].data.accessToken}`, - "Content-Type": "application/json", - }, - body: JSON.stringify({}), - }); + await using client1 = await generateClient(users[1]); - expect(res1.ok).toBe(true); + const { ok } = await client1.followAccount(users[0].id); - const res2 = await fakeRequest(`/api/v1/accounts/${users[2].id}/follow`, { - method: "POST", - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - "Content-Type": "application/json", - }, - body: JSON.stringify({}), - }); + expect(ok).toBe(true); - expect(res2.ok).toBe(true); + await using client0 = await generateClient(users[0]); + + const { ok: ok2 } = await client0.followAccount(users[2].id); + + expect(ok2).toBe(true); }); afterAll(async () => { @@ -45,27 +35,21 @@ afterAll(async () => { // /api/v1/accounts/relationships describe("/api/v1/accounts/relationships", () => { test("should return 401 if not authenticated", async () => { - const response = await fakeRequest( - `/api/v1/accounts/relationships?id[]=${users[2].id}`, - ); + await using client = await generateClient(); - expect(response.status).toBe(401); + const { ok, raw } = await client.getRelationships([users[2].id]); + + expect(ok).toBe(false); + expect(raw.status).toBe(401); }); test("should return relationships", async () => { - const response = await fakeRequest( - `/api/v1/accounts/relationships?id[]=${users[2].id}`, - { - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, - ); + await using client = await generateClient(users[0]); - expect(response.status).toBe(200); + const { data, ok } = await client.getRelationships([users[2].id]); - const body = await response.json(); - expect(body).toEqual( + expect(ok).toBe(true); + expect(data).toEqual( expect.arrayContaining([ expect.objectContaining({ id: users[2].id, @@ -83,19 +67,12 @@ describe("/api/v1/accounts/relationships", () => { }); test("should be requested_by user1", async () => { - const response = await fakeRequest( - `/api/v1/accounts/relationships?id[]=${users[1].id}`, - { - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, - ); + await using client = await generateClient(users[0]); - expect(response.status).toBe(200); + const { data, ok } = await client.getRelationships([users[1].id]); - const body = await response.json(); - expect(body).toEqual( + expect(ok).toBe(true); + expect(data).toEqual( expect.arrayContaining([ expect.objectContaining({ following: false, diff --git a/api/api/v1/accounts/search/index.test.ts b/api/api/v1/accounts/search/index.test.ts index 0751a202..6aeb39b6 100644 --- a/api/api/v1/accounts/search/index.test.ts +++ b/api/api/v1/accounts/search/index.test.ts @@ -1,8 +1,7 @@ import { afterAll, describe, expect, test } from "bun:test"; -import type { Account as ApiAccount } from "@versia/client/types"; -import { fakeRequest, getTestUsers } from "~/tests/utils"; +import { generateClient, getTestUsers } from "~/tests/utils"; -const { users, tokens, deleteUsers } = await getTestUsers(5); +const { users, deleteUsers } = await getTestUsers(5); afterAll(async () => { await deleteUsers(); @@ -11,18 +10,11 @@ afterAll(async () => { // /api/v1/accounts/search describe("/api/v1/accounts/search", () => { test("should return 200 with users", async () => { - const response = await fakeRequest( - `/api/v1/accounts/search?q=${users[0].data.username}`, - { - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - }, - ); + await using client = await generateClient(users[0]); - expect(response.status).toBe(200); + const { data, ok } = await client.searchAccount(users[0].data.username); - const data = (await response.json()) as ApiAccount[]; + expect(ok).toBe(true); expect(data).toEqual( expect.arrayContaining([ expect.objectContaining({ diff --git a/api/api/v1/accounts/update_credentials/index.test.ts b/api/api/v1/accounts/update_credentials/index.test.ts index f1c0ebb4..ee2264a5 100644 --- a/api/api/v1/accounts/update_credentials/index.test.ts +++ b/api/api/v1/accounts/update_credentials/index.test.ts @@ -1,9 +1,8 @@ import { afterAll, describe, expect, test } from "bun:test"; -import type { Account as APIAccount } from "@versia/client/types"; import { config } from "~/config.ts"; -import { fakeRequest, getTestUsers } from "~/tests/utils"; +import { generateClient, getTestUsers } from "~/tests/utils"; -const { tokens, deleteUsers } = await getTestUsers(1); +const { users, deleteUsers } = await getTestUsers(1); afterAll(async () => { await deleteUsers(); @@ -13,53 +12,28 @@ afterAll(async () => { describe("/api/v1/accounts/update_credentials", () => { describe("HTML injection testing", () => { test("should not allow HTML injection", async () => { - const response = await fakeRequest( - "/api/v1/accounts/update_credentials", - { - method: "PATCH", - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - body: new URLSearchParams({ - note: "Hi! ", - }), - }, - ); + await using client = await generateClient(users[0]); - expect(response.status).toBe(200); - expect(response.headers.get("content-type")).toContain( - "application/json", - ); + const { ok, data } = await client.updateCredentials({ + note: "Hi! ", + }); - const object = (await response.json()) as APIAccount; - - expect(object.note).toBe( + expect(ok).toBe(true); + expect(data.note).toBe( "

Hi! <script>alert('Hello, world!');</script>

\n", ); }); test("should rewrite all image and video src to go through proxy", async () => { - const response = await fakeRequest( - "/api/v1/accounts/update_credentials", - { - method: "PATCH", - headers: { - Authorization: `Bearer ${tokens[0].data.accessToken}`, - }, - body: new URLSearchParams({ - note: "