-
Notifications
You must be signed in to change notification settings - Fork 820
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(cli-core): added tests for utils from cli-core package (#13080)
* test: add tests to isResourceNameUnique util * test: add tests for recursiveOmit util * docs: fix prettier command * docs: add git-secrets instruction * docs: fix git-secrets link * test: change test object name * chore: dependency comments for utils
- Loading branch information
1 parent
2941584
commit 1c83134
Showing
5 changed files
with
121 additions
and
2 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
104 changes: 104 additions & 0 deletions
104
packages/amplify-cli-core/src/__tests__/utils/recursiveOmit.test.ts
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,104 @@ | ||
import { recursiveOmit } from '../../utils'; | ||
import { $TSObject } from '../..'; | ||
|
||
describe('recursiveOmit', () => { | ||
let testObject: $TSObject; | ||
|
||
beforeEach(() => { | ||
testObject = { | ||
prop1: { | ||
prop2: { | ||
prop3: 'val3', | ||
prop4: 'val4', | ||
}, | ||
prop5: { | ||
prop6: 'val6', | ||
}, | ||
}, | ||
}; | ||
}); | ||
|
||
test('empty path does not mutate object', () => { | ||
const result = { | ||
prop1: { | ||
prop2: { | ||
prop3: 'val3', | ||
prop4: 'val4', | ||
}, | ||
prop5: { | ||
prop6: 'val6', | ||
}, | ||
}, | ||
}; | ||
|
||
recursiveOmit(testObject, []); | ||
expect(testObject).toEqual(result); | ||
}); | ||
|
||
test('wrong path does not mutate object', () => { | ||
const result = { | ||
prop1: { | ||
prop2: { | ||
prop3: 'val3', | ||
prop4: 'val4', | ||
}, | ||
prop5: { | ||
prop6: 'val6', | ||
}, | ||
}, | ||
}; | ||
|
||
recursiveOmit(testObject, ['prop1', 'prop7']); | ||
expect(testObject).toEqual(result); | ||
}); | ||
|
||
test('deleting a key with subkeys removes them all', () => { | ||
const result = {}; | ||
|
||
recursiveOmit(testObject, ['prop1']); | ||
expect(testObject).toEqual(result); | ||
}); | ||
|
||
test('deleting a key with subkeys does not mutate sibling keys and subkeys', () => { | ||
const result = { | ||
prop1: { | ||
prop5: { | ||
prop6: 'val6', | ||
}, | ||
}, | ||
}; | ||
|
||
recursiveOmit(testObject, ['prop1', 'prop2']); | ||
expect(testObject).toEqual(result); | ||
}); | ||
|
||
test('deleting a key in a specific path does not affect sibling keys if there are any', () => { | ||
const result = { | ||
prop1: { | ||
prop2: { | ||
prop4: 'val4', | ||
}, | ||
prop5: { | ||
prop6: 'val6', | ||
}, | ||
}, | ||
}; | ||
|
||
recursiveOmit(testObject, ['prop1', 'prop2', 'prop3']); | ||
expect(testObject).toEqual(result); | ||
}); | ||
|
||
test('deleting a key in a specific path results in deleting keys that no longer have child keys', () => { | ||
const result = { | ||
prop1: { | ||
prop2: { | ||
prop3: 'val3', | ||
prop4: 'val4', | ||
}, | ||
}, | ||
}; | ||
|
||
recursiveOmit(testObject, ['prop1', 'prop5', 'prop6']); | ||
expect(testObject).toEqual(result); | ||
}); | ||
}); |
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