[go: up one dir, main page]

Skip to content

Commit

Permalink
Allow optional extension params to be omitted (firebase#3126)
Browse files Browse the repository at this point in the history
  • Loading branch information
oxc committed Feb 11, 2021
1 parent 417879f commit 6b22276
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Fixes issue where proxied requests to dynamic content through the Hosting emulator would return unexpected `location` headers. (#3097)
- Fixes issue where optional extension parameters could not be omitted (#3126)
2 changes: 1 addition & 1 deletion src/extensions/extensionsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export function populateDefaultParams(paramVars: any, paramSpec: any): any {
if (!paramVars[env.param]) {
if (env.default) {
newParams[env.param] = env.default;
} else {
} else if (env.required) {
throw new FirebaseError(
`${env.param} has not been set in the given params file` +
" and there is no default available. Please set this variable before installing again."
Expand Down
29 changes: 24 additions & 5 deletions src/test/extensions/paramHelper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ import * as fs from "fs-extra";

import { FirebaseError } from "../../error";
import * as logger from "../../logger";
import { ExtensionInstance, ParamType } from "../../extensions/extensionsApi";
import { ExtensionInstance, Param, ParamType } from "../../extensions/extensionsApi";
import * as extensionsHelper from "../../extensions/extensionsHelper";
import * as paramHelper from "../../extensions/paramHelper";
import * as prompt from "../../prompt";

const PROJECT_ID = "test-proj";
const TEST_PARAMS = [
const TEST_PARAMS: Param[] = [
{
param: "A_PARAMETER",
label: "Param",
type: ParamType.STRING,
required: true,
},
{
param: "ANOTHER_PARAMETER",
Expand All @@ -26,7 +27,7 @@ const TEST_PARAMS = [
},
];

const TEST_PARAMS_2 = [
const TEST_PARAMS_2: Param[] = [
{
param: "ANOTHER_PARAMETER",
label: "Another Param",
Expand All @@ -46,7 +47,7 @@ const TEST_PARAMS_2 = [
default: "default",
},
];
const TEST_PARAMS_3 = [
const TEST_PARAMS_3: Param[] = [
{
param: "A_PARAMETER",
label: "Param",
Expand Down Expand Up @@ -115,7 +116,23 @@ describe("paramHelper", () => {
});
});

it("should throw if a param without a default is not in envFilePath", async () => {
it("should omit optional params that are not in envFilePath", async () => {
dotenvStub.returns({
ANOTHER_PARAMETER: "aValue",
});

const params = await paramHelper.getParams(
PROJECT_ID,
TEST_PARAMS_3,
"./a/path/to/a/file.env"
);

expect(params).to.eql({
ANOTHER_PARAMETER: "aValue",
});
});

it("should throw if a required param without a default is not in envFilePath", async () => {
dotenvStub.returns({
ANOTHER_PARAMETER: "aValue",
});
Expand Down Expand Up @@ -217,6 +234,7 @@ describe("paramHelper", () => {
label: "Param",
default: "new default",
type: ParamType.STRING,
required: true,
},
{
param: "ANOTHER_PARAMETER",
Expand Down Expand Up @@ -244,6 +262,7 @@ describe("paramHelper", () => {
label: "Param",
default: "new default",
type: ParamType.STRING,
required: true,
},
{
param: "ANOTHER_PARAMETER",
Expand Down

0 comments on commit 6b22276

Please sign in to comment.