-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- small refactor improevements - added tests references: #3
- Loading branch information
1 parent
999376e
commit 79640b3
Showing
13 changed files
with
114 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pnpm-lock.yaml | ||
pnpm-lock.yaml | ||
.sst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { createEventBuilder, ZodValidator } from 'sst/node/event-bus' | ||
|
||
export const event = createEventBuilder({ | ||
// @ts-expect-error | ||
// @ts-ignore | ||
bus: 'bus', | ||
validator: ZodValidator, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Logger } from '@funcy/core/src/types' | ||
import { vi } from 'vitest' | ||
|
||
export const logger = (): Logger => ({ | ||
debug: vi.fn(), | ||
info: vi.fn(), | ||
warn: vi.fn(), | ||
error: vi.fn(), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { describe, it, expect, vi } from 'vitest' | ||
import { api, res } from '../' | ||
import * as events from './data/api-proxy-events' | ||
import { ctx } from './data/lambda-context' | ||
import { logger } from './mocks/logger.mock' | ||
|
||
describe('pipeline', () => { | ||
it('should enable cloudwatch metrics if specified', () => { | ||
const event: any = { ...events.payloadV2 } | ||
const fn = api({ | ||
monitoring: { | ||
cloudWatchMetrics: { | ||
namespace: 'my-namespace', | ||
}, | ||
}, | ||
handler: vi.fn<any>(({ context }) => { | ||
expect(context.metrics).toBeDefined() | ||
return res.ok() | ||
}), | ||
}) | ||
|
||
fn(event, ctx()) | ||
}) | ||
|
||
it('should enable full input/output logging if debug mode', async () => { | ||
const event: any = { ...events.payloadV2 } | ||
const log = logger() | ||
const fn = api({ | ||
monitoring: { | ||
logger: () => log, | ||
logLevel: 'debug', | ||
}, | ||
handler: () => res.ok(), | ||
}) | ||
|
||
await fn(event, ctx()) | ||
expect(log.debug).toHaveBeenCalled() | ||
}) | ||
|
||
it('should add extra middleware to the pipeline if specified', async () => { | ||
const event: any = { ...events.payloadV2 } | ||
const middleware = { before: vi.fn() } | ||
const fn = api({ | ||
function: { | ||
middleware: [middleware], | ||
}, | ||
handler: () => res.ok(), | ||
}) | ||
|
||
await fn(event, ctx()) | ||
expect(middleware.before).toHaveBeenCalled() | ||
}) | ||
|
||
it('should enable CORS middleware if specified', async () => { | ||
const event: any = { ...events.payloadV2 } | ||
const disabled = api({ | ||
handler: () => res.ok(), | ||
}) | ||
|
||
const r1 = await disabled(event, ctx()) | ||
expect(r1.headers?.['Access-Control-Allow-Origin']).toBeUndefined() | ||
|
||
const enabled = api({ | ||
http: { cors: { origin: 'web.mysite.com' } }, | ||
handler: () => res.ok(), | ||
}) | ||
|
||
const r2 = await enabled(event, ctx()) | ||
expect(r2.headers?.['Access-Control-Allow-Origin']).toBe('web.mysite.com') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters