diff --git a/apps/api/src/bin/www.ts b/apps/api/src/bin/www.ts index 3c6552a..b270c7b 100644 --- a/apps/api/src/bin/www.ts +++ b/apps/api/src/bin/www.ts @@ -2,16 +2,16 @@ import { app } from "@/app"; import { Environment } from "@/config/environment"; (() => { - const PORT = Environment.PORT; - app.listen(PORT); + const PORT = Environment.PORT; + app.listen(PORT); - console.log(`app running on port ${PORT}`); + console.log(`app running on port ${PORT}`); - if (Environment.NODE_ENV) { - console.log(`running in ${Environment.NODE_ENV} mode`); - } else { - console.log( - "no environment provided on .env file, make sure to set the NODE_ENV variable", - ); - } + if (Environment.NODE_ENV) { + console.log(`running in ${Environment.NODE_ENV} mode`); + } else { + console.log( + "no environment provided on .env file, make sure to set the NODE_ENV variable", + ); + } })(); diff --git a/apps/api/src/config/database/config.ts b/apps/api/src/config/database/config.ts index 058a2a1..99929aa 100644 --- a/apps/api/src/config/database/config.ts +++ b/apps/api/src/config/database/config.ts @@ -12,23 +12,23 @@ import * as schema from "./schema"; * */ async function getDb() { - if (Environment.NODE_ENV === "production") { - // this set up is for supabase datbase, so we disable prepare, since transaction mode doesnt support it - const client = postgres(Environment.DATABASE_URL, { prepare: false }); + if (Environment.NODE_ENV === "production") { + // this set up is for supabase datbase, so we disable prepare, since transaction mode doesnt support it + const client = postgres(Environment.DATABASE_URL, { prepare: false }); - const db = drizzle(client, { schema }); + const db = drizzle(client, { schema }); - return db; - } + return db; + } - const { POSTGRES_PASSWORD, POSTGRES_USER, POSTGRES_DATABASE } = Environment; + const { POSTGRES_PASSWORD, POSTGRES_USER, POSTGRES_DATABASE } = Environment; - const connectionString = `postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@127.0.0.1:5432/${POSTGRES_DATABASE}`; - const client = postgres(connectionString, { prepare: false }); + const connectionString = `postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@127.0.0.1:5432/${POSTGRES_DATABASE}`; + const client = postgres(connectionString, { prepare: false }); - const db = drizzle(client, { schema }); + const db = drizzle(client, { schema }); - return db; + return db; } const db = await getDb(); diff --git a/apps/api/src/config/database/custom-types.ts b/apps/api/src/config/database/custom-types.ts index cc32379..8893f66 100644 --- a/apps/api/src/config/database/custom-types.ts +++ b/apps/api/src/config/database/custom-types.ts @@ -1,9 +1,9 @@ import { customType } from "drizzle-orm/pg-core"; const bytea = customType<{ data: Buffer; notNull: false; default: false }>({ - dataType() { - return "bytea"; - }, + dataType() { + return "bytea"; + }, }); export { bytea }; diff --git a/apps/api/src/config/database/migrations/meta/0000_snapshot.json b/apps/api/src/config/database/migrations/meta/0000_snapshot.json index 0adf976..1767e2f 100644 --- a/apps/api/src/config/database/migrations/meta/0000_snapshot.json +++ b/apps/api/src/config/database/migrations/meta/0000_snapshot.json @@ -1,148 +1,142 @@ { - "id": "45a2554d-f7ce-4db6-be5f-0b6d03cda34e", - "prevId": "00000000-0000-0000-0000-000000000000", - "version": "7", - "dialect": "postgresql", - "tables": { - "public.entry": { - "name": "entry", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "user_id": { - "name": "user_id", - "type": "uuid", - "primaryKey": false, - "notNull": true - }, - "title": { - "name": "title", - "type": "varchar(80)", - "primaryKey": false, - "notNull": true, - "default": "'Untintled'" - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "word_count": { - "name": "word_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "content": { - "name": "content", - "type": "json", - "primaryKey": false, - "notNull": false, - "default": "'{\"type\":\"doc\",\"content\":[{\"type\":\"paragraph\"}]}'::json" - }, - "iv": { - "name": "iv", - "type": "bytea", - "primaryKey": false, - "notNull": false - }, - "end_date": { - "name": "end_date", - "type": "timestamp", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "entry_user_id_users_id_fk": { - "name": "entry_user_id_users_id_fk", - "tableFrom": "entry", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "public.users": { - "name": "users", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "name": { - "name": "name", - "type": "varchar(50)", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "varchar(100)", - "primaryKey": false, - "notNull": true - }, - "password": { - "name": "password", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "end_date": { - "name": "end_date", - "type": "date", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "users_email_unique": { - "name": "users_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - } - } - }, - "enums": {}, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file + "id": "45a2554d-f7ce-4db6-be5f-0b6d03cda34e", + "prevId": "00000000-0000-0000-0000-000000000000", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.entry": { + "name": "entry", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(80)", + "primaryKey": false, + "notNull": true, + "default": "'Untintled'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "word_count": { + "name": "word_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "content": { + "name": "content", + "type": "json", + "primaryKey": false, + "notNull": false, + "default": "'{\"type\":\"doc\",\"content\":[{\"type\":\"paragraph\"}]}'::json" + }, + "iv": { + "name": "iv", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "end_date": { + "name": "end_date", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "entry_user_id_users_id_fk": { + "name": "entry_user_id_users_id_fk", + "tableFrom": "entry", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "password": { + "name": "password", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "end_date": { + "name": "end_date", + "type": "date", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": ["email"] + } + } + } + }, + "enums": {}, + "schemas": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} diff --git a/apps/api/src/config/database/migrations/meta/0001_snapshot.json b/apps/api/src/config/database/migrations/meta/0001_snapshot.json index 152bed8..d899c1b 100644 --- a/apps/api/src/config/database/migrations/meta/0001_snapshot.json +++ b/apps/api/src/config/database/migrations/meta/0001_snapshot.json @@ -1,133 +1,127 @@ { - "id": "6bfbb042-5dfb-42f5-8185-2a2e897d7484", - "prevId": "45a2554d-f7ce-4db6-be5f-0b6d03cda34e", - "version": "7", - "dialect": "postgresql", - "tables": { - "public.entry": { - "name": "entry", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "user_id": { - "name": "user_id", - "type": "uuid", - "primaryKey": false, - "notNull": true - }, - "data": { - "name": "data", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "iv": { - "name": "iv", - "type": "bytea", - "primaryKey": false, - "notNull": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "end_date": { - "name": "end_date", - "type": "timestamp", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "entry_user_id_users_id_fk": { - "name": "entry_user_id_users_id_fk", - "tableFrom": "entry", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "public.users": { - "name": "users", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "name": { - "name": "name", - "type": "varchar(50)", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "varchar(100)", - "primaryKey": false, - "notNull": true - }, - "password": { - "name": "password", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "end_date": { - "name": "end_date", - "type": "date", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "users_email_unique": { - "name": "users_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - } - } - }, - "enums": {}, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file + "id": "6bfbb042-5dfb-42f5-8185-2a2e897d7484", + "prevId": "45a2554d-f7ce-4db6-be5f-0b6d03cda34e", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.entry": { + "name": "entry", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "iv": { + "name": "iv", + "type": "bytea", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "end_date": { + "name": "end_date", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "entry_user_id_users_id_fk": { + "name": "entry_user_id_users_id_fk", + "tableFrom": "entry", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "password": { + "name": "password", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "end_date": { + "name": "end_date", + "type": "date", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": ["email"] + } + } + } + }, + "enums": {}, + "schemas": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} diff --git a/apps/api/src/config/database/migrations/meta/0002_snapshot.json b/apps/api/src/config/database/migrations/meta/0002_snapshot.json index d2c6bd1..1dd1592 100644 --- a/apps/api/src/config/database/migrations/meta/0002_snapshot.json +++ b/apps/api/src/config/database/migrations/meta/0002_snapshot.json @@ -1,133 +1,127 @@ { - "id": "44223be2-6cf6-451f-95ea-90ba58b65e6d", - "prevId": "6bfbb042-5dfb-42f5-8185-2a2e897d7484", - "version": "7", - "dialect": "postgresql", - "tables": { - "public.entry": { - "name": "entry", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "user_id": { - "name": "user_id", - "type": "uuid", - "primaryKey": false, - "notNull": true - }, - "data": { - "name": "data", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "iv": { - "name": "iv", - "type": "varchar", - "primaryKey": false, - "notNull": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "end_date": { - "name": "end_date", - "type": "timestamp", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "entry_user_id_users_id_fk": { - "name": "entry_user_id_users_id_fk", - "tableFrom": "entry", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "public.users": { - "name": "users", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "uuid", - "primaryKey": true, - "notNull": true, - "default": "gen_random_uuid()" - }, - "name": { - "name": "name", - "type": "varchar(50)", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "varchar(100)", - "primaryKey": false, - "notNull": true - }, - "password": { - "name": "password", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "end_date": { - "name": "end_date", - "type": "date", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "users_email_unique": { - "name": "users_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - } - } - }, - "enums": {}, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file + "id": "44223be2-6cf6-451f-95ea-90ba58b65e6d", + "prevId": "6bfbb042-5dfb-42f5-8185-2a2e897d7484", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.entry": { + "name": "entry", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "iv": { + "name": "iv", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "end_date": { + "name": "end_date", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "entry_user_id_users_id_fk": { + "name": "entry_user_id_users_id_fk", + "tableFrom": "entry", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "password": { + "name": "password", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "end_date": { + "name": "end_date", + "type": "date", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": ["email"] + } + } + } + }, + "enums": {}, + "schemas": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} diff --git a/apps/api/src/config/database/migrations/meta/_journal.json b/apps/api/src/config/database/migrations/meta/_journal.json index 8c2d1b0..514ff02 100644 --- a/apps/api/src/config/database/migrations/meta/_journal.json +++ b/apps/api/src/config/database/migrations/meta/_journal.json @@ -31,4 +31,4 @@ "breakpoints": true } ] -} \ No newline at end of file +} diff --git a/apps/api/src/config/routing/index.ts b/apps/api/src/config/routing/index.ts index 944b4d9..081daf5 100644 --- a/apps/api/src/config/routing/index.ts +++ b/apps/api/src/config/routing/index.ts @@ -6,20 +6,20 @@ import Elysia, { error } from "elysia"; const Routes = new Elysia(); Routes.onAfterHandle(({ set }) => { - set.headers["Content-Type"] = "application/json; charset=utf8"; + set.headers["Content-Type"] = "application/json; charset=utf8"; }); Routes.onError(({ code, error: e }) => { - switch (code) { - case "PARSE": - return error("Bad Request", { error: "error parsing body" }); - case "NOT_FOUND": - return error("Not Implemented", { error: "Route not found :(" }); - case "VALIDATION": - return error("Bad Request", { error: e.validator }); - default: - return error("Internal Server Error", {}); - } + switch (code) { + case "PARSE": + return error("Bad Request", { error: "error parsing body" }); + case "NOT_FOUND": + return error("Not Implemented", { error: "Route not found :(" }); + case "VALIDATION": + return error("Bad Request", { error: e.validator }); + default: + return error("Internal Server Error", {}); + } }); Routes.use(HealthRouter); diff --git a/apps/api/tests/integration/entry/post.test.ts b/apps/api/tests/integration/entry/post.test.ts index 487668d..4d4ca13 100644 --- a/apps/api/tests/integration/entry/post.test.ts +++ b/apps/api/tests/integration/entry/post.test.ts @@ -5,65 +5,65 @@ import { createUser } from "@/tests/lib/user"; import { endpointPath } from "."; describe("Test POST method on entries endpoints", () => { - describe("Entry created succesfully", async () => { - const { cookie } = await createUser({}); + describe("Entry created succesfully", async () => { + const { cookie } = await createUser({}); - const res = await app.handle( - new Request(`${endpointPath}`, { - method: "POST", - headers: { - "Content-Type": "application/json; charset=utf-8", - cookie: cookie, - }, - body: JSON.stringify(EXAMPLE_DOCUMENT), - }), - ); + const res = await app.handle( + new Request(`${endpointPath}`, { + method: "POST", + headers: { + "Content-Type": "application/json; charset=utf-8", + cookie: cookie, + }, + body: JSON.stringify(EXAMPLE_DOCUMENT), + }), + ); - it("should return 201 status code", async () => { - expect(res.status).toBe(201); - }); + it("should return 201 status code", async () => { + expect(res.status).toBe(201); + }); - describe("return body", async () => { - const body: { id: string } = await res.json(); + describe("return body", async () => { + const body: { id: string } = await res.json(); - it("should return object on body response", () => { - expect(body).toBeObject(); - }); + it("should return object on body response", () => { + expect(body).toBeObject(); + }); - it("should return new entry id on body response", () => { - expect(body).toContainKey("id"); - expect(body.id).toBeString(); - }); - }); - }); + it("should return new entry id on body response", () => { + expect(body).toContainKey("id"); + expect(body.id).toBeString(); + }); + }); + }); - describe("Incorrect schema on body json", async () => { - const { cookie } = await createUser({}); + describe("Incorrect schema on body json", async () => { + const { cookie } = await createUser({}); - const res = await app.handle( - new Request(`${endpointPath}/`, { - method: "POST", - headers: { - "Content-Type": "application/json; charset=utf-8", - cookie: cookie, - }, - body: JSON.stringify({ - title: 1233, - content: "asdfas", - word_count: "asdf", - iv: 123, - }), - }), - ); + const res = await app.handle( + new Request(`${endpointPath}/`, { + method: "POST", + headers: { + "Content-Type": "application/json; charset=utf-8", + cookie: cookie, + }, + body: JSON.stringify({ + title: 1233, + content: "asdfas", + word_count: "asdf", + iv: 123, + }), + }), + ); - it("should return 400 status code", async () => { - expect(res.status).toBe(400); - }); + it("should return 400 status code", async () => { + expect(res.status).toBe(400); + }); - it("should return error message", async () => { - const body = await res.json(); + it("should return error message", async () => { + const body = await res.json(); - expect(body).toContainKey("error"); - }); - }); + expect(body).toContainKey("error"); + }); + }); }); diff --git a/apps/api/tests/lib/parse-unit8array/index.ts b/apps/api/tests/lib/parse-unit8array/index.ts index b4ffeeb..bd2f23b 100644 --- a/apps/api/tests/lib/parse-unit8array/index.ts +++ b/apps/api/tests/lib/parse-unit8array/index.ts @@ -1,27 +1,27 @@ function uint8ArrayToBase64(uint8Array: Uint8Array) { - let binary = ""; - const len = uint8Array.byteLength; - for (let i = 0; i < len; i++) { - binary += String.fromCharCode(uint8Array[i]); - } - return btoa(binary); + let binary = ""; + const len = uint8Array.byteLength; + for (let i = 0; i < len; i++) { + binary += String.fromCharCode(uint8Array[i]); + } + return btoa(binary); } type Base64String = string & { __base64: never }; function base64ToUint8Array(base64: Base64String) { - const binaryString = atob(base64); - const len = binaryString.length; - const bytes = new Uint8Array(len); - for (let i = 0; i < len; i++) { - bytes[i] = binaryString.charCodeAt(i); - } - return bytes; + const binaryString = atob(base64); + const len = binaryString.length; + const bytes = new Uint8Array(len); + for (let i = 0; i < len; i++) { + bytes[i] = binaryString.charCodeAt(i); + } + return bytes; } function isBase64(str: string): str is Base64String { - const base64Regex = /^[A-Za-z0-9+/]+={0,2}$/; - return base64Regex.test(str); + const base64Regex = /^[A-Za-z0-9+/]+={0,2}$/; + return base64Regex.test(str); } export { uint8ArrayToBase64, base64ToUint8Array, isBase64 };