Compare commits
1 Commits
3040735500
...
99cc30d7f7
Author | SHA1 | Date |
---|---|---|
Sugui | 99cc30d7f7 |
|
@ -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();
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { env } from "bun";
|
||||
import app from "./app";
|
||||
import app from "src/app";
|
||||
|
||||
const PORT = env.PORT;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<GelbooruServiceResponse> {
|
||||
|
|
|
@ -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[] = [];
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import BotImage from "./BotImage";
|
||||
import BotImage from "src/types/BotImage";
|
||||
|
||||
export interface BotApiResponse {
|
||||
images: BotImage[]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import GelbooruPost from "./GelbooruPost";
|
||||
import GelbooruPost from "src/types/GelbooruPost";
|
||||
|
||||
export default interface GelbooruServiceResponse {
|
||||
posts: GelbooruPost[];
|
||||
|
|
|
@ -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: () => {
|
||||
|
|
|
@ -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: [
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
"allowJs": true,
|
||||
"types": [
|
||||
"bun-types" // add Bun global
|
||||
]
|
||||
],
|
||||
"baseUrl": "./",
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue