From 3c289dd3de00449bfaed3f18b3497f07e4377590 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Mon, 16 Oct 2023 08:50:10 -1000 Subject: [PATCH] Tweaks to test --- server/api/api/v1/accounts/[id]/index.ts | 2 +- tests/api.test.ts | 4 +- tests/inbox.test.ts | 214 ++++++++++++----------- tsconfig.json | 2 +- 4 files changed, 120 insertions(+), 102 deletions(-) diff --git a/server/api/api/v1/accounts/[id]/index.ts b/server/api/api/v1/accounts/[id]/index.ts index ced8b5c9..c0f0c8f8 100644 --- a/server/api/api/v1/accounts/[id]/index.ts +++ b/server/api/api/v1/accounts/[id]/index.ts @@ -4,7 +4,7 @@ import { User } from "~database/entities/User"; import { applyConfig } from "@api"; export const meta = applyConfig({ - allowedMethods: ["POST"], + allowedMethods: ["GET"], ratelimits: { max: 30, duration: 60, diff --git a/tests/api.test.ts b/tests/api.test.ts index b579b518..58f896b0 100644 --- a/tests/api.test.ts +++ b/tests/api.test.ts @@ -200,7 +200,9 @@ describe("GET /api/v1/accounts/verify_credentials", () => { expect(account.following_count).toBe(0); expect(account.statuses_count).toBe(0); expect(account.note).toBe(""); - expect(account.url).toBe(`${config.http.base_url}/users/${user.username}`); + expect(account.url).toBe( + `${config.http.base_url}/users/${user.username}` + ); expect(account.avatar).toBeDefined(); expect(account.avatar_static).toBeDefined(); expect(account.header).toBeDefined(); diff --git a/tests/inbox.test.ts b/tests/inbox.test.ts index 7a6b3d7b..ed99474a 100644 --- a/tests/inbox.test.ts +++ b/tests/inbox.test.ts @@ -23,34 +23,38 @@ describe("POST /@test/inbox", () => { test("should store a new Note object", async () => { const activityId = `https://example.com/objects/${crypto.randomUUID()}`; - const response = await fetch(`${config.http.base_url}/users/test/inbox/`, { - method: "POST", - headers: { - "Content-Type": "application/activity+json", - }, - body: JSON.stringify({ - "@context": "https://www.w3.org/ns/activitystreams", - type: "Create", - id: activityId, - actor: { - id: `${config.http.base_url}/users/test`, - type: "Person", - preferredUsername: "test", + const response = await fetch( + `${config.http.base_url}/users/test/inbox/`, + { + method: "POST", + headers: { + "Content-Type": "application/activity+json", + Origin: "http://lysand-test.localhost", }, - to: ["https://www.w3.org/ns/activitystreams#Public"], - cc: [], - published: "2021-01-01T00:00:00.000Z", - object: { + body: JSON.stringify({ "@context": "https://www.w3.org/ns/activitystreams", - id: "https://example.com/notes/1", - type: "Note", - content: "Hello, world!", - summary: null, - inReplyTo: null, + type: "Create", + id: activityId, + actor: { + id: `${config.http.base_url}/users/test`, + type: "Person", + preferredUsername: "test", + }, + to: ["https://www.w3.org/ns/activitystreams#Public"], + cc: [], published: "2021-01-01T00:00:00.000Z", - }, - }), - }); + object: { + "@context": "https://www.w3.org/ns/activitystreams", + id: "https://example.com/notes/1", + type: "Note", + content: "Hello, world!", + summary: null, + inReplyTo: null, + published: "2021-01-01T00:00:00.000Z", + }, + }), + } + ); expect(response.status).toBe(200); expect(response.headers.get("content-type")).toBe("application/json"); @@ -82,34 +86,38 @@ describe("POST /@test/inbox", () => { test("should try to update that Note object", async () => { const activityId = `https://example.com/objects/${crypto.randomUUID()}`; - const response = await fetch(`${config.http.base_url}/users/test/inbox/`, { - method: "POST", - headers: { - "Content-Type": "application/activity+json", - }, - body: JSON.stringify({ - "@context": "https://www.w3.org/ns/activitystreams", - type: "Update", - id: activityId, - actor: { - id: `${config.http.base_url}/users/test`, - type: "Person", - preferredUsername: "test", + const response = await fetch( + `${config.http.base_url}/users/test/inbox/`, + { + method: "POST", + headers: { + "Content-Type": "application/activity+json", + Origin: "http://lysand-test.localhost", }, - to: ["https://www.w3.org/ns/activitystreams#Public"], - cc: [], - published: "2021-01-02T00:00:00.000Z", - object: { + body: JSON.stringify({ "@context": "https://www.w3.org/ns/activitystreams", - id: "https://example.com/notes/1", - type: "Note", - content: "This note has been edited!", - summary: null, - inReplyTo: null, - published: "2021-01-01T00:00:00.000Z", - }, - }), - }); + type: "Update", + id: activityId, + actor: { + id: `${config.http.base_url}/users/test`, + type: "Person", + preferredUsername: "test", + }, + to: ["https://www.w3.org/ns/activitystreams#Public"], + cc: [], + published: "2021-01-02T00:00:00.000Z", + object: { + "@context": "https://www.w3.org/ns/activitystreams", + id: "https://example.com/notes/1", + type: "Note", + content: "This note has been edited!", + summary: null, + inReplyTo: null, + published: "2021-01-01T00:00:00.000Z", + }, + }), + } + ); expect(response.status).toBe(200); expect(response.headers.get("content-type")).toBe("application/json"); @@ -140,34 +148,38 @@ describe("POST /@test/inbox", () => { test("should delete the Note object", async () => { const activityId = `https://example.com/objects/${crypto.randomUUID()}`; - const response = await fetch(`${config.http.base_url}/users/test/inbox/`, { - method: "POST", - headers: { - "Content-Type": "application/activity+json", - }, - body: JSON.stringify({ - "@context": "https://www.w3.org/ns/activitystreams", - type: "Delete", - id: activityId, - actor: { - id: `${config.http.base_url}/users/test`, - type: "Person", - preferredUsername: "test", + const response = await fetch( + `${config.http.base_url}/users/test/inbox/`, + { + method: "POST", + headers: { + "Content-Type": "application/activity+json", + Origin: "http://lysand-test.localhost", }, - to: ["https://www.w3.org/ns/activitystreams#Public"], - cc: [], - published: "2021-01-03T00:00:00.000Z", - object: { + body: JSON.stringify({ "@context": "https://www.w3.org/ns/activitystreams", - id: "https://example.com/notes/1", - type: "Note", - content: "This note has been edited!", - summary: null, - inReplyTo: null, - published: "2021-01-01T00:00:00.000Z", - }, - }), - }); + type: "Delete", + id: activityId, + actor: { + id: `${config.http.base_url}/users/test`, + type: "Person", + preferredUsername: "test", + }, + to: ["https://www.w3.org/ns/activitystreams#Public"], + cc: [], + published: "2021-01-03T00:00:00.000Z", + object: { + "@context": "https://www.w3.org/ns/activitystreams", + id: "https://example.com/notes/1", + type: "Note", + content: "This note has been edited!", + summary: null, + inReplyTo: null, + published: "2021-01-01T00:00:00.000Z", + }, + }), + } + ); expect(response.status).toBe(200); expect(response.headers.get("content-type")).toBe("application/json"); @@ -226,30 +238,34 @@ describe("POST /@test/inbox", () => { test("should return a 404 error when trying to delete a non-existent Note object", async () => { const activityId = `https://example.com/objects/${crypto.randomUUID()}`; - const response = await fetch(`${config.http.base_url}/users/test/inbox/`, { - method: "POST", - headers: { - "Content-Type": "application/activity+json", - }, - body: JSON.stringify({ - "@context": "https://www.w3.org/ns/activitystreams", - type: "Delete", - id: activityId, - actor: { - id: `${config.http.base_url}/users/test`, - type: "Person", - preferredUsername: "test", + const response = await fetch( + `${config.http.base_url}/users/test/inbox/`, + { + method: "POST", + headers: { + "Content-Type": "application/activity+json", + Origin: "http://lysand-test.localhost", }, - to: ["https://www.w3.org/ns/activitystreams#Public"], - cc: [], - published: "2021-01-03T00:00:00.000Z", - object: { + body: JSON.stringify({ "@context": "https://www.w3.org/ns/activitystreams", - id: "https://example.com/notes/2345678909876543", - type: "Note", - }, - }), - }); + type: "Delete", + id: activityId, + actor: { + id: `${config.http.base_url}/users/test`, + type: "Person", + preferredUsername: "test", + }, + to: ["https://www.w3.org/ns/activitystreams#Public"], + cc: [], + published: "2021-01-03T00:00:00.000Z", + object: { + "@context": "https://www.w3.org/ns/activitystreams", + id: "https://example.com/notes/2345678909876543", + type: "Note", + }, + }), + } + ); expect(response.status).toBe(404); expect(response.headers.get("content-type")).toBe("application/json"); diff --git a/tsconfig.json b/tsconfig.json index a26f7689..c76781c9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,7 +18,7 @@ "strictFunctionTypes": true, "forceConsistentCasingInFileNames": true, "allowJs": true, - "emitDecoratorMetadata": true, + "emitDecoratorMetadata": false, "experimentalDecorators": true, "types": [ "bun-types" // add Bun global