feat: scenario option for authorization server test (#227)
This commit is contained in:
parent
38c4852d8c
commit
fa96f3aca1
1 changed files with 216 additions and 3 deletions
|
|
@ -89,3 +89,138 @@ describe('AuthorizationServerMetadataEndpointScenario', () => {
|
|||
expect(check.errorMessage).toContain('code_challenge_methods_supported');
|
||||
});
|
||||
});
|
||||
|
||||
describe('AuthorizationServerOptionsSchema', () => {
|
||||
// Dynamic import to avoid circular dependency issues at module level
|
||||
async function getSchema() {
|
||||
const { AuthorizationServerOptionsSchema } =
|
||||
await import('../../schemas.js');
|
||||
return AuthorizationServerOptionsSchema;
|
||||
}
|
||||
|
||||
it('accepts a valid scenario name', async () => {
|
||||
const schema = await getSchema();
|
||||
const result = schema.safeParse({
|
||||
url: 'https://example.com',
|
||||
scenario: 'authorization-server-metadata-endpoint'
|
||||
});
|
||||
expect(result.success).toBe(true);
|
||||
if (result.success) {
|
||||
expect(result.data.scenario).toBe(
|
||||
'authorization-server-metadata-endpoint'
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it('rejects an unknown scenario name', async () => {
|
||||
const schema = await getSchema();
|
||||
const result = schema.safeParse({
|
||||
url: 'https://example.com',
|
||||
scenario: 'nonexistent-scenario'
|
||||
});
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
|
||||
it('accepts without scenario (optional)', async () => {
|
||||
const schema = await getSchema();
|
||||
const result = schema.safeParse({
|
||||
url: 'https://example.com'
|
||||
});
|
||||
expect(result.success).toBe(true);
|
||||
if (result.success) {
|
||||
expect(result.data.scenario).toBeUndefined();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('printAuthorizationServerResults', () => {
|
||||
async function getPrintFn() {
|
||||
const { printAuthorizationServerResults } =
|
||||
await import('../../runner/authorization-server.js');
|
||||
return printAuthorizationServerResults;
|
||||
}
|
||||
|
||||
const successCheck = {
|
||||
id: 'test-check',
|
||||
name: 'TestCheck',
|
||||
description: 'A test check',
|
||||
status: 'SUCCESS' as const,
|
||||
timestamp: new Date().toISOString()
|
||||
};
|
||||
|
||||
const failureCheck = {
|
||||
id: 'test-check-fail',
|
||||
name: 'TestCheckFail',
|
||||
description: 'A failing check',
|
||||
status: 'FAILURE' as const,
|
||||
timestamp: new Date().toISOString(),
|
||||
errorMessage: 'Something went wrong'
|
||||
};
|
||||
|
||||
it('prints pretty-printed output when verbose is false', async () => {
|
||||
const printFn = await getPrintFn();
|
||||
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
||||
|
||||
const result = printFn([successCheck], 'Test scenario description', false);
|
||||
|
||||
expect(result).toEqual({
|
||||
passed: 1,
|
||||
failed: 0,
|
||||
denominator: 1,
|
||||
warnings: 0
|
||||
});
|
||||
|
||||
// Should print "Checks:" header (pretty format), not raw JSON
|
||||
const allOutput = consoleSpy.mock.calls.map((c) => c[0]).join('\n');
|
||||
expect(allOutput).toContain('Checks:');
|
||||
expect(allOutput).not.toContain('"id"');
|
||||
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
|
||||
it('prints JSON output when verbose is true', async () => {
|
||||
const printFn = await getPrintFn();
|
||||
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
||||
|
||||
const result = printFn([successCheck], 'Test scenario description', true);
|
||||
|
||||
expect(result).toEqual({
|
||||
passed: 1,
|
||||
failed: 0,
|
||||
denominator: 1,
|
||||
warnings: 0
|
||||
});
|
||||
|
||||
// Should print raw JSON, not "Checks:" header
|
||||
const allOutput = consoleSpy.mock.calls.map((c) => c[0]).join('\n');
|
||||
expect(allOutput).toContain('"id"');
|
||||
expect(allOutput).toContain('"test-check"');
|
||||
expect(allOutput).not.toMatch(/^Checks:/m);
|
||||
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
|
||||
it('reports failed checks with error messages', async () => {
|
||||
const printFn = await getPrintFn();
|
||||
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
||||
|
||||
const result = printFn(
|
||||
[successCheck, failureCheck],
|
||||
'Test scenario description',
|
||||
false
|
||||
);
|
||||
|
||||
expect(result).toEqual({
|
||||
passed: 1,
|
||||
failed: 1,
|
||||
denominator: 2,
|
||||
warnings: 0
|
||||
});
|
||||
|
||||
const allOutput = consoleSpy.mock.calls.map((c) => c[0]).join('\n');
|
||||
expect(allOutput).toContain('Failed Checks');
|
||||
expect(allOutput).toContain('Something went wrong');
|
||||
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue