Implemented test

This commit is contained in:
Sugui 2024-03-28 11:41:03 +01:00
parent cfee164603
commit 2f7b1cc07d
1 changed files with 34 additions and 0 deletions

34
test/ImageService.test.ts Normal file
View File

@ -0,0 +1,34 @@
import { afterEach, beforeAll, describe, expect, it, mock } from "bun:test";
import Image from "../src/models/Image"
import ImageService from "../src/services/ImageService";
import GelbooruResponse from "../src/models/GelbooruServiceResponse";
describe("endpoint gets a non repeated image", () => {
it("should return an image that is not in the response of the /images endpoint of the bot API", async () => {
const REPEATED_URL = "image.com/1";
const UNIQUE_URL = "image.com/2";
mock.module("../services/GelbooruApiService", () => {
let alreadyCalled = false;
return {
default: {
get: (): GelbooruResponse[] => {
if (alreadyCalled) {
return [{ url: UNIQUE_URL, tags: [] }];
} else {
alreadyCalled = true;
return [{ url: REPEATED_URL, tags: [] }];
}
}
}
}
});
const botApiImagesResponse = { images: [
{_id: "0", url: REPEATED_URL, status: "consumed", tags: ["pokemon", "computer"]}
]};
const image: Image = await ImageService.get();
expect(image.url).not.toBe(REPEATED_URL);
})
})