Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GrantBirki committed Aug 13, 2023
1 parent 80aeebb commit cc336ff
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions __tests__/functions/json-validator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ test('fails to validate one json file with an incorrect schema and succeeds on t
{
path: '/foo',
message: 'must be string'
},
{
path: '/bar',
message: 'must be string'
}
]
}
Expand Down Expand Up @@ -254,6 +258,47 @@ test('processes multiple files when yaml_as_json is true and also a mixture of o
)
})

test('processes a real world example when yaml_as_json is true and the single file contains multiple schema errors', async () => {
process.env.INPUT_YAML_AS_JSON = 'true'
process.env.INPUT_JSON_SCHEMA = '__tests__/fixtures/schemas/challenge.json'
process.env.INPUT_BASE_DIR = '__tests__/fixtures/real_world/challenges'

expect(await jsonValidator(excludeMock)).toStrictEqual({
failed: 1,
passed: 0,
skipped: 0,
success: false,
violations: [
{
file: '__tests__/fixtures/real_world/challenges/challenge.yml',
errors: [
{
path: null,
message: `must have required property 'inputFormat'`
},
{
path: null,
message: `must have required property 'publicTests'`
}
]
}
]
})

expect(debugMock).toHaveBeenCalledWith(
'using ajv-formats with json-validator'
)
expect(debugMock).toHaveBeenCalledWith(
'json - using baseDir: __tests__/fixtures/real_world/challenges'
)
expect(debugMock).toHaveBeenCalledWith(
'json - using glob: **/*{.json,yaml,yml}'
)
expect(debugMock).toHaveBeenCalledWith(
`attempting to process yaml file: '__tests__/fixtures/real_world/challenges/challenge.yml' as json`
)
})

test('successfully validates json files with a schema when files is defined', async () => {
const files = [
'__tests__/fixtures/json/valid/json1.json',
Expand Down Expand Up @@ -288,6 +333,10 @@ test('fails to validate a yaml file with an incorrect schema when yaml_as_json i
{
path: null,
message: "must have required property 'foo'"
},
{
path: null,
message: 'must NOT have additional properties'
}
]
}
Expand Down

0 comments on commit cc336ff

Please sign in to comment.