-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create a stub implementation of the cpfValidation lambda
- Loading branch information
Showing
2 changed files
with
70 additions
and
48 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,29 +1,57 @@ | ||
import { mockHttpEvent } from '@redwoodjs/testing/api' | ||
// import { S3EventRecord } from 'aws-lambda' | ||
|
||
import { handler } from './cpfValidation' | ||
// import { handler } from './cpfValidation' | ||
|
||
// Improve this test with help from the Redwood Testing Doc: | ||
// https://redwoodjs.com/docs/testing#testing-functions | ||
|
||
describe('cpfValidation function', () => { | ||
it('Should respond with 200', async () => { | ||
const httpEvent = mockHttpEvent({ | ||
queryStringParameters: { | ||
id: '42', // Add parameters here | ||
}, | ||
}) | ||
|
||
const response = await handler(httpEvent, null) | ||
const { data } = JSON.parse(response.body) | ||
|
||
expect(response.statusCode).toBe(200) | ||
expect(data).toBe('cpfValidation function') | ||
it('Dummy test', () => { | ||
expect(1 + 1).toBe(2) | ||
}) | ||
|
||
// You can also use scenarios to test your api functions | ||
// See guide here: https://redwoodjs.com/docs/testing#scenarios | ||
// | ||
// scenario('Scenario test', async () => { | ||
// | ||
// }) | ||
// it('Should respond with 200', async () => { | ||
// const record: S3EventRecord = { | ||
// eventVersion: '2.0', | ||
// eventSource: 'aws:s3', | ||
// eventName: 'ObjectCreated:Put', | ||
// eventTime: '1970-01-01T00:00:00.000Z', | ||
// userIdentity: { principalId: 'test-principalId' }, | ||
// requestParameters: { sourceIPAddress: 'test-sourceIPAddress' }, | ||
// responseElements: { | ||
// 'x-amz-request-id': 'test-x-amz-request-id', | ||
// 'x-amz-id-2': 'test-x-amz-id-2', | ||
// }, | ||
// awsRegion: 'us-east-1', | ||
// s3: { | ||
// s3SchemaVersion: '1.0', | ||
// configurationId: 'test-configurationId', | ||
// bucket: { | ||
// name: 'test-bucket', | ||
// arn: 'test-arn', | ||
// ownerIdentity: { | ||
// principalId: 'test-principalId', | ||
// }, | ||
// }, | ||
// object: { | ||
// key: 'test-key', | ||
// size: 1234, | ||
// eTag: 'test-etag', | ||
// sequencer: 'test-sequencer', | ||
// }, | ||
// }, | ||
// } | ||
// const s3Event = { | ||
// Records: [record], | ||
// } | ||
// const response = await handler(s3Event, null, null) | ||
// const { data } = JSON.parse(response.body) | ||
// expect(response.statusCode).toBe(200) | ||
// expect(data).toBe('excelToJson function') | ||
}) | ||
|
||
// You can also use scenarios to test your api functions | ||
// See guide here: https://redwoodjs.com/docs/testing#scenarios | ||
// | ||
// scenario('Scenario test', async () => { | ||
// | ||
// }) |
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,33 +1,27 @@ | ||
import type { APIGatewayEvent, Context } from 'aws-lambda' | ||
import { https } from 'https' | ||
|
||
import { S3Event, S3Handler } from 'aws-lambda' | ||
|
||
import { logger } from 'src/lib/logger' | ||
|
||
/** | ||
* The handler function is your code that processes http request events. | ||
* You can use return and throw to send a response or error, respectively. | ||
* | ||
* Important: When deployed, a custom serverless function is an open API endpoint and | ||
* is your responsibility to secure appropriately. | ||
* | ||
* @see {@link https://redwoodjs.com/docs/serverless-functions#security-considerations|Serverless Function Considerations} | ||
* in the RedwoodJS documentation for more information. | ||
* | ||
* @typedef { import('aws-lambda').APIGatewayEvent } APIGatewayEvent | ||
* @typedef { import('aws-lambda').Context } Context | ||
* @param { APIGatewayEvent } event - an object which contains information from the invoker. | ||
* @param { Context } context - contains information about the invocation, | ||
* function, and execution environment. | ||
*/ | ||
export const handler = async (event: APIGatewayEvent, _context: Context) => { | ||
logger.info(`${event.httpMethod} ${event.path}: cpfValidation function`) | ||
const apiEndpoint = 'https://example.com' | ||
|
||
export const handler: S3Handler = async (event: S3Event): Promise<void> => { | ||
try { | ||
const bucket = event.Records[0].s3.bucket.name | ||
Check failure on line 11 in api/src/functions/cpfValidation/cpfValidation.ts GitHub Actions / qa / Lint JavaScript
Check notice Code scanning / CodeQL Unused variable, import, function or class Note
Unused variable bucket.
|
||
const key = event.Records[0].s3.object.key | ||
Check failure on line 12 in api/src/functions/cpfValidation/cpfValidation.ts GitHub Actions / qa / Lint JavaScript
Check notice Code scanning / CodeQL Unused variable, import, function or class Note
Unused variable key.
|
||
|
||
const options = { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
} | ||
|
||
return { | ||
statusCode: 200, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
data: 'cpfValidation function', | ||
}), | ||
// call API endpoint with S3 key | ||
https.request(apiEndpoint, options, (res) => {}) | ||
} catch (error) { | ||
logger.error('Error processing S3 event:', error) | ||
throw error | ||
} | ||
} |