Implemented test
This commit is contained in:
parent
cfee164603
commit
2f7b1cc07d
|
@ -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);
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue