- 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.
81 lines
2.3 KiB
TypeScript
81 lines
2.3 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
E2E_API_BASE_PATH,
|
|
E2E_BACKEND_PORT,
|
|
E2E_DATABASE_PREFIX,
|
|
E2E_FRONTEND_URL,
|
|
assertOfficialE2EEnvironment,
|
|
assertOfficialE2EExecution,
|
|
resolveE2EExecutionMode,
|
|
} from "./e2e-contract.ts";
|
|
|
|
const officialEnvironment = {
|
|
NODE_ENV: "test",
|
|
DB_NAME: `${E2E_DATABASE_PREFIX}test`,
|
|
DB_SYNC_MODE: "none",
|
|
PORT: E2E_BACKEND_PORT,
|
|
API_BASE_PATH: E2E_API_BASE_PATH,
|
|
FRONTEND_URL: E2E_FRONTEND_URL,
|
|
};
|
|
|
|
test("el contrato oficial acepta la configuración E2E completa", () => {
|
|
assert.doesNotThrow(() => assertOfficialE2EEnvironment(officialEnvironment));
|
|
assert.doesNotThrow(() => assertOfficialE2EExecution(officialEnvironment));
|
|
});
|
|
|
|
test("el contrato oficial rechaza una base de datos no E2E", () => {
|
|
assert.throws(
|
|
() => assertOfficialE2EEnvironment({ ...officialEnvironment, DB_NAME: "factuges_erp" }),
|
|
/DB_NAME with prefix/
|
|
);
|
|
});
|
|
|
|
test("el contrato oficial rechaza un NODE_ENV distinto de test", () => {
|
|
assert.throws(
|
|
() => assertOfficialE2EEnvironment({ ...officialEnvironment, NODE_ENV: "development" }),
|
|
/NODE_ENV=test/
|
|
);
|
|
});
|
|
|
|
test("el contrato oficial rechaza sync o puerto distintos del contrato", () => {
|
|
assert.throws(
|
|
() => assertOfficialE2EEnvironment({ ...officialEnvironment, DB_SYNC_MODE: "force" }),
|
|
/DB_SYNC_MODE=none/
|
|
);
|
|
assert.throws(
|
|
() => assertOfficialE2EEnvironment({ ...officialEnvironment, PORT: "3000" }),
|
|
/PORT=3002/
|
|
);
|
|
});
|
|
|
|
test("el contrato oficial rechaza E2E_BASE_URL heredada", () => {
|
|
assert.throws(
|
|
() =>
|
|
assertOfficialE2EExecution({ ...officialEnvironment, E2E_BASE_URL: "https://example.test" }),
|
|
/does not accept E2E_BASE_URL/
|
|
);
|
|
});
|
|
|
|
test("el contrato oficial rechaza el modo externo heredado", () => {
|
|
assert.throws(
|
|
() => assertOfficialE2EExecution({ ...officialEnvironment, E2E_EXECUTION_MODE: "external" }),
|
|
/does not accept E2E_EXECUTION_MODE/
|
|
);
|
|
});
|
|
|
|
test("el modo externo requiere una URL absoluta y explícita", () => {
|
|
assert.throws(
|
|
() => resolveE2EExecutionMode({ E2E_EXECUTION_MODE: "external" }),
|
|
/requires E2E_BASE_URL/
|
|
);
|
|
assert.equal(
|
|
resolveE2EExecutionMode({
|
|
E2E_EXECUTION_MODE: "external",
|
|
E2E_BASE_URL: "https://e2e.example.test",
|
|
}),
|
|
"external"
|
|
);
|
|
});
|