Skip to content

Commit

Permalink
COM-20 Added test details
Browse files Browse the repository at this point in the history
  • Loading branch information
7yntax committed Feb 24, 2025
1 parent 9dbf40b commit da2427e
Show file tree
Hide file tree
Showing 9 changed files with 488 additions and 290 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
"use server";

import { db } from "@bubba/db";
import { authActionClient } from "@/actions/safe-action";
import { auth } from "@/auth";
import {
appErrors,
type CloudTestResult,
type ActionResponse
} from "./types";

export async function getCloudTestDetails(input: { testId: string }): Promise<ActionResponse<CloudTestResult>> {
const { testId } = input;

const session = await auth();
const organizationId = session?.user.organizationId;

if (!organizationId) {
throw new Error("Organization ID not found");
}

try {
const cloudTest = await db.cloudTest.findUnique({
where: {
id: testId,
organizationId,
},
select: {
id: true,
title: true,
description: true,
provider: true,
status: true,
config: true,
authConfig: true,
createdAt: true,
updatedAt: true,
createdBy: {
select: {
id: true,
name: true,
email: true,
},
},
updatedBy: {
select: {
id: true,
name: true,
email: true,
},
},
runs: {
select: {
id: true,
status: true,
result: true,
resultDetails: true,
startedAt: true,
completedAt: true,
executedBy: {
select: {
id: true,
name: true,
email: true,
},
},
createdAt: true,
updatedAt: true,
},
orderBy: {
createdAt: 'desc',
},
take: 10, // Limit to most recent 10 runs
},
},
});

if (!cloudTest) {
return {
success: false,
error: appErrors.NOT_FOUND,
};
}

return {
success: true,
data: cloudTest,
};
} catch (error) {
console.error("Error fetching cloud test details:", error);
return {
success: false,
error: appErrors.UNEXPECTED_ERROR,
};
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { z } from "zod";

// Define the app errors
export const appErrors = {
NOT_FOUND: { message: "Cloud test not found" },
UNEXPECTED_ERROR: { message: "An unexpected error occurred" }
};

export type AppError = typeof appErrors[keyof typeof appErrors];

// Define the input schema
export const cloudTestDetailsInputSchema = z.object({
testId: z.string()
});

export type CloudTestResult = {
id: string;
title: string;
description: string | null;
provider: string;
status: string;
config: any;
authConfig: any;
createdAt: Date;
updatedAt: Date;
createdBy: {
id: string;
name: string | null;
email: string | null;
};
updatedBy: {
id: string;
name: string | null;
email: string | null;
};
runs: Array<{
id: string;
status: string;
result: string | null;
resultDetails: any | null;
startedAt: Date | null;
completedAt: Date | null;
executedBy: {
id: string;
name: string | null;
email: string | null;
};
createdAt: Date;
updatedAt: Date;
}>;
};

// Type-safe action response
export type ActionResponse<T> = Promise<
{ success: true; data: T } | { success: false; error: AppError }
>;
Loading

0 comments on commit da2427e

Please sign in to comment.