diff --git a/app/src/common/libs/lodash_mixins.ts b/app/src/common/libs/lodash_mixins.ts new file mode 100644 index 00000000..3116a1b8 --- /dev/null +++ b/app/src/common/libs/lodash_mixins.ts @@ -0,0 +1,37 @@ +declare module _ { + interface LoDashStatic { + compactObject(object:T, removeFunctions?:boolean):T; + } +} + +namespace common.libs { + + /** + * lodash_mixins.ts + * Add mixins (additional functions) to lodash. Call them with _.[fn_name](params) + * See http://lodash.com/docs#mixin for more info + */ + + _.mixin({ + + /** + * Get an object with all falsy values removed + * @returns {Object} + * @param object + * @param removeFunctions + */ + compactObject : (object:Object, removeFunctions:boolean = false):Object => { + var clone = _.clone(object); + _.each(clone, function(value, key) { + if(!value || removeFunctions && _.isFunction(value)) { + delete clone[key]; + } + }); + return clone; + } + + + }); + + +} \ No newline at end of file diff --git a/app/src/common/services/user/userService.spec.ts b/app/src/common/services/user/userService.spec.ts index 7e9fe9cc..5ce2bce0 100644 --- a/app/src/common/services/user/userService.spec.ts +++ b/app/src/common/services/user/userService.spec.ts @@ -124,10 +124,9 @@ it('should be able to create a new user and attempt login immediately', () => { - let user = _.clone(fixtures.user); + let user = _.compactObject(fixtures.user); delete user._self; - $httpBackend.expectPUT(/\/api\/users\/.+/, (requestObj) => { return _.isEqual(_.keys(user), _.keys(JSON.parse(requestObj))); //as we are not aware of what the userId or userCredentialId is we cannot test full equality }).respond(204);