Skip to content

Commit

Permalink
Refactor to use a more meaningful name
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwadeson committed Mar 15, 2024
1 parent 67f7fb5 commit b48feec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions typescript/src/feast/pubsub/pubsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import { HTTPResponses } from "../../models/apiGatewayHttp";

export async function handler(request: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> {
console.log(`[34ef7aa3] ${JSON.stringify(request)}`)
return processEvent()(request)
const handler = buildHandler()
return handler(request)
}

export function processEvent(
export function buildHandler(
sendMessageToSqs: (queueUrl: string, message: AppleSubscriptionReference) => Promise<PromiseResult<Sqs.SendMessageResult, AWSError>> = sendToSqs
): (request: APIGatewayProxyEvent) => Promise<APIGatewayProxyResult> {
return async (request: APIGatewayProxyEvent) => {
Expand Down
6 changes: 4 additions & 2 deletions typescript/tests/feast/pubsub/pubsub.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { StatusUpdateNotification } from "../../../src/pubsub/apple";
import Mock = jest.Mock;
import { APIGatewayProxyEvent } from "aws-lambda";
import { processEvent } from "../../../src/feast/pubsub/pubsub";
import { buildHandler } from "../../../src/feast/pubsub/pubsub";
import { HTTPResponses } from "../../../src/models/apiGatewayHttp";

describe("The Feast Apple pubsub", () => {
Expand Down Expand Up @@ -80,7 +80,9 @@ describe("The Feast Apple pubsub", () => {

const expectedSubscriptionReferenceInSqs = {receipt: "TEST"};

return processEvent(mockSqsFunction)(input).then(result => {
const handler = buildHandler(mockSqsFunction)

return handler(input).then(result => {
expect(result).toStrictEqual(HTTPResponses.OK);
expect(mockSqsFunction.mock.calls.length).toEqual(1);
expect(mockSqsFunction.mock.calls[0][1]).toStrictEqual(expectedSubscriptionReferenceInSqs);
Expand Down

0 comments on commit b48feec

Please sign in to comment.