Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

fix: Updates default http output binding #308

Merged
merged 4 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/services/azureKeyVaultService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Serverless from "serverless";
import { BaseService } from "./baseService";
import { FunctionAppService } from "./functionAppService";
import { KeyVaultManagementClient } from "@azure/arm-keyvault";
import { KeyPermissions, SecretPermissions, Vault } from "@azure/arm-keyvault/esm/models/index";
import { Vault, SecretPermissions } from "@azure/arm-keyvault/esm/models";

/**
* Defines the Azure Key Vault configuration
Expand Down
47 changes: 47 additions & 0 deletions src/shared/binding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,51 @@ describe("Bindings", () => {
BindingUtils.getBindingsMetaData(sls);
expect(sls.cli.log).toBeCalledWith("Parsing Azure Functions Bindings.json...");
});

it("Http output bindings should default to 'res'", () => {
const binding = BindingUtils.getHttpOutBinding();

expect(binding).toMatchObject({
type: "http",
direction: "out",
name: "res"
});
});

it("Gets the http binding with default settings", () => {
const serverless = MockFactory.createTestServerless();
const parsedBindings = BindingUtils.getBindingsMetaData(serverless);
const bindingType = "http";

const bindingTypes = parsedBindings.bindingTypes;
const bindingTypeIndex = bindingTypes.indexOf(bindingType);
const bindingSettings = parsedBindings.bindingSettings[bindingTypeIndex];

const binding = BindingUtils.getBinding(bindingType, bindingSettings, {});

expect(binding).toMatchObject({
type: "http",
direction: "out",
name: "res",
});
});

it("Gets the http binding with custom name", () => {
const serverless = MockFactory.createTestServerless();
const parsedBindings = BindingUtils.getBindingsMetaData(serverless);
const bindingType = "http";
const userSettings = { name: "custom" };

const bindingTypes = parsedBindings.bindingTypes;
const bindingTypeIndex = bindingTypes.indexOf(bindingType);
const bindingSettings = parsedBindings.bindingSettings[bindingTypeIndex];

const binding = BindingUtils.getBinding(bindingType, bindingSettings, userSettings);

expect(binding).toMatchObject({
type: "http",
direction: "out",
name: userSettings.name,
});
});
});
7 changes: 2 additions & 5 deletions src/shared/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,12 @@ export class BindingUtils {
return bindingUserSettingsMetaData;
}

public static getHttpOutBinding(bindingUserSettings) {
public static getHttpOutBinding() {
const binding = {};

binding[constants.type] = "http";
binding[constants.direction] = constants.outDirection;
binding[constants.name] = "$return";
if (bindingUserSettings[constants.webHookType]) {
binding[constants.name] = "res";
}
binding[constants.name] = "res";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we always want it to be res, or just default to it and still have the option of choosing the $return?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need the option of choosing $return instead of res.


return binding;
}
Expand Down
2 changes: 1 addition & 1 deletion src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class Utils {
}

if (bindingType === constants.httpTrigger) {
bindings.push(BindingUtils.getHttpOutBinding(bindingUserSettings));
bindings.push(BindingUtils.getHttpOutBinding());
}

functionsJson.bindings = bindings;
Expand Down