Skip to content

Commit

Permalink
feat: running status, then header, then json, then direct body assert…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
Varun0157 committed May 11, 2024
1 parent 47137ec commit 39210d9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
10 changes: 5 additions & 5 deletions src/mergeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function getMergedParams(commonParams: RawParams, requestParams: RawParams): Par

function getMergedHeaders(
commonHeaders: RawHeaders,
requestHeaders: RawHeaders,
requestHeaders: RawHeaders
): { [name: string]: string } {
if (Array.isArray(commonHeaders)) {
commonHeaders = getArrayHeadersAsObject(commonHeaders);
Expand Down Expand Up @@ -79,7 +79,7 @@ function getMergedOptions(cOptions: RawOptions = {}, rOptions: RawOptions = {}):

function getMergedSetVars(
setvars: RawSetVars = {},
captures: Captures = {},
captures: Captures = {}
): { mergedVars: SetVar[]; hasJsonVars: boolean } {
const mergedVars: SetVar[] = [];
let hasJsonVars = false;
Expand Down Expand Up @@ -152,7 +152,7 @@ function mergePrefixBasedTests(tests: RawTests) {

function getMergedTests(
cTests: RawTests = {},
rTests: RawTests = {},
rTests: RawTests = {}
): { mergedTests: Tests; hasJsonTests: boolean } {
// Convert $. and h. at root level into headers and json keys
mergePrefixBasedTests(cTests);
Expand Down Expand Up @@ -209,11 +209,11 @@ export function getMergedData(commonData: Common, requestData: RawRequest): Requ

const { mergedTests: tests, hasJsonTests: hasJsonTests } = getMergedTests(
commonData?.tests,
requestData.tests,
requestData.tests
);
const { mergedVars: setvars, hasJsonVars: hasJsonVars } = getMergedSetVars(
requestData.setvars,
requestData.capture,
requestData.capture
);

const mergedData: RequestSpec = {
Expand Down
26 changes: 13 additions & 13 deletions src/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ export function runAllTests(tests: Tests, responseData: ResponseData): TestResul
const results: TestResult[] = [];
if (!tests) return results;

for (const spec in tests.json) {
const expected = tests.json[spec];
const received = getValueForJSONTests(responseData.json, spec);
const jsonResults = runTest(spec, expected, received);
results.push(...jsonResults);
if (tests.status) {
const expected = tests.status;
const received = responseData.status;
const statusResults = runTest("status", expected, received);
results.push(...statusResults);
}

for (const spec in tests.headers) {
Expand All @@ -22,20 +22,20 @@ export function runAllTests(tests: Tests, responseData: ResponseData): TestResul
results.push(...headerResults);
}

for (const spec in tests.json) {
const expected = tests.json[spec];
const received = getValueForJSONTests(responseData.json, spec);
const jsonResults = runTest(spec, expected, received);
results.push(...jsonResults);
}

if (tests.body) {
const expected = tests.body;
const received = responseData.body;
const bodyResults = runTest("body", expected, received);
results.push(...bodyResults);
}

if (tests.status) {
const expected = tests.status;
const received = responseData.status;
const statusResults = runTest("status", expected, received);
results.push(...statusResults);
}

return results;
}

Expand Down Expand Up @@ -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[] = [];

Expand Down

0 comments on commit 39210d9

Please sign in to comment.