-
Notifications
You must be signed in to change notification settings - Fork 40
feat: add new output formats: jsonArray and yamlArray #897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alinashklyar
wants to merge
7
commits into
master
Choose a base branch
from
CR-7584-json-array
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5d53398
add new output formats: jsonArray and yamlArray
alinashklyar 10cad2a
add specs
alinashklyar 39f82ad
remove odd change:
alinashklyar d7f9b85
empty
alinashklyar 39790b8
empty
mikhail-klimko ff8b05c
debug
mikhail-klimko a70c955
debug
mikhail-klimko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| const CFError = require('cf-errors'); // eslint-disable-line | ||
| const Entity = require('../../logic/entities/Entity'); | ||
| const _ = require('lodash'); | ||
|
|
||
| function output(data) { | ||
| const entities = _.isArray(data) ? data : [data]; | ||
| const jsonArray = []; | ||
|
|
||
| _.forEach(entities, (entity) => { | ||
| if (!(entity instanceof Entity)) { | ||
| throw new CFError('Cannot extract data for "jsonArray" output -- data contains not Entity'); | ||
| } | ||
| jsonArray.push(entity.info); | ||
| }); | ||
|
|
||
| return JSON.stringify(jsonArray, null, '\t'); | ||
| } | ||
|
|
||
| module.exports = output; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| const CFError = require('cf-errors'); | ||
| const Entity = require('../../logic/entities/Entity'); | ||
| const output = require('./jsonArray.output'); | ||
|
|
||
| describe('jsonArray output', () => { | ||
| it('should return empty array for an empty array', () => { | ||
| expect(output([])).toBe('[]'); | ||
| }); | ||
|
|
||
| it('should wrap single Entity into array', () => { | ||
| const entity = new Entity(); | ||
| entity.info = { id: '1', status: 'ok' }; | ||
|
|
||
| const result = JSON.parse(output(entity)); | ||
| expect(Array.isArray(result)).toBe(true); | ||
| expect(result).toHaveLength(1); | ||
| expect(result[0]).toEqual(entity.info); | ||
| }); | ||
|
|
||
| it('should keep multiple Entities as array', () => { | ||
| const entity1 = new Entity(); | ||
| entity1.info = { id: '1' }; | ||
| const entity2 = new Entity(); | ||
| entity2.info = { id: '2' }; | ||
|
|
||
| const result = JSON.parse(output([entity1, entity2])); | ||
| expect(Array.isArray(result)).toBe(true); | ||
| expect(result).toHaveLength(2); | ||
| expect(result[0]).toEqual(entity1.info); | ||
| expect(result[1]).toEqual(entity2.info); | ||
| }); | ||
|
|
||
| it('should throw CFError if element is not an Entity', () => { | ||
| expect(() => output({ id: '1' })).toThrow(CFError); | ||
| expect(() => output([new Entity(), {}])).toThrow(CFError); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| const CFError = require('cf-errors'); | ||
| const Entity = require('../../logic/entities/Entity'); | ||
| const _ = require('lodash'); | ||
| const yaml = require('js-yaml'); | ||
|
|
||
| function output(data) { | ||
| const entities = _.isArray(data) ? data : [data]; | ||
| const yamlArray = []; | ||
|
|
||
| _.forEach(entities, (entity) => { | ||
| if (!(entity instanceof Entity)) { | ||
| throw new CFError('Cannot extract data for "yamlArray" output -- data contains not Entity'); | ||
| } | ||
| yamlArray.push(entity.info); | ||
| }); | ||
|
|
||
| return yaml.dump(yamlArray); | ||
| } | ||
|
|
||
| module.exports = output; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| const CFError = require('cf-errors'); | ||
| const yaml = require('js-yaml'); | ||
| const Entity = require('../../logic/entities/Entity'); | ||
| const output = require('./yamlArray.output'); | ||
|
|
||
| describe('yamlArray output', () => { | ||
| it('should return empty array for an empty array', () => { | ||
| const result = yaml.load(output([])); | ||
| expect(Array.isArray(result)).toBe(true); | ||
| expect(result).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('should wrap single Entity into array', () => { | ||
| const entity = new Entity(); | ||
| entity.info = { id: '1', status: 'ok' }; | ||
|
|
||
| const result = yaml.load(output(entity)); | ||
| expect(Array.isArray(result)).toBe(true); | ||
| expect(result).toHaveLength(1); | ||
| expect(result[0]).toEqual(entity.info); | ||
| }); | ||
|
|
||
| it('should keep multiple Entities as array', () => { | ||
| const entity1 = new Entity(); | ||
| entity1.info = { id: '1' }; | ||
| const entity2 = new Entity(); | ||
| entity2.info = { id: '2' }; | ||
|
|
||
| const result = yaml.load(output([entity1, entity2])); | ||
| expect(Array.isArray(result)).toBe(true); | ||
| expect(result).toHaveLength(2); | ||
| expect(result[0]).toEqual(entity1.info); | ||
| expect(result[1]).toEqual(entity2.info); | ||
| }); | ||
|
|
||
| it('should throw CFError if element is not an Entity', () => { | ||
| expect(() => output({ id: '1' })).toThrow(CFError); | ||
| expect(() => output([new Entity(), {}])).toThrow(CFError); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3558,7 +3558,7 @@ forever-agent@~0.6.1: | |
| resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91" | ||
| integrity sha512-j0KLYPhm6zeac4lz3oJ3o65qvgQCcPubiyotZrXqEaG4hNagNYO8qdlUrX5vwqv9ohqeT/Z3j6+yW067yWWdUw== | ||
|
|
||
| form-data@^2.3.2, form-data@^2.5.4, form-data@~2.3.2: | ||
| form-data@^2.3.2, form-data@^2.5.5, form-data@~2.3.2: | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. automatic change which happened when I did yarn install. I can remove it |
||
| version "2.5.5" | ||
| resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.5.5.tgz#a5f6364ad7e4e67e95b4a07e2d8c6f711c74f624" | ||
| integrity sha512-jqdObeR2rxZZbPSGL+3VckHMYtu+f9//KXBsVny6JSX/pa38Fy+bGjuG8eW/H6USNQWhLi8Num++cU2yOCNz4A== | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created this file based on the implementation of json output file. same for yamlArray