From dc42f050765214e71fd838f8ab6bed273097b511 Mon Sep 17 00:00:00 2001 From: Varun0157 Date: Sat, 11 May 2024 19:54:18 +0530 Subject: [PATCH 1/3] feat: going one level deeper for size assertions (supporting $gt, $gte, etc.) --- package-lock.json | 4 ++-- src/runTests.ts | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 95538d2..d4524a9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "zzapi", - "version": "1.0.2", + "version": "1.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "zzapi", - "version": "1.0.2", + "version": "1.1.1", "license": "MIT", "dependencies": { "got": "11.8.6", diff --git a/src/runTests.ts b/src/runTests.ts index e6d8c3f..fbc2336 100644 --- a/src/runTests.ts +++ b/src/runTests.ts @@ -95,7 +95,17 @@ function runObjectTests( } else if (typeof receivedObject === "string" || Array.isArray(receivedObject)) { receivedLen = receivedObject.length; } - pass = receivedLen === expected; + if (typeof expected === "number") { + pass = receivedLen === expected; + } else { + try { + expected = JSON.parse(expected); + } catch (err: any) { + message = `$size val is not num or valid JSON`; + } + results.push(...runObjectTests(expected, receivedLen, spec)); + continue; + } } else if (op === "$exists") { const exists = received != undefined; pass = exists === expected; From b4b4fb8743240e41c315f0d5811ff2367258d9d0 Mon Sep 17 00:00:00 2001 From: Varun0157 Date: Sat, 11 May 2024 19:58:20 +0530 Subject: [PATCH 2/3] bug: preventing unwanted fall through in the catch case of non-numeric value for expected --- src/runTests.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/runTests.ts b/src/runTests.ts index fbc2336..00fd56e 100644 --- a/src/runTests.ts +++ b/src/runTests.ts @@ -67,7 +67,7 @@ function getValueForJSONTests(responseContent: object, key: string): any { function runObjectTests( opVals: { [key: string]: any }, receivedObject: any, - spec: string, + spec: string ): TestResult[] { let results: TestResult[] = []; @@ -100,11 +100,12 @@ function runObjectTests( } else { try { expected = JSON.parse(expected); + results.push(...runObjectTests(expected, receivedLen, spec)); + continue; } catch (err: any) { + pass = false; message = `$size val is not num or valid JSON`; } - results.push(...runObjectTests(expected, receivedLen, spec)); - continue; } } else if (op === "$exists") { const exists = received != undefined; From 0163b5b3e3f6be690206d8899b8df9d8ccd55240 Mon Sep 17 00:00:00 2001 From: Varun0157 Date: Sat, 11 May 2024 20:00:26 +0530 Subject: [PATCH 3/3] format: reformatting explicitly w prettier --- src/runTests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runTests.ts b/src/runTests.ts index 00fd56e..1103a69 100644 --- a/src/runTests.ts +++ b/src/runTests.ts @@ -67,7 +67,7 @@ function getValueForJSONTests(responseContent: object, key: string): any { function runObjectTests( opVals: { [key: string]: any }, receivedObject: any, - spec: string + spec: string, ): TestResult[] { let results: TestResult[] = [];