Skip to content

Commit

Permalink
fix(util-endpoints) improve evaluateEndpointRule's debug msg smithy-l…
Browse files Browse the repository at this point in the history
  • Loading branch information
necisam committed May 9, 2024
1 parent ce6b1be commit 787abc5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
26 changes: 19 additions & 7 deletions packages/util-endpoints/src/utils/evaluateEndpointRule.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { EvaluateOptions } from "@smithy/types";

import { debugId, toDebugString } from "../debug";
import { ConditionObject, EndpointRuleObject } from "../types";
import { evaluateConditions } from "./evaluateConditions";
import { evaluateEndpointRule } from "./evaluateEndpointRule";
Expand All @@ -11,9 +14,16 @@ jest.mock("./getEndpointHeaders");
jest.mock("./getEndpointProperties");

describe(evaluateEndpointRule.name, () => {
const mockOptions = {
const mockLogger = {
debug: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
};
const mockOptions: EvaluateOptions = {
endpointParams: {},
referenceRecord: {},
logger: mockLogger,
};
const mockConditions: ConditionObject[] = [
{ fn: "fn1", argv: ["arg1"] },
Expand Down Expand Up @@ -65,6 +75,7 @@ describe(evaluateEndpointRule.name, () => {
});
expect(getEndpointHeaders).not.toHaveBeenCalled();
expect(getEndpointProperties).not.toHaveBeenCalled();
expect(mockLogger.debug).nthCalledWith(1, `${debugId} Resolving endpoint from template: ${toDebugString(mockEndpointRule.endpoint)}`)
});

it("with headers and properties", () => {
Expand All @@ -76,15 +87,15 @@ describe(evaluateEndpointRule.name, () => {

(getEndpointHeaders as jest.Mock).mockReturnValue(mockOutputHeaders);
(getEndpointProperties as jest.Mock).mockReturnValue(mockOutputProperties);

const headerEndpoint = {
...mockEndpoint,
headers: mockInputHeaders,
properties: mockInputProperties,
}
const result = evaluateEndpointRule(
{
...mockEndpointRule,
endpoint: {
...mockEndpoint,
headers: mockInputHeaders,
properties: mockInputProperties,
},
endpoint: headerEndpoint,
},
mockOptions
);
Expand All @@ -96,6 +107,7 @@ describe(evaluateEndpointRule.name, () => {
});
expect(getEndpointHeaders).toHaveBeenCalledWith(mockInputHeaders, mockUpdatedOptions);
expect(getEndpointProperties).toHaveBeenCalledWith(mockInputProperties, mockUpdatedOptions);
expect(mockLogger.debug).nthCalledWith(1, `${debugId} Resolving endpoint from template: ${toDebugString(headerEndpoint)}`)
});
});
});
2 changes: 1 addition & 1 deletion packages/util-endpoints/src/utils/evaluateEndpointRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const evaluateEndpointRule = (

const { url, properties, headers } = endpoint;

options.logger?.debug?.(debugId, `Resolving endpoint from template: ${toDebugString(endpoint)}`);
options.logger?.debug?.(`${debugId} Resolving endpoint from template: ${toDebugString(endpoint)}`);

return {
...(headers != undefined && {
Expand Down

0 comments on commit 787abc5

Please sign in to comment.