Skip to content

Commit

Permalink
chore: fix prettier write dir and add tests dir
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonraimondi committed Mar 21, 2024
1 parent c12b93d commit 3b971c3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dev": "tsx --watch src/main.ts | pino-pretty",
"compile": "tsc --project tsconfig.build.json",
"build": "run-s clean compile",
"format": "prettier --write \"./src/**/*.ts\"",
"format": "prettier --write \"./(src|tests)/**/*.ts\"",
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage",
Expand Down
20 changes: 15 additions & 5 deletions tests/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ suite("app", () => {
it("throws when invalid domain", async () => {
const res = await app.request("/?url=bar");
expect(res.status).toBe(400);
expect(await res.text()).toMatch(/Invalid query/ig);
expect(await res.text()).toMatch(/Invalid query/gi);
});
});

describe("GET /?hash=", () => {
describe("without CRYPTO_KEY", () => {
it("throws when server is not configured for encryption", async () => {
const res = await app.request("/?hash=str-enc:a/4xkic0kY8scM3QRJIiLLtQ3NhZxEudhmd7RZDbsuuguXkamhZe0HdW9LmnZxtGCtf0GAPO5II85fE8rSkdFNIbBATyS/INKM0hmw==:a4S74z7c4DQVtijl");
const res = await app.request(
"/?hash=str-enc:a/4xkic0kY8scM3QRJIiLLtQ3NhZxEudhmd7RZDbsuuguXkamhZe0HdW9LmnZxtGCtf0GAPO5II85fE8rSkdFNIbBATyS/INKM0hmw==:a4S74z7c4DQVtijl",
);
const body = await res.json();
expect(res.status).toBe(400);
expect(body.message).toMatch(/This server is not configured for encryption/);
Expand All @@ -78,13 +80,21 @@ suite("app", () => {

describe("with CRYPTO_KEY", () => {
beforeEach(async () => {
const cryptoKey = '{"kty":"oct","k":"cq8cebOn49gXxcjoRbjP93z4OpzCkyz4WJSgPnvR4ds","alg":"A256GCM","key_ops":["encrypt","decrypt"],"ext":true}';
const cryptoKey =
'{"kty":"oct","k":"cq8cebOn49gXxcjoRbjP93z4OpzCkyz4WJSgPnvR4ds","alg":"A256GCM","key_ops":["encrypt","decrypt"],"ext":true}';
const stringEncrypter = await StringEncrypter.fromCryptoString(cryptoKey);
app = createApplication(browserPool, imageRenderService, imageStorageService, stringEncrypter);
app = createApplication(
browserPool,
imageRenderService,
imageStorageService,
stringEncrypter,
);
});

it("succeeds!", async () => {
const res = await app.request("/?hash=str-enc:a/4xkic0kY8scM3QRJIiLLtQ3NhZxEudhmd7RZDbsuuguXkamhZe0HdW9LmnZxtGCtf0GAPO5II85fE8rSkdFNIbBATyS/INKM0hmw==:a4S74z7c4DQVtijl");
const res = await app.request(
"/?hash=str-enc:a/4xkic0kY8scM3QRJIiLLtQ3NhZxEudhmd7RZDbsuuguXkamhZe0HdW9LmnZxtGCtf0GAPO5II85fE8rSkdFNIbBATyS/INKM0hmw==:a4S74z7c4DQVtijl",
);
expect(res.status).toBe(200);
});
});
Expand Down
7 changes: 3 additions & 4 deletions tests/helpers/stubs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from "fs/promises";

import {ImageRenderInterface} from "../../src/lib/image_render.js";
import { ImageRenderInterface } from "../../src/lib/image_render.js";

export class StubImageRenderService implements ImageRenderInterface {
static readonly POOL_METRICS = {
Expand All @@ -13,11 +13,10 @@ export class StubImageRenderService implements ImageRenderInterface {
available: 1,
};

async drainBrowserPool(): Promise<void> {
}
async drainBrowserPool(): Promise<void> {}

async screenshot(): Promise<Buffer> {
const {join} = await import("path");
const { join } = await import("path");
const filePath = join(__dirname, "./assets/test_img.png");
return await fs.readFile(filePath);
}
Expand Down

0 comments on commit 3b971c3

Please sign in to comment.