Skip to content

Commit

Permalink
fix validation
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie committed Feb 18, 2021
1 parent e3aed20 commit 6210899
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
8 changes: 6 additions & 2 deletions packages/core/src/__tests__/validate-config.test.ts
Expand Up @@ -466,18 +466,22 @@ describe("validatePlugin", () => {
}
});

// Check no validation issues with base options
expect(
await validatePlugins(hook, {
plugins: [["test-plugin", { url: "foo" }]],
})
).toStrictEqual([]);
// Check no validation issues with intersected options
expect(
await validatePlugins(hook, {
plugins: [["test-plugin", { auth: "app" }]],
})
).toMatchSnapshot();
// Check no validation issues with intersected options
expect(
await validatePlugins(hook, {
plugins: [["test-plugin", { auth: "app", channels: ['foo'] }]],
})
).toStrictEqual([]);
});

test("should validate plugin configuration - array of configurations", async () => {
Expand Down
24 changes: 17 additions & 7 deletions packages/core/src/validate-config.ts
Expand Up @@ -256,17 +256,16 @@ export const validateIoConfiguration = (
type._tag === "IntersectionType" || (type as any)._tag === "ExactType"
)
) {
const matchingMember = exactDeclaration.types
.map((t) => t.decode(rc))
.filter((t) => "left" in t)[0];
const decodedTypes = exactDeclaration.types.map((t) => t.decode(rc));
const matchingMissingMember = decodedTypes.filter((t) => "left" in t)[0];

if (matchingMember && "left" in matchingMember) {
if (matchingMissingMember && "left" in matchingMissingMember) {
const correct = Object.keys(
matchingMember.left[0].context[0].actual as any
matchingMissingMember.left[0].context[0].actual as any
);
const missing =
matchingMember.left[0].context[
matchingMember.left[0].context.length - 1
matchingMissingMember.left[0].context[
matchingMissingMember.left[0].context.length - 1
].key;

return [
Expand All @@ -277,6 +276,17 @@ export const validateIoConfiguration = (
)} you must also provide ${unexpectedValue(missing)}\n`,
];
}

const matchingCorrectMember = decodedTypes.filter(
(t) =>
"right" in t &&
Object.keys(t.right).length &&
Object.keys(t.right).every((key) => unknownKeys.includes(key))
)[0];

if (matchingCorrectMember) {
return [];
}
}

return [
Expand Down

0 comments on commit 6210899

Please sign in to comment.