summaryrefslogtreecommitdiff
path: root/spec/javascripts/lib
diff options
context:
space:
mode:
authorKushal Pandya <kushalspandya@gmail.com>2019-01-30 14:36:58 +0530
committerKushal Pandya <kushalspandya@gmail.com>2019-01-31 17:02:46 +0530
commit93e58bf9b5072f0c998ba91829d7f4f9da129754 (patch)
tree59c7b11dd00dcaea63670eeb89f3aae81c0088a3 /spec/javascripts/lib
parent6da156ab4876d946794daa5f48febe88be82fd0e (diff)
downloadgitlab-ce-93e58bf9b5072f0c998ba91829d7f4f9da129754.tar.gz
Support for ignore rules in 'convertObjectPropsToCamelCase' helper
Does following enhancements to `convertObjectPropsToCamelCase` helper; - Adds support for `dropKeys` within options param to discard properties. - Adds support for `allowKeys` within options param to skip converting property names.
Diffstat (limited to 'spec/javascripts/lib')
-rw-r--r--spec/javascripts/lib/utils/common_utils_spec.js152
1 files changed, 116 insertions, 36 deletions
diff --git a/spec/javascripts/lib/utils/common_utils_spec.js b/spec/javascripts/lib/utils/common_utils_spec.js
index 121c4040212..e3fd9604474 100644
--- a/spec/javascripts/lib/utils/common_utils_spec.js
+++ b/spec/javascripts/lib/utils/common_utils_spec.js
@@ -680,51 +680,131 @@ describe('common_utils', () => {
});
});
- describe('deep: true', () => {
- it('converts object with child objects', () => {
- const obj = {
- snake_key: {
- child_snake_key: 'value',
- },
- };
-
- expect(commonUtils.convertObjectPropsToCamelCase(obj, { deep: true })).toEqual({
- snakeKey: {
- childSnakeKey: 'value',
- },
- });
- });
+ describe('with options', () => {
+ const objWithoutChildren = {
+ project_name: 'GitLab CE',
+ group_name: 'GitLab.org',
+ license_type: 'MIT',
+ };
- it('converts array with child objects', () => {
- const arr = [
- {
- child_snake_key: 'value',
- },
- ];
-
- expect(commonUtils.convertObjectPropsToCamelCase(arr, { deep: true })).toEqual([
- {
- childSnakeKey: 'value',
- },
- ]);
- });
+ const objWithChildren = {
+ project_name: 'GitLab CE',
+ group_name: 'GitLab.org',
+ license_type: 'MIT',
+ tech_stack: {
+ backend: 'Ruby',
+ frontend_framework: 'Vue',
+ database: 'PostgreSQL',
+ },
+ };
+
+ describe('when options.deep is true', () => {
+ it('converts object with child objects', () => {
+ const obj = {
+ snake_key: {
+ child_snake_key: 'value',
+ },
+ };
+
+ expect(commonUtils.convertObjectPropsToCamelCase(obj, { deep: true })).toEqual({
+ snakeKey: {
+ childSnakeKey: 'value',
+ },
+ });
+ });
- it('converts array with child arrays', () => {
- const arr = [
- [
+ it('converts array with child objects', () => {
+ const arr = [
{
child_snake_key: 'value',
},
- ],
- ];
+ ];
- expect(commonUtils.convertObjectPropsToCamelCase(arr, { deep: true })).toEqual([
- [
+ expect(commonUtils.convertObjectPropsToCamelCase(arr, { deep: true })).toEqual([
{
childSnakeKey: 'value',
},
- ],
- ]);
+ ]);
+ });
+
+ it('converts array with child arrays', () => {
+ const arr = [
+ [
+ {
+ child_snake_key: 'value',
+ },
+ ],
+ ];
+
+ expect(commonUtils.convertObjectPropsToCamelCase(arr, { deep: true })).toEqual([
+ [
+ {
+ childSnakeKey: 'value',
+ },
+ ],
+ ]);
+ });
+ });
+
+ describe('when options.dropKeys is provided', () => {
+ it('discards properties mentioned in `dropKeys` array', () => {
+ expect(
+ commonUtils.convertObjectPropsToCamelCase(objWithoutChildren, {
+ dropKeys: ['group_name'],
+ }),
+ ).toEqual({
+ projectName: 'GitLab CE',
+ licenseType: 'MIT',
+ });
+ });
+
+ it('discards properties mentioned in `dropKeys` array when `deep` is true', () => {
+ expect(
+ commonUtils.convertObjectPropsToCamelCase(objWithChildren, {
+ deep: true,
+ dropKeys: ['group_name', 'database'],
+ }),
+ ).toEqual({
+ projectName: 'GitLab CE',
+ licenseType: 'MIT',
+ techStack: {
+ backend: 'Ruby',
+ frontendFramework: 'Vue',
+ },
+ });
+ });
+ });
+
+ describe('when options.ignoreKeyNames is provided', () => {
+ it('leaves properties mentioned in `ignoreKeyNames` array intact', () => {
+ expect(
+ commonUtils.convertObjectPropsToCamelCase(objWithoutChildren, {
+ ignoreKeyNames: ['group_name'],
+ }),
+ ).toEqual({
+ projectName: 'GitLab CE',
+ licenseType: 'MIT',
+ group_name: 'GitLab.org',
+ });
+ });
+
+ it('leaves properties mentioned in `ignoreKeyNames` array intact when `deep` is true', () => {
+ expect(
+ commonUtils.convertObjectPropsToCamelCase(objWithChildren, {
+ deep: true,
+ ignoreKeyNames: ['group_name', 'frontend_framework'],
+ }),
+ ).toEqual({
+ projectName: 'GitLab CE',
+ group_name: 'GitLab.org',
+ licenseType: 'MIT',
+ techStack: {
+ backend: 'Ruby',
+ frontend_framework: 'Vue',
+ database: 'PostgreSQL',
+ },
+ });
+ });
});
});
});