Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,31 @@ describe.skipIf(!url)("encrypted integration persistence (PostgreSQL)", () => {
let db: Database;
let admin: pg.Client;
let databaseName: string;
let tearingDown = false;
let unexpectedPoolError: Error | undefined;
beforeAll(async () => {
admin = new pg.Client({ connectionString: url });
await admin.connect();
databaseName = `encrypted_integration_${crypto.randomUUID().replaceAll("-", "")}`;
await admin.query(`CREATE DATABASE ${databaseName}`);
const databaseUrl = new URL(url!); databaseUrl.pathname = `/${databaseName}`;
db = new Database({ connectionString: databaseUrl.toString() });
db.pool.on("error", error => {
if (tearingDown && (error as NodeJS.ErrnoException).code === "57P01") return;
unexpectedPoolError = error;
});
const migrations = new URL("../migrations/", import.meta.url);
for (const file of (await readdir(migrations)).filter(file => /^\d+.*\.sql$/.test(file)).sort()) await db.pool.query(await readFile(new URL(file, migrations), "utf8"));
const migration = await db.pool.query("SELECT to_regclass('app.integration_collections') AS collection, to_regclass('app.integration_changes') AS changes");
expect(migration.rows[0]).toEqual({ collection: "app.integration_collections", changes: "app.integration_changes" });
}, 30_000);
afterAll(async () => { await db?.close(); await admin?.query(`DROP DATABASE IF EXISTS ${databaseName} WITH (FORCE)`); await admin?.end(); });
afterAll(async () => {
await db?.close();
tearingDown = true;
await admin?.query(`DROP DATABASE IF EXISTS ${databaseName} WITH (FORCE)`);
await admin?.end();
if (unexpectedPoolError) throw unexpectedPoolError;
});

async function freshRepository() {
const tenantId = crypto.randomUUID();
Expand Down
9 changes: 4 additions & 5 deletions packages/api/test/static-slice.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,22 @@ describe.skipIf(!url)("compiled React + actual Worker API + PostgreSQL", () => {
return route.fulfill({ status: response.status, headers, body: Buffer.from(await response.arrayBuffer()) });
});
const page = await context.newPage(); page.setDefaultTimeout(10000);
await page.goto(`https://factorize.test/jobs/${job.id}/edit`);
await page.waitForURL(`**/jobs/${job.id}/settings`);
await page.goto(`https://factorize.test/jobs/${job.id}/settings/context`);
await page.getByLabel("Prompt template", { exact: true }).fill("My edited prompt");
await browserWriteRequest;
await service.updateJob(job.id, { name: "Concurrent name", slug: job.slug, promptTemplate: job.promptTemplate, executionConfigId: job.executionConfigId, concurrencyLimit: 1, triggers: [{ id: job.triggers[0].id, slug: job.triggers[0].slug, kind: "manual", enabled: true, config: {} }], expectedUpdatedAt: job.updatedAt });
releaseBrowserWrite();
await page.getByRole("button", { name: "Reconcile my changes" }).waitFor();
await page.getByRole("button", { name: "Reconcile my changes" }).click();
expect(await page.getByLabel("Name", { exact: true }).inputValue()).toBe("Concurrent name");
await page.getByRole("status").filter({ hasText: "Job settings saved." }).waitFor();
expect(new URL(page.url()).pathname).toBe(`/jobs/${job.id}/settings`);
expect(new URL(page.url()).pathname).toBe(`/jobs/${job.id}/settings/context`);
const saved = await service.getJob(job.id); expect(saved.name).toBe("Concurrent name"); expect(saved.promptTemplate).toBe("My edited prompt"); expect(saved.triggers[0].id).toBe(job.triggers[0].id);
const row = (await f.db.pool.query("SELECT encrypted_prompt_template FROM app.jobs WHERE tenant_id=$1 AND id=$2", [f.tenantId, job.id])).rows[0]; expect(await decrypt(row.encrypted_prompt_template, f.env.CREDENTIAL_ENCRYPTION_KEY)).toBe("My edited prompt");
await page.reload();
await page.getByLabel("Prompt template", { exact: true }).waitFor();
expect(await page.getByLabel("Name", { exact: true }).inputValue()).toBe("Concurrent name");
expect(await page.getByLabel("Prompt template", { exact: true }).inputValue()).toBe("My edited prompt");
await page.goto(`https://factorize.test/jobs/${job.id}/settings/general`);
expect(await page.getByLabel("Name", { exact: true }).inputValue()).toBe("Concurrent name");
await page.goto("https://factorize.test/settings/api-keys"); await page.getByRole("button", { name: "Create API Key" }).click(); await page.waitForURL("**/settings/api-keys/new"); await page.getByLabel("Key name").fill("Real key"); await page.getByRole("button", { name: "Create key" }).click(); await page.getByText("Copy this key now. It will only be displayed once.", { exact: true }).waitFor();
await page.getByRole("button", { name: "Dismiss key" }).click(); await page.reload(); await page.getByText("Real key", { exact: true }).waitFor();
page.once("dialog", dialog => dialog.accept()); await page.getByRole("button", { name: "Revoke key" }).click(); await page.getByText("Revoked", { exact: true }).waitFor();
Expand Down
Loading
Loading