Skip to content

Commit

Permalink
update json tests for dot mode
Browse files Browse the repository at this point in the history
  • Loading branch information
GrantBirki committed Jul 31, 2023
1 parent 2ab8f19 commit b4a6b82
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"foo": 5,
"bar": "zxy"
}
20 changes: 19 additions & 1 deletion __tests__/functions/json-validator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ beforeEach(() => {
process.env.INPUT_JSON_EXTENSION = '.json'
process.env.INPUT_JSON_EXCLUDE_REGEX = '.*bad.*\\.json'
process.env.INPUT_YAML_AS_JSON = false
process.env.INPUT_USE_DOT_MATCH = 'true'
})

test('successfully validates a json file with a schema', async () => {
Expand Down Expand Up @@ -60,7 +61,8 @@ test('successfully skips a file found in the exclude txt file', async () => {
})
})

test('successfully validates a json file with a schema and skips the schema as well', async () => {
test('successfully validates a json file with a schema and skips the schema as well while using the dot match in a disabled mode', async () => {
process.env.INPUT_USE_DOT_MATCH = 'false'
process.env.INPUT_JSON_SCHEMA =
'./__tests__/fixtures/json/project_dir/schemas/schema.json'
process.env.INPUT_BASE_DIR = './__tests__/fixtures/json/project_dir'
Expand All @@ -76,6 +78,22 @@ test('successfully validates a json file with a schema and skips the schema as w
)
})

test('successfully validates a json file with a schema and skips the schema as well', async () => {
process.env.INPUT_JSON_SCHEMA =
'./__tests__/fixtures/json/project_dir/schemas/schema.json'
process.env.INPUT_BASE_DIR = './__tests__/fixtures/json/project_dir'
expect(await jsonValidator(excludeMock)).toStrictEqual({
failed: 0,
passed: 2,
skipped: 0,
success: true,
violations: []
})
expect(debugMock).toHaveBeenCalledWith(
`skipping json schema file: ${process.env.INPUT_JSON_SCHEMA}`
)
})

test('fails to validate a json file without using a schema', async () => {
process.env.INPUT_JSON_SCHEMA = ''
process.env.INPUT_BASE_DIR = './__tests__/fixtures/json/invalid'
Expand Down

0 comments on commit b4a6b82

Please sign in to comment.