73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import express from 'express';
|
|
import test from 'node:test';
|
|
|
|
import { runtimeContextMiddleware } from '../../src/middlewares/runtime-context.ts';
|
|
import runtimeContextRoutes from '../../src/routes/runtime-context.ts';
|
|
import { startTestServer } from '../http-test-utils.ts';
|
|
|
|
function buildRuntimeContextApp() {
|
|
const app = express();
|
|
app.use(runtimeContextMiddleware);
|
|
app.use('/api/runtime-context', runtimeContextRoutes);
|
|
return app;
|
|
}
|
|
|
|
void test('GET /api/runtime-context returns default admin runtime context', async () => {
|
|
const server = await startTestServer(buildRuntimeContextApp());
|
|
try {
|
|
const response = await fetch(`${server.baseUrl}/api/runtime-context`);
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.deepEqual(await response.json(), {
|
|
mode: 'admin',
|
|
projectSlug: null,
|
|
});
|
|
} finally {
|
|
await server.close();
|
|
}
|
|
});
|
|
|
|
void test('GET /api/runtime-context exposes valid runtime headers over HTTP', async () => {
|
|
const server = await startTestServer(buildRuntimeContextApp());
|
|
try {
|
|
const response = await fetch(`${server.baseUrl}/api/runtime-context`, {
|
|
headers: {
|
|
'x-runtime-environment': 'production',
|
|
'x-runtime-project-slug': 'museum-tour',
|
|
},
|
|
});
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.deepEqual(await response.json(), {
|
|
mode: 'admin',
|
|
projectSlug: null,
|
|
headerEnvironment: 'production',
|
|
headerProjectSlug: 'museum-tour',
|
|
});
|
|
} finally {
|
|
await server.close();
|
|
}
|
|
});
|
|
|
|
void test('GET /api/runtime-context ignores unsupported runtime environment headers', async () => {
|
|
const server = await startTestServer(buildRuntimeContextApp());
|
|
try {
|
|
const response = await fetch(`${server.baseUrl}/api/runtime-context`, {
|
|
headers: {
|
|
'x-runtime-environment': 'qa',
|
|
'x-runtime-project-slug': 'museum-tour',
|
|
},
|
|
});
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.deepEqual(await response.json(), {
|
|
mode: 'admin',
|
|
projectSlug: null,
|
|
headerProjectSlug: 'museum-tour',
|
|
});
|
|
} finally {
|
|
await server.close();
|
|
}
|
|
});
|