2024-03-28 10:41:03 +00:00
|
|
|
import { afterEach, beforeAll, describe, expect, it, mock } from "bun:test";
|
2024-03-28 11:43:24 +00:00
|
|
|
import Image from "../src/types/Image"
|
2024-03-28 10:41:03 +00:00
|
|
|
import ImageService from "../src/services/ImageService";
|
2024-03-28 11:43:24 +00:00
|
|
|
import GelbooruApiResponse from "../src/types/GelbooruServiceResponse";
|
|
|
|
import { BotApiResponse } from "../src/types/BotApiResponse";
|
2024-03-28 10:41:03 +00:00
|
|
|
|
|
|
|
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";
|
|
|
|
|
2024-03-28 11:43:24 +00:00
|
|
|
mock.module("../src/services/GelbooruApiService", () => {
|
2024-03-28 10:41:03 +00:00
|
|
|
let alreadyCalled = false;
|
|
|
|
return {
|
|
|
|
default: {
|
2024-03-28 11:43:24 +00:00
|
|
|
get: (): GelbooruApiResponse => {
|
2024-03-28 10:41:03 +00:00
|
|
|
if (alreadyCalled) {
|
2024-03-28 11:43:24 +00:00
|
|
|
return { posts: [{ url: UNIQUE_URL, tags: [] }] };
|
2024-03-28 10:41:03 +00:00
|
|
|
} else {
|
|
|
|
alreadyCalled = true;
|
2024-03-28 11:43:24 +00:00
|
|
|
return { posts: [{ url: REPEATED_URL, tags: [] }] };
|
2024-03-28 10:41:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-03-28 11:43:24 +00:00
|
|
|
mock.module("../src/services/BotApiService", () => ({
|
|
|
|
default: {
|
|
|
|
getAll: (): BotApiResponse => ({
|
|
|
|
images: [
|
|
|
|
{ _id: "0", url: REPEATED_URL, status: "consumed", tags: ["pokemon", "computer"], "__v": 0 }
|
|
|
|
]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
2024-03-28 10:41:03 +00:00
|
|
|
const image: Image = await ImageService.get();
|
|
|
|
expect(image.url).not.toBe(REPEATED_URL);
|
|
|
|
})
|
|
|
|
})
|