This commit is contained in:
Naidu_4444
2025-07-01 14:47:32 +00:00
parent 36ad5f9442
commit c723e0169e
2 changed files with 27 additions and 8 deletions

View File

@@ -67,15 +67,33 @@ describe("tag lib", () => {
});
describe("updateTagName", () => {
test("updates tag name and revalidates cache", async () => {
test("returns ok on successful update", async () => {
vi.mocked(prisma.tag.update).mockResolvedValueOnce(baseTag);
const result = await updateTagName(baseTag.id, "Tag1");
expect(result).toEqual(baseTag);
expect(prisma.tag.update).toHaveBeenCalledWith({ where: { id: baseTag.id }, data: { name: "Tag1" } });
expect(result.ok).toBe(true);
if (result.ok) {
expect(result.data).toEqual(baseTag);
}
expect(prisma.tag.update).toHaveBeenCalledWith({
where: { id: baseTag.id },
data: { name: "Tag1" },
});
});
test("throws error on prisma error", async () => {
test("returns internal_server_error on unknown error", async () => {
vi.mocked(prisma.tag.update).mockRejectedValueOnce(new Error("fail"));
await expect(updateTagName(baseTag.id, "Tag1")).rejects.toThrow("fail");
const result = await updateTagName(baseTag.id, "Tag1");
expect(result.ok).toBe(false);
if (!result.ok) {
expect(result.error).toStrictEqual({
type: "internal_server_error",
details: [{ field: "tag", issue: "fail" }],
});
}
});
});

View File

@@ -72,10 +72,11 @@ export const SingleTag: React.FC<SingleTagProps> = ({
defaultValue={tagName}
onBlur={(e) => {
updateTagNameAction({ tagId, name: e.target.value.trim() }).then((res) => {
if (res?.data.ok) {
const result = res?.data;
if (result?.ok) {
setUpdateTagError(false);
toast.success(t("environments.project.tags.tag_updated"));
} else if (res?.data.error?.type === "conflict") {
} else if (result?.error?.type === "conflict") {
toast.error(t("environments.project.tags.tag_already_exists"), {
duration: 2000,
icon: <AlertCircleIcon className="h-5 w-5 text-orange-500" />,
@@ -83,7 +84,7 @@ export const SingleTag: React.FC<SingleTagProps> = ({
setUpdateTagError(true);
} else {
toast.error(
getFormattedErrorMessage(res) ?? t("common.something_went_wrong_please_try_again"),
getFormattedErrorMessage(result) ?? t("common.something_went_wrong_please_try_again"),
{ duration: 2000 }
);
setUpdateTagError(true);