-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1082 from adobe/fixPropositionsReturnValue
Fix propositions return value
- Loading branch information
Showing
16 changed files
with
145 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
Copyright 2023 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
import assign from "./assign"; | ||
import isObject from "./isObject"; | ||
|
||
export default (...values) => { | ||
if (values.length < 2) { | ||
// if the number of args is 0 or 1, just use the default behavior from Object.assign | ||
return assign(...values); | ||
} | ||
return values.reduce((accumulator, currentValue) => { | ||
if (isObject(currentValue)) { | ||
Object.keys(currentValue).forEach(key => { | ||
if (Array.isArray(currentValue[key])) { | ||
if (Array.isArray(accumulator[key])) { | ||
accumulator[key].push(...currentValue[key]); | ||
} else { | ||
// clone the array so the original isn't modified. | ||
accumulator[key] = [...currentValue[key]]; | ||
} | ||
} else { | ||
accumulator[key] = currentValue[key]; | ||
} | ||
}); | ||
} | ||
return accumulator; | ||
}); // no default value to pass into reduce because we want to skip the first value | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,9 @@ describe("mergeLifecycleResponses", () => { | |
] | ||
} | ||
] | ||
}, | ||
{ | ||
propositions: [] | ||
} | ||
] | ||
]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import assignConcatArrayValues from "../../../../src/utils/assignConcatArrayValues"; | ||
|
||
describe("assignConcatArrayValues", () => { | ||
it("throws an error if no arguments are passed", () => { | ||
expect(() => assignConcatArrayValues()).toThrowError(); | ||
}); | ||
|
||
it("returns an empty array if an empty array is passed", () => { | ||
const obj = []; | ||
expect(assignConcatArrayValues(obj)).toBe(obj); | ||
}); | ||
|
||
it("returns the first object if only one argument is passed", () => { | ||
const obj = {}; | ||
expect(assignConcatArrayValues(obj)).toBe(obj); | ||
}); | ||
|
||
it("works with two objects with different properties", () => { | ||
const obj1 = { a: 1 }; | ||
const obj2 = { b: 2 }; | ||
const result = assignConcatArrayValues(obj1, obj2); | ||
expect(result).toEqual({ a: 1, b: 2 }); | ||
expect(result).toBe(obj1); | ||
}); | ||
|
||
it("works with two objects with the same property", () => { | ||
expect(assignConcatArrayValues({ a: 1 }, { a: 2 })).toEqual({ a: 2 }); | ||
}); | ||
|
||
it("works with two objects with the same property that is an array", () => { | ||
expect(assignConcatArrayValues({ a: [1] }, { a: [2] })).toEqual({ | ||
a: [1, 2] | ||
}); | ||
}); | ||
|
||
it("works with three objects with the same property that is an array", () => { | ||
expect(assignConcatArrayValues({ a: [1] }, { a: [] }, { a: [3] })).toEqual({ | ||
a: [1, 3] | ||
}); | ||
}); | ||
|
||
it("works with three objects with the same property that is an array and different properties", () => { | ||
expect( | ||
assignConcatArrayValues( | ||
{ a: [1] }, | ||
{ a: [], c: true, d: false }, | ||
{ a: [3], b: "2", e: null } | ||
) | ||
).toEqual({ | ||
a: [1, 3], | ||
b: "2", | ||
c: true, | ||
d: false, | ||
e: null | ||
}); | ||
}); | ||
|
||
it("skips non-objects", () => { | ||
expect( | ||
assignConcatArrayValues({ a: [1] }, null, { a: [3] }, false, [], 5) | ||
).toEqual({ | ||
a: [1, 3] | ||
}); | ||
}); | ||
}); |