mirror of
https://github.com/ansible/awx.git
synced 2026-02-16 10:40:01 -03:30
Merge pull request #284 from jakemcdermott/move-yaml-test
move yaml test to utils
This commit is contained in:
70
src/util/yaml.test.js
Normal file
70
src/util/yaml.test.js
Normal file
@@ -0,0 +1,70 @@
|
||||
import { yamlToJson, jsonToYaml } from './yaml';
|
||||
|
||||
describe('yamlToJson', () => {
|
||||
test('should convert to json', () => {
|
||||
const yaml = `
|
||||
---
|
||||
one: 1
|
||||
two: two
|
||||
`;
|
||||
expect(yamlToJson(yaml)).toEqual(`{
|
||||
"one": 1,
|
||||
"two": "two"
|
||||
}`);
|
||||
});
|
||||
|
||||
test('should remove comments', () => {
|
||||
const yaml = `
|
||||
---
|
||||
one: 1
|
||||
# comment
|
||||
two: two
|
||||
# comment two
|
||||
`;
|
||||
expect(yamlToJson(yaml)).toEqual(`{
|
||||
"one": 1,
|
||||
"two": "two"
|
||||
}`);
|
||||
});
|
||||
|
||||
test('should convert empty string to {}', () => {
|
||||
expect(yamlToJson('')).toEqual('{}');
|
||||
});
|
||||
|
||||
test('should convert null to {}', () => {
|
||||
expect(yamlToJson(null)).toEqual('{}');
|
||||
});
|
||||
|
||||
test('should convert empty yaml to {}', () => {
|
||||
expect(yamlToJson('---')).toEqual('{}');
|
||||
});
|
||||
|
||||
test('should throw if invalid yaml given', () => {
|
||||
expect(() => yamlToJson('foo')).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('jsonToYaml', () => {
|
||||
test('should convert to yaml', () => {
|
||||
const json = `{
|
||||
"one": 1,
|
||||
"two": "two"
|
||||
}
|
||||
`;
|
||||
expect(jsonToYaml(json)).toEqual(`one: 1
|
||||
two: two
|
||||
`);
|
||||
});
|
||||
|
||||
test('should convert empty object to empty yaml doc', () => {
|
||||
expect(jsonToYaml('{}')).toEqual('---\n');
|
||||
});
|
||||
|
||||
test('should convert empty string to empty yaml doc', () => {
|
||||
expect(jsonToYaml('')).toEqual('---\n');
|
||||
});
|
||||
|
||||
test('should throw if invalid json given', () => {
|
||||
expect(() => jsonToYaml('bad data')).toThrow();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user