From a2fdf862dd4278d17332d30b9999fb2beed42f62 Mon Sep 17 00:00:00 2001 From: Sugui Date: Wed, 17 Apr 2024 19:23:39 +0200 Subject: [PATCH] Changed relative paths to absolute paths --- src/app.ts | 2 +- src/controllers/ImageController.ts | 2 +- src/index.ts | 2 +- src/services/BotApiService.ts | 2 +- src/services/GelbooruApiService.ts | 4 ++-- src/services/ImageService.ts | 8 +++---- src/types/BotApiResponse.ts | 2 +- src/types/GelbooruServiceResponse.ts | 2 +- test/ImageController/ImageController.test.ts | 16 +++++++------- test/ImageService/ImageService.test.ts | 22 ++++++++++---------- tsconfig.json | 3 ++- 11 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/app.ts b/src/app.ts index abb68a2..893a90b 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,7 +1,7 @@ import compression from "compression"; import express from "express"; import listEndpoints from "express-list-endpoints"; -import ImageController from "./controllers/ImageController"; +import ImageController from "src/controllers/ImageController"; const app = express(); diff --git a/src/controllers/ImageController.ts b/src/controllers/ImageController.ts index 759e732..611b1cc 100644 --- a/src/controllers/ImageController.ts +++ b/src/controllers/ImageController.ts @@ -1,5 +1,5 @@ import { Request, Response } from "express"; -import ImageService from "../services/ImageService"; +import ImageService from "src/services/ImageService"; class ImageController { async get(req: Request, res: Response) { diff --git a/src/index.ts b/src/index.ts index 6060e6d..6032ee1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import { env } from "bun"; -import app from "./app"; +import app from "src/app"; const PORT = env.PORT; diff --git a/src/services/BotApiService.ts b/src/services/BotApiService.ts index 4b4f4a1..94cdd38 100644 --- a/src/services/BotApiService.ts +++ b/src/services/BotApiService.ts @@ -1,5 +1,5 @@ import { env } from "bun"; -import { BotApiResponse } from "../types/BotApiResponse"; +import { BotApiResponse } from "src/types/BotApiResponse"; class BotApiService { readonly BOT_API_URI = env.BOT_API_URI; diff --git a/src/services/GelbooruApiService.ts b/src/services/GelbooruApiService.ts index 480d2b9..3a4d5dc 100644 --- a/src/services/GelbooruApiService.ts +++ b/src/services/GelbooruApiService.ts @@ -1,5 +1,5 @@ -import GelbooruApiResponse from "../types/GelbooruApiResponse"; -import GelbooruServiceResponse from "../types/GelbooruServiceResponse"; +import GelbooruApiResponse from "src/types/GelbooruApiResponse"; +import GelbooruServiceResponse from "src/types/GelbooruServiceResponse"; class GelbooruApiService { async get(): Promise { diff --git a/src/services/ImageService.ts b/src/services/ImageService.ts index 56924c0..20f37a3 100644 --- a/src/services/ImageService.ts +++ b/src/services/ImageService.ts @@ -1,7 +1,7 @@ -import GelbooruServiceResponse from "../types/GelbooruServiceResponse"; -import Image from "../types/Image"; -import BotApiService from "./BotApiService"; -import GelbooruApiService from "./GelbooruApiService"; +import GelbooruServiceResponse from "src/types/GelbooruServiceResponse"; +import Image from "src/types/Image"; +import BotApiService from "src/services/BotApiService"; +import GelbooruApiService from "src/services/GelbooruApiService"; class ImageService { postsQueue: Image[] = []; diff --git a/src/types/BotApiResponse.ts b/src/types/BotApiResponse.ts index fc184ce..1076bee 100644 --- a/src/types/BotApiResponse.ts +++ b/src/types/BotApiResponse.ts @@ -1,4 +1,4 @@ -import BotImage from "./BotImage"; +import BotImage from "src/types/BotImage"; export interface BotApiResponse { images: BotImage[] diff --git a/src/types/GelbooruServiceResponse.ts b/src/types/GelbooruServiceResponse.ts index a6cf355..4bfc75f 100644 --- a/src/types/GelbooruServiceResponse.ts +++ b/src/types/GelbooruServiceResponse.ts @@ -1,4 +1,4 @@ -import GelbooruPost from "./GelbooruPost"; +import GelbooruPost from "src/types/GelbooruPost"; export default interface GelbooruServiceResponse { posts: GelbooruPost[]; diff --git a/test/ImageController/ImageController.test.ts b/test/ImageController/ImageController.test.ts index 52b9da9..6971d94 100644 --- a/test/ImageController/ImageController.test.ts +++ b/test/ImageController/ImageController.test.ts @@ -1,18 +1,18 @@ import { afterEach, describe, expect, it, mock, jest } from "bun:test"; -import Image from "../../src/types/Image"; -import ImageService from "../../src/services/ImageService"; -import GelbooruApiResponse from "../../src/types/GelbooruServiceResponse"; -import { BotApiResponse } from "../../src/types/BotApiResponse"; +import Image from "src/types/Image"; +import ImageService from "src/services/ImageService"; +import GelbooruApiResponse from "src/types/GelbooruServiceResponse"; +import { BotApiResponse } from "src/types/BotApiResponse"; import fs from "node:fs"; -import ImageController from "../../src/controllers/ImageController"; -import app from "../../src/app"; +import ImageController from "src/controllers/ImageController"; +import app from "src/app"; import request from "supertest"; const imageServiceOriginal = ImageService; afterEach(() => { mock.restore(); - mock.module("../../src/services/ImageService", () => ({ + mock.module("src/services/ImageService", () => ({ default: imageServiceOriginal, })); }) @@ -26,7 +26,7 @@ describe("endpoint returns the correct status codes", () => { }); it("should return 500 if any error happens", async () => { - mock.module("../../src/services/ImageService", () => { + mock.module("src/services/ImageService", () => { return { default: { get: () => { diff --git a/test/ImageService/ImageService.test.ts b/test/ImageService/ImageService.test.ts index 9ae0912..865816a 100644 --- a/test/ImageService/ImageService.test.ts +++ b/test/ImageService/ImageService.test.ts @@ -1,10 +1,10 @@ import { afterEach, describe, expect, it, mock, spyOn } from "bun:test"; -import Image from "../../src/types/Image"; -import ImageService from "../../src/services/ImageService"; -import GelbooruApiResponse from "../../src/types/GelbooruServiceResponse"; -import { BotApiResponse } from "../../src/types/BotApiResponse"; -import GelbooruApiService from "../../src/services/GelbooruApiService"; -import BotApiService from "../../src/services/BotApiService"; +import Image from "src/types/Image"; +import ImageService from "src/services/ImageService"; +import GelbooruApiResponse from "src/types/GelbooruServiceResponse"; +import { BotApiResponse } from "src/types/BotApiResponse"; +import GelbooruApiService from "src/services/GelbooruApiService"; +import BotApiService from "src/services/BotApiService"; import fs from "node:fs"; const imageServiceOriginal = ImageService; @@ -13,13 +13,13 @@ const botApiServiceOriginal = BotApiService; afterEach(() => { mock.restore(); - mock.module("../../src/services/ImageService", () => ({ + mock.module("src/services/ImageService", () => ({ default: imageServiceOriginal, })); - mock.module("../../src/services/GelbooruApiService", () => ({ + mock.module("src/services/GelbooruApiService", () => ({ default: gelbooruApiServiceOriginal, })); - mock.module("../../src/services/BotApiService", () => ({ + mock.module("src/services/BotApiService", () => ({ default: botApiServiceOriginal })); }) @@ -29,7 +29,7 @@ describe("endpoint gets a non repeated image", () => { const REPEATED_URL = "https://fastly.picsum.photos/id/1/10/20.jpg?hmac=gY6PvUXFacKfYpBpTTVcNLxumpyMmoCamM-J5DOPwNc"; const UNIQUE_URL = "https://fastly.picsum.photos/id/2/10/20.jpg?hmac=zy6lz21CuRIstr9ETx9h5AuoH50s_L2uIEct3dROpY8"; - mock.module("../../src/services/GelbooruApiService", () => { + mock.module("src/services/GelbooruApiService", () => { let alreadyCalled = false; return { default: { @@ -45,7 +45,7 @@ describe("endpoint gets a non repeated image", () => { } }); - mock.module("../../src/services/BotApiService", () => ({ + mock.module("src/services/BotApiService", () => ({ default: { getAll: (): BotApiResponse => ({ images: [ diff --git a/tsconfig.json b/tsconfig.json index 7556e1d..eeeb347 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,6 +17,7 @@ "allowJs": true, "types": [ "bun-types" // add Bun global - ] + ], + "baseUrl": "./", } }