Skip to content

Commit

Permalink
Add filter to prevent NPE while reactivating from extension console (#…
Browse files Browse the repository at this point in the history
…6410)

* add filter to prevent NPE while reactivating

* move filter and add test
  • Loading branch information
turbochef authored Sep 7, 2023
1 parent 76868c3 commit 655c496
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
10 changes: 10 additions & 0 deletions src/store/extensionsUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { type IntegrationDependency } from "@/types/integrationTypes";
import { uuidv4, validateRegistryId } from "@/types/helpers";
import { validateOutputKey } from "@/runtime/runtimeTypes";
import { integrationDependencyFactory } from "@/testUtils/factories/integrationFactories";
import { PIXIEBRIX_INTEGRATION_ID } from "@/services/constants";

describe("inferRecipeOptions", () => {
it("returns first option", () => {
Expand Down Expand Up @@ -98,4 +99,13 @@ describe("inferModIntegrations", () => {
})
).toBeEmpty();
});

it("handles unconfigured integrations when the id is the default", () => {
const unconfigured = integrationDependencyFactory();
delete unconfigured.config;
unconfigured.id = validateRegistryId(PIXIEBRIX_INTEGRATION_ID);
expect(
inferConfiguredModIntegrations([{ services: [unconfigured] }])
).toBeEmpty();
});
});
12 changes: 4 additions & 8 deletions src/store/extensionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,12 @@ export function inferConfiguredModIntegrations(
({ config }) => config
);

if (
id !== PIXIEBRIX_INTEGRATION_ID &&
configuredDependencies.length === 0
) {
if (optional) {
continue;
} else {
// PIXIEBRIX_SERVICE_ID gets the implicit configuration
if (configuredDependencies.length === 0) {
if (id !== PIXIEBRIX_INTEGRATION_ID && !optional) {
throw new Error(`Integration ${id} is not configured`);
}

continue;
}

// If optional is passed in, we know that the user is being given an
Expand Down

0 comments on commit 655c496

Please sign in to comment.