Skip to content

Commit 15cacbf

Browse files
committed
handling threshold constraints
1 parent 3d66db0 commit 15cacbf

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/lib/schemaValidation.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,15 @@ const SnapshotSchema: JSONSchemaType<Snapshot> = {
536536
},
537537
approvalThreshold: {
538538
type: "number",
539-
errorMessage: "Invalid snapshot options; approvalThreshold must be a number"
539+
minimum: 0,
540+
maximum: 100,
541+
errorMessage: "Invalid snapshot options; approvalThreshold must be a number between 0 and 100"
540542
},
541543
rejectionThreshold: {
542544
type: "number",
543-
errorMessage: "Invalid snapshot options; rejectionThreshold must be a number"
545+
minimum: 0,
546+
maximum: 100,
547+
errorMessage: "Invalid snapshot options; rejectionThreshold must be a number between 0 and 100"
544548
}
545549
},
546550
additionalProperties: false

src/lib/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ export default async (ctx: Context): Promise<FastifyInstance<Server, IncomingMes
3939
let { snapshot, testType } = request.body;
4040
if (!validateSnapshot(snapshot)) throw new Error(validateSnapshot.errors[0].message);
4141

42-
if(snapshot?.options?.approvalThreshold && snapshot?.options?.rejectionThreshold) {
42+
if(snapshot?.options?.approvalThreshold !== undefined && snapshot?.options?.rejectionThreshold !== undefined) {
4343
if(snapshot?.options?.rejectionThreshold <= snapshot?.options?.approvalThreshold) {
44-
throw new Error('Invalid snapshot; rejectionThreshold must be greater than approvalThreshold');
44+
throw new Error(`Invalid snapshot options; rejectionThreshold (${snapshot.options.rejectionThreshold}) must be greater than approvalThreshold (${snapshot.options.approvalThreshold})`);
4545
}
4646
}
4747

0 commit comments

Comments
 (0)