Example #1
0
 it('discards properties mentioned in `dropKeys` array', () => {
   expect(
     commonUtils.convertObjectPropsToCamelCase(objWithoutChildren, {
       dropKeys: ['group_name'],
     }),
   ).toEqual({
     projectName: 'GitLab CE',
     licenseType: 'MIT',
   });
 });
Example #2
0
 return Vue.http.patch(`${this.path}.json`, data).then(({ body = {} } = {}) => {
   /**
    * Since post implementation of Scoped labels, server can reject
    * same key-ed labels. To keep the UI and server Model consistent,
    * we're just assigning labels that server echo's back to us when we
    * PATCH the said object.
    */
   if (body) {
     this.labels = convertObjectPropsToCamelCase(body.labels, { deep: true });
   }
 });
Example #3
0
 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',
   });
 });
Example #4
0
        it('converts array with child objects', () => {
          const arr = [
            {
              child_snake_key: 'value',
            },
          ];

          expect(commonUtils.convertObjectPropsToCamelCase(arr, { deep: true })).toEqual([
            {
              childSnakeKey: 'value',
            },
          ]);
        });
Example #5
0
        it('converts object with child objects', () => {
          const obj = {
            snake_key: {
              child_snake_key: 'value',
            },
          };

          expect(commonUtils.convertObjectPropsToCamelCase(obj, { deep: true })).toEqual({
            snakeKey: {
              childSnakeKey: 'value',
            },
          });
        });
Example #6
0
    it('does not deep-convert by default', () => {
      const obj = {
        snake_key: {
          child_snake_key: 'value',
        },
      };

      expect(commonUtils.convertObjectPropsToCamelCase(obj)).toEqual({
        snakeKey: {
          child_snake_key: 'value',
        },
      });
    });
Example #7
0
 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',
     },
   });
 });
Example #8
0
 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',
     },
   });
 });
Example #9
0
    it('returns new object with camelCase property names by converting object with snake_case names', () => {
      const snakeRegEx = /(_\w)/g;
      const mockObj = {
        id: 1,
        group_name: 'GitLab.org',
        absolute_web_url: 'https://gitlab.com/gitlab-org/',
      };
      const mappings = {
        id: 'id',
        groupName: 'group_name',
        absoluteWebUrl: 'absolute_web_url',
      };

      const convertedObj = commonUtils.convertObjectPropsToCamelCase(mockObj);

      Object.keys(convertedObj).forEach(prop => {
        expect(snakeRegEx.test(prop)).toBeFalsy();
        expect(convertedObj[prop]).toBe(mockObj[mappings[prop]]);
      });
    });
Example #10
0
            .then(data => {
              const {
                subscribed,
                totalTimeSpent,
                timeEstimate,
                humanTimeEstimate,
                humanTotalTimeSpent,
                weight,
                epic,
              } = convertObjectPropsToCamelCase(data);

              newIssue.setFetchingState('subscriptions', false);
              newIssue.updateData({
                humanTimeSpent: humanTotalTimeSpent,
                timeSpent: totalTimeSpent,
                humanTimeEstimate,
                timeEstimate,
                subscribed,
                weight,
                epic,
              });
            })
Example #11
0
 beforeEach(() => {
   const imageDiffDiscussionMock = getJSONFixture(imageDiscussionFixture)[0];
   props.discussion = convertObjectPropsToCamelCase(imageDiffDiscussionMock);
 });
Example #12
0
export default {
  [types.SET_BASE_CONFIG](state, options) {
    const { endpoint, projectPath } = options;
    Object.assign(state, { endpoint, projectPath });
  },

  [types.SET_LOADING](state, isLoading) {
    Object.assign(state, { isLoading });
  },

  [types.SET_DIFF_DATA](state, data) {
    prepareDiffData(data);

    Object.assign(state, {
      ...convertObjectPropsToCamelCase(data),
    });
  },

  [types.RENDER_FILE](state, file) {
    Object.assign(file, {
      renderIt: true,
    });
  },

  [types.SET_MERGE_REQUEST_DIFFS](state, mergeRequestDiffs) {
    Object.assign(state, {
      mergeRequestDiffs,
    });
  },
Example #13
0
 it('return empty object if method is called with null or undefined', () => {
   expect(Object.keys(commonUtils.convertObjectPropsToCamelCase(null)).length).toBe(0);
   expect(Object.keys(commonUtils.convertObjectPropsToCamelCase()).length).toBe(0);
   expect(Object.keys(commonUtils.convertObjectPropsToCamelCase({})).length).toBe(0);
 });