Skip to content

Commit e84fabe

Browse files
committed
test: align interceptor unit tests with FIX-BATCH-3 changes
Four unit tests asserted against pre-FIX-BATCH-3 behavior. Bringing them in line with the shipped code: 1. logs/__tests__/interceptor.test.ts — error message no longer mentions the internal field name `interceptorFunctionName`. Assert against the new "has no Lambda function" copy that the user actually sees. 2. shared/__tests__/interceptor-mode-check.test.ts — error message no longer leaks `deployed-state.json`. Assert against the new "is not deployed" copy. 3. schema/.../interceptor.test.ts — schema fields are .optional() and defaults are applied at consumption time (not parse time), so a sparse parse leaves them undefined rather than filling them in. 4. operations/deploy/__tests__/preflight.test.ts — the new validateGatewayTargetLambdas() preflight imports getCredentialProvider from aws/account.js. Stub it in the existing vi.mock so existing fixtures (which have no lambda-function-arn targets) keep working.
1 parent 5c49d54 commit e84fabe

4 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/cli/commands/logs/__tests__/interceptor.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe('handleLogsInterceptor', () => {
9393
const r = await handleLogsInterceptor({ name: 'auth' });
9494
expect(r.success).toBe(false);
9595
if (!r.success) {
96-
expect(r.error.message).toMatch(/interceptorFunctionName/);
96+
expect(r.error.message).toMatch(/has no Lambda function/);
9797
expect(r.error.message).toMatch(/agentcore deploy/);
9898
}
9999
});

src/cli/commands/shared/__tests__/interceptor-mode-check.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('lookupInterceptor', () => {
6868

6969
it('throws ResourceNotFoundError when name is missing', async () => {
7070
mockReadDeployedState.mockResolvedValue(deployedState({}));
71-
await expect(lookupInterceptor('nope')).rejects.toThrow(/not found in deployed-state/);
71+
await expect(lookupInterceptor('nope')).rejects.toThrow(/is not deployed/);
7272
});
7373
});
7474

src/cli/operations/deploy/__tests__/preflight.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ vi.mock('../../../cdk/local-cdk-project.js', () => ({
5454

5555
vi.mock('../../../aws/account.js', () => ({
5656
validateAwsCredentials: mockValidateAwsCredentials,
57+
// Stub for validateGatewayTargetLambdas — never reached in these tests because
58+
// none of the fixtures have lambda-function-arn gateway targets.
59+
getCredentialProvider: () => () => Promise.resolve({ accessKeyId: 'x', secretAccessKey: 'x' }),
5760
}));
5861

5962
describe('validateProject', () => {

src/schema/schemas/primitives/__tests__/interceptor.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { InterceptorSchema } from '../interceptor';
66
import { describe, expect, it } from 'vitest';
77

88
describe('InterceptorSchema', () => {
9-
it('accepts a managed entry with required defaults applied', () => {
9+
it('accepts a managed entry with optional fields omitted (defaults applied at consumption time)', () => {
1010
const r = InterceptorSchema.safeParse({
1111
name: 'auth-check',
1212
gatewayName: 'my-gw',
@@ -15,10 +15,14 @@ describe('InterceptorSchema', () => {
1515
});
1616
expect(r.success).toBe(true);
1717
if (r.success) {
18-
// Defaults apply
19-
expect(r.data.passRequestHeaders).toBe(true);
20-
expect(r.data.config.managed?.runtime).toBe('python3.12');
21-
expect(r.data.config.managed?.timeoutSeconds).toBe(30);
18+
// Schema parse keeps user-edited JSON sparse — defaults are NOT injected here.
19+
// Consumers (CDK constructs, primitive add flows) apply defaults via
20+
// `?? INTERCEPTOR_DEFAULTS.X` at use time. See INTERCEPTOR_DEFAULTS in
21+
// schema/schemas/primitives/interceptor.ts.
22+
expect(r.data.passRequestHeaders).toBeUndefined();
23+
expect(r.data.config.managed?.runtime).toBeUndefined();
24+
expect(r.data.config.managed?.timeoutSeconds).toBeUndefined();
25+
expect(r.data.config.managed?.entrypoint).toBeUndefined();
2226
}
2327
});
2428

0 commit comments

Comments
 (0)