diff --git a/src/json.ts b/src/json.ts index 250b87e..fbd85d3 100644 --- a/src/json.ts +++ b/src/json.ts @@ -243,10 +243,12 @@ export async function validateJson( ) ) { valid = false + errors.push( + ...(validator.errors as ErrorObject[]).map( + errorObjectToValidationError + ) + ) } - errors.push( - ...(validator.errors as ErrorObject[]).map(errorObjectToValidationError) - ) resolve({ valid, errors }) } diff --git a/test/fixtures/sample-valid.json b/test/fixtures/sample-valid.json new file mode 100644 index 0000000..6fa56c5 --- /dev/null +++ b/test/fixtures/sample-valid.json @@ -0,0 +1,66 @@ +{ + "hospital_name": "Test Hospital", + "last_updated_on": "2023-01-01", + "version": "1.1", + "standard_charge_information": [ + { + "description": "MRI", + "billing_code_information": [{ "code": "12345", "type": "CDM" }], + "standard_charges": [ + { + "setting": "outpatient", + "minimum": 300, + "maximum": 1500, + "gross_charge": 1500, + "discounted_cash": 1200, + "payers_information": [ + { + "payer_name": "Aetna", + "plan_name": "Commercial", + "contracting_method": "case rate", + "standard_charge": 1000 + }, + { + "payer_name": "Payer", + "plan_name": "PPO", + "contracting_method": "case rate", + "standard_charge": 1000 + } + ], + "billing_class": "facility" + } + ] + }, + { + "description": "Exam", + "billing_code_information": [ + { "code": "2345", "type": "CDM" }, + { "code": "123", "type": "RC" } + ], + "standard_charges": [ + { + "setting": "outpatient", + "minimum": 1, + "maximum": 50, + "gross_charge": 50, + "discounted_cash": 40, + "payers_information": [ + { + "payer_name": "Aetna", + "plan_name": "Commercial", + "contracting_method": "case rate", + "standard_charge": 25 + }, + { + "payer_name": "America", + "plan_name": "PPO", + "contracting_method": "case rate", + "standard_charge": 25 + } + ], + "billing_class": "facility" + } + ] + } + ] +} diff --git a/test/json.spec.ts b/test/json.spec.ts index 6b36e11..646e8a4 100644 --- a/test/json.spec.ts +++ b/test/json.spec.ts @@ -14,6 +14,12 @@ test("validateJson empty", async (t) => { t.deepEqual(result.errors.length, 4) }) +test("validateJson valid", async (t) => { + const result = await validateJson(loadFixtureStream("sample-valid.json")) + t.is(result.valid, true) + t.deepEqual(result.errors.length, 0) +}) + test("validateJsonSync", (t) => { const result = validateJsonSync(loadFixture("sample-1.json")) t.is(result.valid, false) @@ -25,3 +31,9 @@ test("validateJsonSync empty", (t) => { t.is(result.valid, false) t.is(result.errors.length, 4) }) + +test("validateJsonSync valid", (t) => { + const result = validateJsonSync(loadFixture("sample-valid.json")) + t.is(result.valid, true) + t.is(result.errors.length, 0) +})