Skip to content

Commit

Permalink
test: enables formats
Browse files Browse the repository at this point in the history
  • Loading branch information
celestial-labs committed Dec 21, 2023
1 parent 32b48ac commit 0be40b1
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions src/activities/__tests__/ValidateJsonSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,108 @@ describe("ValidateJsonSchema", () => {
"schema is required"
);
});

describe("formats", () => {
const cases = [
{
description: "a valid e-mail address",
input: { data: "[email protected]", schema: { type: "string", format: "email" } },
expected: true
},
{
description: "an invalid e-mail address",
input: { data: "2962", schema: { type: "string", format: "email" } },
expected: false
},

{
description: "valid regex",
input: { data: "[0-9]", schema: { type: "string", format: "regex" } },
expected: true
},
{
description: "invalid regex",
input: { data: "[9-0]", schema: { type: "string", format: "regex" } },
expected: false
},
{
description: "not string is valid",
input: { data: 123, schema: { type: "number", format: "regex" } },
expected: true
},

{
description: "valid uri",
input: { data: "urn:isbn:978-3-531-18621-4", schema: { type: "string", format: "uri" } },
expected: true
},
{
description: "invalid relative uri-reference",
input: { data: "/abc", schema: { type: "string", format: "uri" } },
expected: false
},

{
description: "valid uri-template",
input: {
data: "http://example.com/dictionary/{term:1}/{term}",
schema: { type: "string", format: "uri-template" }
},
expected: true
},
{
description: "invalid uri-template",
input: {
data: "http://example.com/dictionary/{term:1}/{term",
schema: { type: "string", format: "uri-template" }
},
expected: false
},

{
description: "valid hostname",
input: { data: "123.example.com", schema: { type: "string", format: "hostname" } },
expected: true
},

{
description: "a valid date string",
input: { data: "1963-06-19", schema: { type: "string", format: "date" } },
expected: true
},
{
description: "an invalid date string",
input: { data: "06/19/1963", schema: { type: "string", format: "date" } },
expected: false
},

{
description: "a valid uuid",
input: { data: "f81d4fae-7dec-11d0-a765-00a0c91e6bf6", schema: { type: "string", format: "uuid" } },
expected: true
},
{
description: "not valid uuid",
input: { data: "f81d4fae7dec11d0a76500a0c91e6bf6", schema: { type: "string", format: "uuid" } },
expected: false
}
];


it.each(cases)("$description", ({ input, expected }) => {
const activity: ValidateJsonSchema = new ValidateJsonSchema();
const { isValid, errors } = activity.execute(input);

expect(typeof isValid).toBe("boolean");

if (expected) {
expect(isValid).toBe(true);
expect(errors).toBeUndefined();
} else {
expect(isValid).toBe(false);
expect(errors).toBeDefined();
expect(Array.isArray(errors)).toBe(true);
}
});
});
});

0 comments on commit 0be40b1

Please sign in to comment.