diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/frontend/releases/util_spec.js | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/frontend/releases/util_spec.js')
-rw-r--r-- | spec/frontend/releases/util_spec.js | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/spec/frontend/releases/util_spec.js b/spec/frontend/releases/util_spec.js new file mode 100644 index 00000000000..90aa9c4c7d8 --- /dev/null +++ b/spec/frontend/releases/util_spec.js @@ -0,0 +1,103 @@ +import { releaseToApiJson, apiJsonToRelease } from '~/releases/util'; + +describe('releases/util.js', () => { + describe('releaseToApiJson', () => { + it('converts a release JavaScript object into JSON that the Release API can accept', () => { + const release = { + tagName: 'tag-name', + name: 'Release name', + description: 'Release description', + milestones: [{ id: 1, title: '13.2' }, { id: 2, title: '13.3' }], + assets: { + links: [{ url: 'https://gitlab.example.com/link', linkType: 'other' }], + }, + }; + + const expectedJson = { + tag_name: 'tag-name', + ref: null, + name: 'Release name', + description: 'Release description', + milestones: ['13.2', '13.3'], + assets: { + links: [{ url: 'https://gitlab.example.com/link', link_type: 'other' }], + }, + }; + + expect(releaseToApiJson(release)).toEqual(expectedJson); + }); + + describe('when createFrom is provided', () => { + it('adds the provided createFrom ref to the JSON as a "ref" property', () => { + const createFrom = 'main'; + + const release = {}; + + const expectedJson = { + ref: createFrom, + }; + + expect(releaseToApiJson(release, createFrom)).toMatchObject(expectedJson); + }); + }); + + describe('release.name', () => { + it.each` + input | output + ${null} | ${null} + ${''} | ${null} + ${' \t\n\r\n'} | ${null} + ${' Release name '} | ${'Release name'} + `('converts a name like `$input` to `$output`', ({ input, output }) => { + const release = { name: input }; + + const expectedJson = { + name: output, + }; + + expect(releaseToApiJson(release)).toMatchObject(expectedJson); + }); + }); + + describe('when release.milestones is falsy', () => { + it('includes a "milestone" property in the returned result as an empty array', () => { + const release = {}; + + const expectedJson = { + milestones: [], + }; + + expect(releaseToApiJson(release)).toMatchObject(expectedJson); + }); + }); + }); + + describe('apiJsonToRelease', () => { + it('converts JSON received from the Release API into an object usable by the Vue application', () => { + const json = { + tag_name: 'tag-name', + assets: { + links: [ + { + link_type: 'other', + }, + ], + }, + }; + + const expectedRelease = { + tagName: 'tag-name', + assets: { + links: [ + { + linkType: 'other', + }, + ], + }, + milestones: [], + }; + + expect(apiJsonToRelease(json)).toEqual(expectedRelease); + }); + }); +}); |