Skip to content

Commit

Permalink
feat, test: allow route in metadata to be optional (#518)
Browse files Browse the repository at this point in the history
feat: allow route in metadata to be optional
  • Loading branch information
alanhwu authored Feb 4, 2025
1 parent ee23d31 commit 2d40b07
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/handlers/get-unimind/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class GetUnimindHandler extends APIGLambdaHandler<ContainerInjected, Requ
const { logOnly, ...quoteMetadataFields } = requestQueryParams
const quoteMetadata = {
...quoteMetadataFields,
route: JSON.parse(requestQueryParams.route)
route: requestQueryParams.route ? JSON.parse(requestQueryParams.route) : undefined
}
// For requests that don't expect params, we only save the quote metadata and return
if (logOnly) {
Expand Down
2 changes: 1 addition & 1 deletion lib/handlers/get-unimind/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const unimindQueryParamsSchema = Joi.object({
referencePrice: Joi.string().required(),
priceImpact: Joi.number().required(),
route: Joi.string()
.required()
.optional()
.custom((value, helpers) => {
try {
const parsed = JSON.parse(value)
Expand Down
4 changes: 2 additions & 2 deletions lib/repositories/quote-metadata-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export class DynamoQuoteMetadataRepository implements QuoteMetadataRepository {
quoteId: { partitionKey: true, type: DYNAMODB_TYPES.STRING },
referencePrice: { type: DYNAMODB_TYPES.STRING, required: true },
priceImpact: { type: DYNAMODB_TYPES.NUMBER, required: true },
route: {type: DYNAMODB_TYPES.MAP, required: true},
pair: {type: DYNAMODB_TYPES.STRING, required: true}
pair: {type: DYNAMODB_TYPES.STRING, required: true},
route: {type: DYNAMODB_TYPES.MAP, required: false}
},
table,
} as const)
Expand Down
26 changes: 24 additions & 2 deletions test/unit/handlers/get-unimind/get-unimind.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,5 +409,27 @@ describe('Testing get unimind handler', () => {
expect(response.statusCode).toBe(200)
expect(mockQuoteMetadataRepo.put).toHaveBeenCalledTimes(1)
expect(mockUnimindParametersRepo.getByPair).toHaveBeenCalledTimes(1)
})
})
})

it('Allow route to be optional', async () => {
const quoteMetadata = {
quoteId: 'test-quote-id',
referencePrice: '4221.21',
priceImpact: 0.01,
pair: 'ETH-USDC',
// missing route
}

const response = await getUnimindHandler.handler(
{
queryStringParameters: quoteMetadata,
requestContext: { requestId: 'test-request-id' }
} as any,
EVENT_CONTEXT
)

expect(response.statusCode).toBe(200)
expect(mockQuoteMetadataRepo.put).toHaveBeenCalledTimes(1)
expect(mockUnimindParametersRepo.getByPair).toHaveBeenCalledTimes(1)
})
})

0 comments on commit 2d40b07

Please sign in to comment.