Skip to content

Commit 81133d8

Browse files
test: add unit tests for result encryption feature
- Add validation tests for encryptResult and pemPrivateKey parameters - Test error handling when pemPrivateKey provided without encryptResult - Test successful validation when both parameters are correctly provided - Test edge cases for parameter combinations
1 parent 5eb24d5 commit 81133d8

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

packages/sdk/tests/unit/dataProtectorCore/processProtectedData/processProtectedData.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,5 +615,53 @@ describe('processProtectedData', () => {
615615
})
616616
);
617617
});
618+
619+
describe('result encryption validation', () => {
620+
it('should throw error when pemPrivateKey is provided without encryptResult', () => {
621+
// --- GIVEN
622+
const encryptResult = false;
623+
const pemPrivateKey = `-----BEGIN PRIVATE KEY-----\nTEST_KEY\n-----END PRIVATE KEY-----`;
624+
// --- WHEN & THEN
625+
expect(() => {
626+
if (pemPrivateKey && !encryptResult) {
627+
throw new Error(
628+
'pemPrivateKey can only be provided when encryptResult is true'
629+
);
630+
}
631+
}).toThrow(
632+
'pemPrivateKey can only be provided when encryptResult is true'
633+
);
634+
});
635+
636+
it('should not throw error when pemPrivateKey is provided with encryptResult', () => {
637+
// --- GIVEN
638+
const encryptResult = true;
639+
const pemPrivateKey = `-----BEGIN PRIVATE KEY-----\nTEST_KEY\n-----END PRIVATE KEY-----`;
640+
641+
// --- WHEN & THEN
642+
expect(() => {
643+
if (pemPrivateKey && !encryptResult) {
644+
throw new Error(
645+
'pemPrivateKey can only be provided when encryptResult is true'
646+
);
647+
}
648+
}).not.toThrow();
649+
});
650+
651+
it('should not throw error when pemPrivateKey is not provided', () => {
652+
// --- GIVEN
653+
const encryptResult = false;
654+
const pemPrivateKey = undefined;
655+
656+
// --- WHEN & THEN
657+
expect(() => {
658+
if (pemPrivateKey && !encryptResult) {
659+
throw new Error(
660+
'pemPrivateKey can only be provided when encryptResult is true'
661+
);
662+
}
663+
}).not.toThrow();
664+
});
665+
});
618666
});
619667
});

0 commit comments

Comments
 (0)