refactor(database): ♻️ Move Token to its own ORM abstraction, optimize familiar_followers route

This commit is contained in:
Jesse Wierzbinski 2024-11-03 17:45:21 +01:00
parent 962c159ddd
commit 845041e4db
No known key found for this signature in database
55 changed files with 694 additions and 504 deletions

View file

@ -34,7 +34,7 @@ describe("API Tests", () => {
{
method: "PATCH",
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
},
body: getFormData({
display_name: "New Display Name",
@ -59,7 +59,7 @@ describe("API Tests", () => {
"/api/v1/accounts/verify_credentials",
{
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
},
},
);
@ -106,7 +106,7 @@ describe("API Tests", () => {
{
method: "POST",
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({}),
@ -132,7 +132,7 @@ describe("API Tests", () => {
{
method: "POST",
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({}),
@ -156,7 +156,7 @@ describe("API Tests", () => {
const response = await fakeRequest("/api/v1/blocks", {
method: "GET",
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
},
});
@ -179,7 +179,7 @@ describe("API Tests", () => {
{
method: "POST",
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({}),
@ -205,7 +205,7 @@ describe("API Tests", () => {
{
method: "POST",
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({}),
@ -231,7 +231,7 @@ describe("API Tests", () => {
{
method: "POST",
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({}),
@ -257,7 +257,7 @@ describe("API Tests", () => {
{
method: "POST",
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ comment: "This is a new note" }),
@ -283,7 +283,7 @@ describe("API Tests", () => {
{
method: "GET",
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
},
},
);
@ -314,7 +314,7 @@ describe("API Tests", () => {
const response = await fakeRequest("/api/v1/profile/avatar", {
method: "DELETE",
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
},
});
@ -335,7 +335,7 @@ describe("API Tests", () => {
const response = await fakeRequest("/api/v1/profile/header", {
method: "DELETE",
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
},
});
@ -358,7 +358,7 @@ describe("API Tests", () => {
{
method: "POST",
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({}),
@ -371,13 +371,13 @@ 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 no familiar followers", async () => {
const response = await fakeRequest(
`/api/v1/accounts/familiar_followers?id[]=${user2.id}`,
{
method: "GET",
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
},
},
);
@ -393,7 +393,9 @@ describe("API Tests", () => {
}[];
expect(Array.isArray(familiarFollowers)).toBe(true);
expect(familiarFollowers.length).toBe(0);
expect(familiarFollowers.length).toBe(1);
expect(familiarFollowers[0].id).toBe(user2.id);
expect(familiarFollowers[0].accounts).toBeArrayOfSize(0);
});
});
});

View file

@ -29,7 +29,7 @@ describe("API Tests", () => {
const response = await fakeRequest("/api/v2/media", {
method: "POST",
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
},
body: formData,
});
@ -52,7 +52,7 @@ describe("API Tests", () => {
const response = await fakeRequest("/api/v1/statuses", {
method: "POST",
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
},
body: new URLSearchParams({
status: "Hello, world!",
@ -94,7 +94,7 @@ describe("API Tests", () => {
const response = await fakeRequest("/api/v1/statuses", {
method: "POST",
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
},
body: new URLSearchParams({
status: "This is a reply!",
@ -139,7 +139,7 @@ describe("API Tests", () => {
`/api/v1/statuses/${status?.id}`,
{
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
},
},
);
@ -184,7 +184,7 @@ describe("API Tests", () => {
{
method: "POST",
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
},
},
);
@ -209,7 +209,7 @@ describe("API Tests", () => {
{
method: "POST",
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
},
},
);
@ -232,7 +232,7 @@ describe("API Tests", () => {
`/api/v1/statuses/${status?.id}/context`,
{
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
},
},
);
@ -259,7 +259,7 @@ describe("API Tests", () => {
{
method: "GET",
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
},
},
);
@ -289,7 +289,7 @@ describe("API Tests", () => {
{
method: "POST",
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
},
},
);
@ -306,7 +306,7 @@ describe("API Tests", () => {
{
method: "POST",
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
},
},
);
@ -330,7 +330,7 @@ describe("API Tests", () => {
{
method: "DELETE",
headers: {
Authorization: `Bearer ${token.accessToken}`,
Authorization: `Bearer ${token.data.accessToken}`,
},
},
);