-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(portal): add products hook service tests
- Loading branch information
Showing
1 changed file
with
92 additions
and
0 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
kraken-app/kraken-app-portal/src/__test__/services/products.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { describe, it, expect, vi } from "vitest"; | ||
import * as service from "../../services/products"; | ||
import request from "@/utils/helpers/request"; | ||
import { PRODUCT } from "@/utils/constants/api"; | ||
|
||
// Mock request function | ||
vi.mock("@/utils/helpers/request"); | ||
|
||
describe("Service Tests", () => { | ||
afterEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it("should call getListComponents with correct parameters", async () => { | ||
const productId = "testProduct"; | ||
const params = { key: "value" }; | ||
await service.getListComponents(productId, params); | ||
|
||
expect(request).toHaveBeenCalledWith(`${PRODUCT}/${productId}/components`, { | ||
params, | ||
}); | ||
}); | ||
|
||
it("should call getListComponentsV2 with correct parameters", async () => { | ||
const productId = "testProduct"; | ||
const targetMapperKey = "testKey"; | ||
await service.getListComponentsV2(productId, targetMapperKey); | ||
|
||
expect(request).toHaveBeenCalledWith(`${PRODUCT}/${productId}/components/${targetMapperKey}`); | ||
}); | ||
|
||
it("should call createNewComponent with correct parameters", async () => { | ||
const productId = "testProduct"; | ||
const data = { name: "testComponent" }; | ||
await service.createNewComponent(productId, data); | ||
|
||
expect(request).toHaveBeenCalledWith(`${PRODUCT}/${productId}/components`, { | ||
method: "POST", | ||
data, | ||
}); | ||
}); | ||
|
||
it("should call getListEnvs with correct parameters", async () => { | ||
const productId = "testProduct"; | ||
await service.getListEnvs(productId); | ||
|
||
expect(request).toHaveBeenCalledWith(`${PRODUCT}/${productId}/envs`); | ||
}); | ||
|
||
it("should call getComponentDetail with correct parameters", async () => { | ||
const productId = "testProduct"; | ||
const componentId = "testComponent"; | ||
await service.getComponentDetail(productId, componentId); | ||
|
||
expect(request).toHaveBeenCalledWith(`${PRODUCT}/${productId}/components/${componentId}`); | ||
}); | ||
|
||
it("should call editComponentDetail with correct parameters", async () => { | ||
const productId = "testProduct"; | ||
const componentId = "testComponent"; | ||
const data = { description: "updated description" }; | ||
await service.editComponentDetail(productId, componentId, data); | ||
|
||
expect(request).toHaveBeenCalledWith(`${PRODUCT}/${productId}/components/${componentId}`, { | ||
method: "PATCH", | ||
data, | ||
}); | ||
}); | ||
|
||
it("should call deployProduct with correct parameters", async () => { | ||
const productId = "testProduct"; | ||
const envId = "testEnv"; | ||
const data = { status: "deploy" }; | ||
await service.deployProduct(productId, envId, data); | ||
|
||
expect(request).toHaveBeenCalledWith(`${PRODUCT}/${productId}/envs/${envId}/deployment`, { | ||
method: "POST", | ||
data, | ||
}); | ||
}); | ||
|
||
it("should call getAllApiKeyList with correct parameters", async () => { | ||
const productId = "testProduct"; | ||
const params = { page: 1, limit: 10, size: 10 }; | ||
await service.getAllApiKeyList(productId, params); | ||
|
||
expect(request).toHaveBeenCalledWith(`${PRODUCT}/${productId}/env-api-tokens`, { | ||
method: "GET", | ||
params, | ||
}); | ||
}); | ||
}); |