- Add E2ESchemaDatabaseConfig interface for database configuration validation. - Implement assertE2ESchemaDatabaseConfig function to enforce schema requirements. - Create prepareE2ESchema function to handle schema preparation and initialization. - Develop E2E lifecycle management functions to provision, prepare, and run tests. - Introduce Docker Compose setup for E2E database environment. - Add Playwright configuration for E2E testing. - Implement various test cases to validate E2E schema preparation and lifecycle. - Create utility functions for environment variable management and database assertions. - Establish smoke tests to verify initial data setup and integrity.
94 lines
3.1 KiB
TypeScript
94 lines
3.1 KiB
TypeScript
import assert from "node:assert/strict";
|
|
|
|
import mysql from "../../../apps/server/node_modules/mysql2/promise.js";
|
|
import { logger } from "../../../apps/server/src/lib/logger";
|
|
import { bootstrapE2EData } from "../../../apps/server/src/testing/e2e/bootstrap-e2e-data";
|
|
import { prepareE2ESchema } from "../../../apps/server/src/testing/e2e/prepare-e2e-schema";
|
|
import { BcryptPasswordHasher } from "../../../modules/identity/src/api/infrastructure/index.js";
|
|
|
|
import { createE2EDatabaseEnvironment } from "./e2e-database-environment";
|
|
import { toE2ESchemaDatabaseConfig } from "./e2e-schema-database-config";
|
|
|
|
async function run(): Promise<void> {
|
|
const email = required("E2E_USER_EMAIL");
|
|
const password = required("E2E_USER_PASSWORD");
|
|
const environment = await createE2EDatabaseEnvironment();
|
|
try {
|
|
const databaseConfig = toE2ESchemaDatabaseConfig(environment);
|
|
await prepareE2ESchema(databaseConfig);
|
|
const result = await bootstrapE2EData(
|
|
databaseConfig,
|
|
{
|
|
executionId: environment.executionId,
|
|
email,
|
|
password,
|
|
companyName: "FactuGes E2E",
|
|
companySlug: "factuges-e2e",
|
|
},
|
|
{ logger }
|
|
);
|
|
const connection = await mysql.createConnection({
|
|
host: environment.host,
|
|
port: environment.port,
|
|
user: environment.username,
|
|
password: environment.password,
|
|
database: environment.databaseName,
|
|
});
|
|
try {
|
|
const [accounts] = await connection.query<any[]>(
|
|
"SELECT id, password_hash FROM identity_accounts"
|
|
);
|
|
const [companies] = await connection.query<any[]>(
|
|
"SELECT id FROM companies WHERE slug = 'factuges-e2e'"
|
|
);
|
|
assert.equal(accounts.length, 1);
|
|
assert.equal(companies.length, 1);
|
|
assert.equal(accounts[0].id, result.accountId);
|
|
assert.equal(companies[0].id, result.companyId);
|
|
assert.notEqual(accounts[0].password_hash, password);
|
|
const verified = await new BcryptPasswordHasher({ rounds: 10 }).verify({
|
|
plainPassword: password,
|
|
passwordHash: { toPrimitive: () => accounts[0].password_hash } as never,
|
|
});
|
|
assert.equal(verified.data, true);
|
|
for (const table of [
|
|
"identity_company_memberships",
|
|
"identity_roles",
|
|
"identity_company_membership_roles",
|
|
"initial_onboardings",
|
|
]) {
|
|
const [rows] = await connection.query<any[]>(`SELECT COUNT(*) AS count FROM ${table}`);
|
|
assert.equal(rows[0].count, 1);
|
|
}
|
|
for (const table of [
|
|
"customers",
|
|
"suppliers",
|
|
"proformas",
|
|
"issued_invoices",
|
|
"recurring_proformas",
|
|
"document_series",
|
|
"tax_definitions",
|
|
"tax_regimes",
|
|
"payment_methods",
|
|
"payment_terms",
|
|
]) {
|
|
const [rows] = await connection.query<any[]>(`SELECT COUNT(*) AS count FROM ${table}`);
|
|
assert.equal(rows[0].count, 0);
|
|
}
|
|
console.log("P4.2a smoke passed");
|
|
} finally {
|
|
await connection.end();
|
|
}
|
|
} finally {
|
|
await environment.destroy();
|
|
}
|
|
}
|
|
run().catch((error: unknown) => { console.error(error); process.exitCode = 1; });
|
|
function required(name: "E2E_USER_EMAIL" | "E2E_USER_PASSWORD"): string {
|
|
const value = process.env[name];
|
|
if (!value) {
|
|
throw new Error(`Missing ${name}`);
|
|
}
|
|
return value;
|
|
}
|