Skip to content

Commit

Permalink
fix: parsing valid json
Browse files Browse the repository at this point in the history
  • Loading branch information
patsier-cms committed Jul 24, 2023
1 parent 4462eaa commit 4f62215
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}

Expand Down
66 changes: 66 additions & 0 deletions test/fixtures/sample-valid.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]
}
12 changes: 12 additions & 0 deletions test/json.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
})

0 comments on commit 4f62215

Please sign in to comment.