test(playwright): additional dataset list playwright tests (#36684)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Joe Li
2026-02-05 16:42:07 -08:00
committed by GitHub
parent ef4f7afa90
commit 5040db859c
30 changed files with 2828 additions and 125 deletions

View File

@@ -20,9 +20,13 @@
import { Page, APIResponse } from '@playwright/test';
import rison from 'rison';
import { apiGet, apiPost, apiDelete, ApiRequestOptions } from './requests';
import { getDatabaseByName } from './database';
export const ENDPOINTS = {
DATASET: 'api/v1/dataset/',
DATASET_EXPORT: 'api/v1/dataset/export/',
DATASET_DUPLICATE: 'api/v1/dataset/duplicate',
DATASET_IMPORT: 'api/v1/dataset/import/',
} as const;
/**
@@ -37,12 +41,12 @@ export interface DatasetCreatePayload {
}
/**
* TypeScript interface for virtual dataset creation API payload
* Virtual datasets are SQL-based and support the Duplicate action in UI
* TypeScript interface for virtual dataset creation API payload.
* Virtual datasets are defined by SQL queries rather than physical tables.
*/
export interface VirtualDatasetCreatePayload {
database: number;
schema: string;
schema: string | null;
table_name: string;
sql: string;
owners?: number[];
@@ -55,8 +59,8 @@ export interface VirtualDatasetCreatePayload {
export interface DatasetResult {
id: number;
table_name: string;
sql?: string;
schema?: string;
sql?: string | null;
schema?: string | null;
database: {
id: number;
database_name: string;
@@ -79,11 +83,11 @@ export async function apiPostDataset(
}
/**
* POST request to create a virtual (SQL-based) dataset
* Virtual datasets support the Duplicate action in the UI
* POST request to create a virtual dataset with SQL.
* Use expectStatusOneOf() on the response and handle both result.id and id shapes.
* @param page - Playwright page instance (provides authentication context)
* @param requestBody - Virtual dataset config (database, schema, table_name, sql)
* @returns API response from dataset creation
* @param requestBody - Virtual dataset configuration (database, schema, table_name, sql)
* @returns API response from virtual dataset creation
*/
export async function apiPostVirtualDataset(
page: Page,
@@ -96,16 +100,27 @@ export async function apiPostVirtualDataset(
* Creates a simple virtual dataset for testing purposes
* @param page - Playwright page instance
* @param name - Name for the virtual dataset
* @param databaseId - ID of the database to use (defaults to 1 for examples db)
* @param databaseId - ID of the database to use (looks up 'examples' DB if not provided)
* @returns The created dataset ID, or null on failure
*/
export async function createTestVirtualDataset(
page: Page,
name: string,
databaseId = 1,
databaseId?: number,
): Promise<number | null> {
// Look up examples database if no ID provided
let dbId = databaseId;
if (dbId === undefined) {
const examplesDb = await getDatabaseByName(page, 'examples');
if (!examplesDb?.id) {
console.warn('Failed to find examples database');
return null;
}
dbId = examplesDb.id;
}
const response = await apiPostVirtualDataset(page, {
database: databaseId,
database: dbId,
schema: '',
table_name: name,
sql: "SELECT 1 as id, 'test' as name",
@@ -118,7 +133,8 @@ export async function createTestVirtualDataset(
}
const body = await response.json();
return body.id ?? null;
// Handle both response shapes: { id } or { result: { id } }
return body.result?.id ?? body.id ?? null;
}
/**
@@ -186,3 +202,30 @@ export async function apiDeleteDataset(
): Promise<APIResponse> {
return apiDelete(page, `${ENDPOINTS.DATASET}${datasetId}`, options);
}
/**
* Duplicate a dataset via the API
* @param page - Playwright page instance (provides authentication context)
* @param datasetId - ID of the dataset to duplicate
* @param newName - Name for the duplicated dataset
* @returns Object containing the new dataset's ID (use apiGetDataset for full details)
*/
export async function duplicateDataset(
page: Page,
datasetId: number,
newName: string,
): Promise<{ id: number }> {
const response = await apiPost(page, `${ENDPOINTS.DATASET}duplicate`, {
base_model_id: datasetId,
table_name: newName,
});
const body = await response.json();
// Normalize: API may return id at top level or inside result
const resolvedId = body.result?.id ?? body.id;
if (!resolvedId) {
throw new Error(
`Duplicate dataset API returned no id. Response: ${JSON.stringify(body)}`,
);
}
return { id: resolvedId };
}