chore: publish clean community baseline
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
const { expect } = require('@playwright/test');
|
||||
|
||||
const ADMIN_EMAIL = process.env.CRANK_E2E_ADMIN_EMAIL || 'owner@crank.local';
|
||||
const ADMIN_PASSWORD = process.env.CRANK_E2E_ADMIN_PASSWORD || 'change-me-admin-password';
|
||||
|
||||
function localized(en, ru) {
|
||||
return new RegExp(`(?:${en}|${ru})`, 'i');
|
||||
}
|
||||
|
||||
async function login(page) {
|
||||
await page.goto('/login');
|
||||
await expect(page.locator('#login-form')).toBeVisible();
|
||||
await page.locator('#email').fill(ADMIN_EMAIL);
|
||||
await page.locator('#password').fill(ADMIN_PASSWORD);
|
||||
await page.locator('.btn-signin').click();
|
||||
await expect(page).toHaveURL(/\/$/);
|
||||
await expect(page.locator('.page-title, .page-heading').first()).toBeVisible();
|
||||
}
|
||||
|
||||
async function browserJson(page, method, urlPath, body, okStatuses = [200]) {
|
||||
const response = await page.evaluate(async ({ method, urlPath, body }) => {
|
||||
const request = {
|
||||
method,
|
||||
credentials: 'same-origin',
|
||||
headers: {},
|
||||
};
|
||||
if (body !== undefined) {
|
||||
request.headers['Content-Type'] = 'application/json';
|
||||
request.body = JSON.stringify(body);
|
||||
}
|
||||
|
||||
const result = await fetch(urlPath, request);
|
||||
const text = await result.text();
|
||||
let json = null;
|
||||
try {
|
||||
json = text ? JSON.parse(text) : null;
|
||||
} catch (_error) {
|
||||
json = null;
|
||||
}
|
||||
|
||||
return {
|
||||
status: result.status,
|
||||
text,
|
||||
json,
|
||||
};
|
||||
}, { method, urlPath, body });
|
||||
|
||||
if (!okStatuses.includes(response.status)) {
|
||||
throw new Error(`HTTP ${response.status} ${urlPath}: ${response.text}`);
|
||||
}
|
||||
|
||||
return response.json;
|
||||
}
|
||||
|
||||
async function getSession(page) {
|
||||
return browserJson(page, 'GET', '/api/auth/session');
|
||||
}
|
||||
|
||||
async function getCurrentWorkspace(page) {
|
||||
const session = await getSession(page);
|
||||
const workspaceId = session.current_workspace_id
|
||||
|| (session.memberships && session.memberships[0] && session.memberships[0].workspace.id);
|
||||
const membership = (session.memberships || []).find((item) => item.workspace.id === workspaceId)
|
||||
|| (session.memberships || [])[0];
|
||||
return membership ? membership.workspace : null;
|
||||
}
|
||||
|
||||
async function createAgent(page, workspaceId, payload) {
|
||||
return browserJson(
|
||||
page,
|
||||
'POST',
|
||||
`/api/admin/workspaces/${encodeURIComponent(workspaceId)}/agents`,
|
||||
payload,
|
||||
);
|
||||
}
|
||||
|
||||
function uniqueName(prefix) {
|
||||
return `${prefix}_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
ADMIN_EMAIL,
|
||||
ADMIN_PASSWORD,
|
||||
browserJson,
|
||||
createAgent,
|
||||
getCurrentWorkspace,
|
||||
getSession,
|
||||
localized,
|
||||
login,
|
||||
uniqueName,
|
||||
};
|
||||
Reference in New Issue
Block a user