Skip to content

Commit

Permalink
Add tests for utils.cleanJSON/config.closedWorldAssumption (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandesu committed Feb 24, 2022
1 parent 123dc9d commit 533f6d1
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const assert = require("assert")
const utils = require("../utils")
const config = require("../config")

describe("utils", () => {

Expand Down Expand Up @@ -366,4 +367,78 @@ describe("utils", () => {
}
})

describe("cleanJSON", () => {
const prevClosedWorldAssumption = config.closedWorldAssumption

const tests = [
{
closedWorldAssumption: false,
input: {
_a: 1,
b: {},
c: [],
d: 2,
},
output: {
d: 2,
},
},
{
closedWorldAssumption: true,
input: {
b: {},
c: [],
},
output: {
b: {},
c: [],
},
},
{
closedWorldAssumption: false,
input: [
{
_a: 1,
b: {},
c: [],
d: null,
},
],
output: [
{
d: null,
},
],
},
// Currently, only top-level properties are affected by closedWorldAssumption = false.
// See: https://github.com/gbv/jskos-server/commit/123dc9da09f1e41f2263ee8a0f7faeefe67fa9ed#r67204606
{
closedWorldAssumption: false,
input: {
a: {
b: {},
_b: 1,
},
},
output: {
a: {
b: {},
},
},
},
]

let index = 0
for (let { closedWorldAssumption, input, output } of tests) {
it(`should pass test[${index}]`, async () => {
config.closedWorldAssumption = closedWorldAssumption
utils.cleanJSON(input)
assert.deepEqual(input, output)
})
index += 1
}

config.closedWorldAssumption = prevClosedWorldAssumption
})

})

0 comments on commit 533f6d1

Please sign in to comment.