-
Notifications
You must be signed in to change notification settings - Fork 3
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 #27 from superfaceai/hotfix/incorrect-array-merging
Hotfix/incorrect array merging
- Loading branch information
Showing
3 changed files
with
122 additions
and
3 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,108 @@ | ||
import { | ||
assertIsVariables, | ||
isNonPrimitive, | ||
isPrimitive, | ||
mergeVariables, | ||
} from './variables'; | ||
|
||
describe('Variables', () => { | ||
test('assertIsVariables works correctly', () => { | ||
expect(() => assertIsVariables('string')).not.toThrow(); | ||
expect(() => assertIsVariables(123)).not.toThrow(); | ||
expect(() => assertIsVariables({ x: 1 })).not.toThrow(); | ||
expect(() => assertIsVariables(true)).not.toThrow(); | ||
expect(() => assertIsVariables(undefined)).not.toThrow(); | ||
expect(() => assertIsVariables(['heeelo'])).not.toThrow(); | ||
expect(() => assertIsVariables(() => 'boom!')).toThrow(); | ||
}); | ||
|
||
test('isPrimitive works correctly', () => { | ||
expect(isPrimitive('string')).toBe(true); | ||
expect(isPrimitive(123)).toBe(true); | ||
expect(isPrimitive(false)).toBe(true); | ||
expect(isPrimitive(['heeeelo'])).toBe(true); | ||
expect(isPrimitive({ x: 1 })).toBe(false); | ||
}); | ||
|
||
test('isNonPrimitive works correctly', () => { | ||
expect(isNonPrimitive('string')).toBe(false); | ||
expect(isNonPrimitive(123)).toBe(false); | ||
expect(isNonPrimitive(false)).toBe(false); | ||
expect(isNonPrimitive(['heeeelo'])).toBe(false); | ||
expect(isNonPrimitive({ x: 1 })).toBe(true); | ||
}); | ||
|
||
describe('mergeVariables', () => { | ||
it('should correctly merge two simple objects', () => { | ||
{ | ||
const left = {}; | ||
const right = { x: 1 }; | ||
const result = mergeVariables(left, right); | ||
|
||
expect(result).toEqual({ x: 1 }); | ||
} | ||
{ | ||
const left = { y: 2 }; | ||
const right = {}; | ||
const result = mergeVariables(left, right); | ||
|
||
expect(result).toEqual({ y: 2 }); | ||
} | ||
{ | ||
const left = { y: 2 }; | ||
const right = { x: 1 }; | ||
const result = mergeVariables(left, right); | ||
|
||
expect(result).toEqual({ x: 1, y: 2 }); | ||
} | ||
}); | ||
|
||
it('should correctly merge complex objects', () => { | ||
{ | ||
const left = {}; | ||
const right = { ne: { st: 'ed' } }; | ||
const result = mergeVariables(left, right); | ||
|
||
expect(result).toEqual({ ne: { st: 'ed' } }); | ||
} | ||
{ | ||
const left = { not: 'nested' }; | ||
const right = { ne: { st: 'ed' } }; | ||
const result = mergeVariables(left, right); | ||
|
||
expect(result).toEqual({ ne: { st: 'ed' }, not: 'nested' }); | ||
} | ||
{ | ||
const left = { ne: { est: 'eed' } }; | ||
const right = { ne: { st: 'ed' } }; | ||
const result = mergeVariables(left, right); | ||
|
||
expect(result).toEqual({ ne: { st: 'ed', est: 'eed' } }); | ||
} | ||
}); | ||
|
||
it('should overwrite from left to right', () => { | ||
{ | ||
const left = { overwritten: false }; | ||
const right = { overwritten: true }; | ||
const result = mergeVariables(left, right); | ||
|
||
expect(result).toEqual({ overwritten: true }); | ||
} | ||
{ | ||
const left = { overwritten: { yes: false, no: false } }; | ||
const right = { overwritten: { yes: true } }; | ||
const result = mergeVariables(left, right); | ||
|
||
expect(result).toEqual({ overwritten: { yes: true, no: false } }); | ||
} | ||
{ | ||
const left = { overwritten: 7 }; | ||
const right = { overwritten: ['seven'] }; | ||
const result = mergeVariables(left, right); | ||
|
||
expect(result).toEqual({ overwritten: ['seven'] }); | ||
} | ||
}); | ||
}); | ||
}); |
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