Skip to content

Commit

Permalink
feat: Allow long passport variables
Browse files Browse the repository at this point in the history
- This doesn't need to be resticted as it's handled at runtime
  • Loading branch information
DafyddLlyr committed Apr 19, 2024
1 parent 10c709d commit ad4fcd5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
17 changes: 16 additions & 1 deletion editor.planx.uk/src/@planx/components/Pay/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe("GovPayMetadata Schema", () => {
expect(errors[0]).toMatch(/Value is a required field/);
});

test("value cannot be greater than 100 characters", async () => {
test("static values cannot be greater than 100 characters", async () => {
const input = [
...defaults,
{
Expand All @@ -71,6 +71,21 @@ describe("GovPayMetadata Schema", () => {
expect(errors[0]).toMatch(/Value length cannot exceed 100 characters/);
});

test("dynamic passport value can be greater than 100 characters", async () => {
const input = [
...defaults,
{
key: "myPassportVariable",
value:
"@thisIsAVeryLongPassportVariable.itsUnlikelyToHappenButWeDontNeedToRestrict.theDynamicValueThisReadsWillBeTruncatedAtTimeOfSubmission",
},
];
const result = await validate(input);

// No errors, input returned from validation
expect(result).toEqual(input);
});

test("keys must be unique", async () => {
const input = [
...defaults,
Expand Down
12 changes: 11 additions & 1 deletion editor.planx.uk/src/@planx/components/Pay/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,17 @@ export const govPayMetadataSchema = array(
.max(30, "Key length cannot exceed 30 characters"),
value: string()
.required("Value is a required field")
.max(100, "Value length cannot exceed 100 characters"),
.test({
name: "max-length",
message: "Value length cannot exceed 100 characters",
test: (value) => {
if (!value) return true;
// No limit to dynamic passport variable length, this is checked and truncated at runtime
if (value.startsWith("@")) return true;
// Static strings must be 100 characters or less
return value.length <= 100;
},
}),
}),
)
.max(10, "A maximum of 10 fields can be set as metadata")
Expand Down

0 comments on commit ad4fcd5

Please sign in to comment.