mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
test: Add core entry points to allow easier test setup (#18597)
This commit is contained in:
30
packages/testing/playwright/services/project-api-helper.ts
Normal file
30
packages/testing/playwright/services/project-api-helper.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { nanoid } from 'nanoid';
|
||||
|
||||
import type { ApiHelpers } from './api-helper';
|
||||
import { TestError } from '../Types';
|
||||
|
||||
export class ProjectApiHelper {
|
||||
constructor(private api: ApiHelpers) {}
|
||||
|
||||
/**
|
||||
* Create a new project with a unique name
|
||||
* @param projectName Optional base name for the project. If not provided, generates a default name.
|
||||
* @returns The created project data
|
||||
*/
|
||||
async createProject(projectName?: string) {
|
||||
const uniqueName = projectName ? `${projectName} (${nanoid(8)})` : `Test Project ${nanoid(8)}`;
|
||||
|
||||
const response = await this.api.request.post('/rest/projects', {
|
||||
data: {
|
||||
name: uniqueName,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok()) {
|
||||
throw new TestError(`Failed to create project: ${await response.text()}`);
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
return result.data ?? result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user