tests & image-request on google & inspirobot & front
This commit is contained in:
25
__tests__/api/image-request.test.jsx
Normal file
25
__tests__/api/image-request.test.jsx
Normal 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('');
|
||||
});
|
||||
});
|
18
__tests__/api/inspirobot.test.jsx
Normal file
18
__tests__/api/inspirobot.test.jsx
Normal 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)
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user