tests & image-request on google & inspirobot & front

This commit is contained in:
2024-05-11 22:37:32 +02:00
parent 6602bfd408
commit 3f0db3f976
24 changed files with 1421 additions and 454 deletions

View File

@@ -0,0 +1,25 @@
import { describe, it, expect } from "vitest";
import { searchAndResizeImage } from "../../src/api/image-request"
describe("Image request API", () => {
it("return a string", async () => {
let query = 'cat';
let imageUrl = await searchAndResizeImage(query);
let isString = typeof imageUrl == 'string'
expect(isString).toBe(true);
});
it("returns a valid image URL when results are found", async () => {
let query = 'cat';
let imageUrl = await searchAndResizeImage(query);
expect(imageUrl).toMatch(/^https?:\/\/.*\.(?:png|jpg|jpeg|gif|webp)$/i);
});
it("returns an empty string when no image is found", async () => {
const query = '[][][][][][][][][][][][][][]'; //cette requ<71>te ne renvoie aucune image
const imageUrl = await searchAndResizeImage(query);
expect(imageUrl).toEqual('');
});
});

View File

@@ -0,0 +1,18 @@
import { describe, it, expect } from "vitest";
import { findInspiration } from "../../src/api/inspirobot"
describe("Inspirobot API", () => {
it("return a string", async () => {
let imageUrl = await findInspiration();
let isString = typeof imageUrl == 'string'
expect(isString).toBe(true);
});
it("returns a valid image URL or an empty string", async () => {
let query = 'cat';
let imageUrl = await findInspiration(query);
let okResult = imageUrl.endsWith('.jpg') || imageUrl == ""
expect(okResult).toBe(true)
});
});