85 lines
2.7 KiB
TypeScript
85 lines
2.7 KiB
TypeScript
|
|
import { describe, it, expect } from "vitest";
|
||
|
|
import { readFileSync } from "node:fs";
|
||
|
|
import { resolve } from "node:path";
|
||
|
|
|
||
|
|
describe("useApi composable", () => {
|
||
|
|
const path = resolve(__dirname, "../../composables/useApi.ts");
|
||
|
|
const content = readFileSync(path, "utf-8");
|
||
|
|
|
||
|
|
it("should export useApi function", () => {
|
||
|
|
expect(content).toContain("export function useApi");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("should use useRuntimeConfig for apiBase", () => {
|
||
|
|
expect(content).toContain("useRuntimeConfig");
|
||
|
|
expect(content).toContain("apiBase");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("should create $fetch client with baseURL", () => {
|
||
|
|
expect(content).toContain("$fetch.create");
|
||
|
|
expect(content).toContain("baseURL");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("should export get, post, put, del methods", () => {
|
||
|
|
expect(content).toContain("async function get");
|
||
|
|
expect(content).toContain("async function post");
|
||
|
|
expect(content).toContain("async function put");
|
||
|
|
expect(content).toContain("async function del");
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
describe("useEquipment composable", () => {
|
||
|
|
const path = resolve(__dirname, "../../composables/useEquipment.ts");
|
||
|
|
const content = readFileSync(path, "utf-8");
|
||
|
|
|
||
|
|
it("should export EquipmentItem interface", () => {
|
||
|
|
expect(content).toContain("export interface EquipmentItem");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("should export EquipmentDetail interface", () => {
|
||
|
|
expect(content).toContain("export interface EquipmentDetail");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("should export PaginatedEquipment interface", () => {
|
||
|
|
expect(content).toContain("export interface PaginatedEquipment");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("should export SortOption type", () => {
|
||
|
|
expect(content).toContain("export type SortOption");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("should use useApi internally", () => {
|
||
|
|
expect(content).toContain("useApi");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("should have list method with search, category, sort, page params", () => {
|
||
|
|
expect(content).toContain("async function list");
|
||
|
|
expect(content).toContain("search");
|
||
|
|
expect(content).toContain("category");
|
||
|
|
expect(content).toContain("sort");
|
||
|
|
expect(content).toContain("page");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("should call /api/equipment for list", () => {
|
||
|
|
expect(content).toContain("/api/equipment");
|
||
|
|
expect(content).toContain("/api/equipment/categories");
|
||
|
|
expect(content).toContain("/api/equipment/${id}");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("should have detail method", () => {
|
||
|
|
expect(content).toContain("async function detail");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("should have categories method", () => {
|
||
|
|
expect(content).toContain("async function categories");
|
||
|
|
expect(content).toContain("/api/equipment/categories");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("should return list, detail, categories from composable", () => {
|
||
|
|
expect(content).toContain("return");
|
||
|
|
expect(content).toContain("list");
|
||
|
|
expect(content).toContain("detail");
|
||
|
|
expect(content).toContain("categories");
|
||
|
|
});
|
||
|
|
});
|