-
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.
feat(portal): check duplicate name when changing a new seller API (#86)
* feat(improvement): check duplicate name when changing a new seller API name * fix(portal): add products hook service tests * fix(portal): add validator tests * build(misc): add sonarcloud exlusion for utils in kraken-app-portal * correct the sonar coverage config * correct the sonar.coverage.exclusions * fix(portal): adjust Promise rejection message as error --------- Co-authored-by: Dave Xiong <[email protected]>
- Loading branch information
Showing
8 changed files
with
254 additions
and
12 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, | ||
}); | ||
}); | ||
}); |
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
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
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
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
20 changes: 20 additions & 0 deletions
20
kraken-app/kraken-app-portal/src/utils/helpers/validators.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,20 @@ | ||
import { UseMutateAsyncFunction } from '@tanstack/react-query'; | ||
import { isEmpty } from 'lodash'; | ||
import { IProductIdAndNameParams } from '../types/product.type'; | ||
import { isURL } from './url'; | ||
|
||
export const validateServerName = async (validateName: UseMutateAsyncFunction<any, Error, IProductIdAndNameParams, unknown>, currentProduct: string, name: string) => { | ||
const { data: isValid } = await validateName({ productId: currentProduct, name }); | ||
if (isValid) { | ||
return Promise.resolve(); | ||
} else { | ||
return Promise.reject(new Error(`The name ${name} is already taken`)); | ||
} | ||
}; | ||
|
||
export const validateURL = (_: unknown, value: string) => { | ||
if (isURL(value) || isEmpty(value)) { | ||
return Promise.resolve(); | ||
} | ||
return Promise.reject(new Error("Please enter a valid URL")); | ||
}; |
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
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