Skip to content

Commit

Permalink
Add tests for splitCollectionMemberKey
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioh8010 committed Dec 9, 2024
1 parent e58ddf1 commit 4c5a3b0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/unit/onyxUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ describe('OnyxUtils', () => {
OnyxUtils.splitCollectionMemberKey('');
}).toThrowError("Invalid '' key provided, only collection keys are allowed.");
});

it('should allow passing the collection key beforehand for performance gains', () => {
const [collectionKey, id] = OnyxUtils.splitCollectionMemberKey(`${ONYXKEYS.COLLECTION.TEST_KEY}id1`, ONYXKEYS.COLLECTION.TEST_KEY);
expect(collectionKey).toEqual(ONYXKEYS.COLLECTION.TEST_KEY);
expect(id).toEqual('id1');
});

it("should throw error if the passed collection key isn't compatible with the key", () => {
expect(() => {
OnyxUtils.splitCollectionMemberKey(`${ONYXKEYS.COLLECTION.TEST_KEY}id1`, ONYXKEYS.COLLECTION.TEST_LEVEL_KEY);
}).toThrowError("Invalid 'test_level_' collection key provided, it isn't compatible with 'test_id1' key.");
});
});

describe('getCollectionKey', () => {
Expand Down

0 comments on commit 4c5a3b0

Please sign in to comment.