Skip to content

Commit

Permalink
PREAPPS-321 Fix bug with mapValuesDeep and add unit tests
Browse files Browse the repository at this point in the history
Add preference keys to schema for displaying external images
  • Loading branch information
billneff79 committed May 4, 2018
1 parent 8bb1923 commit 480b492
Show file tree
Hide file tree
Showing 8 changed files with 2,053 additions and 881 deletions.
28 changes: 18 additions & 10 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
{
"presets": [
["@babel/env", {
"modules": false
}],
"presets": [
["@babel/env", {
"modules": false
}],
"@babel/typescript"
],
"plugins": [
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread",
"lodash"
],
"env" : {
"test": {
"presets": [
"@babel/env",
"@babel/typescript"
],
"plugins": [
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread",
"lodash"
]
]
}
}
}
4 changes: 4 additions & 0 deletions babelRegisterConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require("@babel/register")({
//by default, babel register does not pull in .ts extension
extensions: [".js", ".ts"],
});
2,817 changes: 1,968 additions & 849 deletions package-lock.json

Large diffs are not rendered by default.

21 changes: 13 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"lint": "tslint --project .",
"lint:fix": "npm run lint -- --fix",
"eslint": "eslint src --ext .js",
"test": "npm-run-all -p lint eslint",
"test": "npm-run-all -p lint eslint test:unit",
"test:unit": "BABEL_ENV=test mocha --require ./babelRegisterConfig.js test/**/*.js",
"test:watch": "npm run test:unit -- --watch",
"clean": "rimraf dist",
"build": "npm-run-all clean generateSchemaTypes rollup:* -p build:ts minify:* copySchema",
"build:ts": "tsc --emitDeclarationOnly --declaration",
Expand Down Expand Up @@ -49,25 +51,28 @@
"mitt": "^1.1.3"
},
"devDependencies": {
"@babel/cli": "^7.0.0-beta.42",
"@babel/core": "^7.0.0-beta.42",
"@babel/plugin-external-helpers": "^7.0.0-beta.42",
"@babel/plugin-proposal-class-properties": "^7.0.0-beta.42",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.42",
"@babel/preset-env": "^7.0.0-beta.42",
"@babel/preset-typescript": "^7.0.0-beta.42",
"@babel/cli": "^7.0.0-beta.46",
"@babel/core": "^7.0.0-beta.46",
"@babel/plugin-external-helpers": "^7.0.0-beta.46",
"@babel/plugin-proposal-class-properties": "^7.0.0-beta.46",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.46",
"@babel/preset-env": "^7.0.0-beta.46",
"@babel/preset-typescript": "^7.0.0-beta.46",
"@babel/register": "^7.0.0-beta.46",
"@types/graphql": "^0.12.6",
"@types/lodash": "^4.14.106",
"@types/node": "^9.6.0",
"@types/recompose": "^0.24.6",
"@types/whatwg-fetch": "0.0.33",
"apollo-codegen": "^0.19.1",
"babel-plugin-lodash": "^3.3.2",
"chai": "^4.1.2",
"copy": "^0.3.1",
"eslint": "^4.19.1",
"eslint-config-synacor": "^3.0.1",
"graphql-code-generator": "^0.8.21",
"mkdirp": "^0.5.1",
"mocha": "^5.1.1",
"npm-run-all": "^4.1.2",
"prettier-eslint": "^8.8.1",
"rimraf": "^2.6.2",
Expand Down
2 changes: 1 addition & 1 deletion src/batch-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ export class ZimbraBatchClient {
this.jsonRequest({
name: 'GetPrefs',
namespace: Namespace.Account
}).then(res => res._attrs);
}).then(res => mapValuesDeep(res._attrs, coerceStringToBoolean));

public relatedContacts = ({ email }: RelatedContactsOptions) =>
this.jsonRequest({
Expand Down
2 changes: 2 additions & 0 deletions src/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,10 @@ type Preferences {
zimbraPrefCalendarInitialView: PrefCalendarInitialView
zimbraPrefCalendarReminderEmail: String
zimbraPrefCalendarWorkingHours: String
zimbraPrefDisplayExternalImages: Boolean
zimbraPrefGroupMailBy: String
zimbraPrefMailSelectAfterDelete: PrefMailSelectAfterDelete
zimbraPrefMailTrustedSenderList: [String]
zimbraPrefMarkMsgRead: Int
zimbraPrefOutOfOfficeFromDate: String
zimbraPrefOutOfOfficeReply: String
Expand Down
21 changes: 8 additions & 13 deletions src/utils/map-values-deep.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { isObject, mapValues } from 'lodash';
import { mapValues } from 'lodash';

export function mapValuesDeep(
obj: {},
callback: (v: any, k: string) => any
): {} {
return mapValues(obj, (v, k) => {
if (Array.isArray(v)) {
return v.map(v2 => mapValuesDeep(v2, callback));
} else if (isObject(v)) {
return mapValuesDeep(v, callback);
}
return callback(v, k);
});
export function mapValuesDeep(obj: {}, callback: (v: any) => any): {} {
if (typeof obj !== 'object') {
return callback(obj);
} else if (Array.isArray(obj)) {
return obj.map(v => mapValuesDeep(v, callback));
}
return mapValues(obj, v => mapValuesDeep(v, callback));
}
39 changes: 39 additions & 0 deletions test/utils/map-values-deep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import chai, { expect } from 'chai';
import { mapValuesDeep } from '../../src/utils/map-values-deep.ts';

/* eslint-env mocha */

function cb(v) {
if (typeof v === 'string') return '_' + v;
if (typeof v === 'number') return v + 1;
throw new Error('Should never see this');
}

describe('utils/mapValuesDeep()', () => {
it('should return string with callback applied when given string', () => {
expect(mapValuesDeep('foo', cb)).to.equal('_foo');
});

it('should return number with callback applied when given number', () => {
expect(mapValuesDeep(1, cb)).to.equal(2);
});

it('should apply callback to each element of an array and return an array', () => {
expect(mapValuesDeep(['foo', 1], cb)).to.eql(['_foo', 2]);
});

it('should apply callback to each value of an object and return an object with same keys', () => {
expect(mapValuesDeep({a: 'foo', b: 1}, cb)).to.eql({a: '_foo', b: 2});
});

it('should apply callback deeply', () => {
expect(mapValuesDeep({
a: [
{ b: [ 'foo', {c: 1}]}
]
}, cb)).to.eql({
a: [
{ b: [ '_foo', {c: 2} ]}
]});
})
});

0 comments on commit 480b492

Please sign in to comment.