Skip to content

Commit 49380a2

Browse files
committed
test: add tests for KeyObject returns and invalid options
1 parent 371400b commit 49380a2

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

test/generateKeyPair.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ describe("Test generateKeyPair()", () => {
1111
expect(isCryptoKey(secret.privateKey)).toEqual(true);
1212
});
1313

14+
test("should return an error if an invalid option property is passed as an argument", async () => {
15+
const invalidProperty = 'notValidProperty';
16+
17+
try {
18+
await generateKeyPair('RS256', { [invalidProperty]: true });
19+
} catch (error) {
20+
if (error instanceof Error) {
21+
expect(error.message).toBe(`${invalidProperty} is not a valid option for generateKeyPair()`);
22+
}
23+
}
24+
});
25+
1426
test("should return an error if an invalid algorithm is placed as an argument", async () => {
1527
try {
1628
await generateKeyPair('HS256');

test/generateSecret.test.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isCryptoKey } from "util/types";
1+
import { isCryptoKey, isKeyObject } from "util/types";
22

33
import { SYNC_ALGS } from "../src/algorithms";
44
import generateSecret from "../src/generateSecret";
@@ -10,6 +10,24 @@ describe("Test generateSecret()", () => {
1010
expect(isCryptoKey(secret)).toEqual(true);
1111
});
1212

13+
test("should return a KeyObject", async () => {
14+
const secret = await generateSecret('A128KW', { toKeyObject: true });
15+
16+
expect(isKeyObject(secret)).toEqual(true);
17+
});
18+
19+
test("should return an error if an invalid option property is passed as an argument", async () => {
20+
const invalidProperty = 'notValidProperty';
21+
22+
try {
23+
await generateSecret('HS256', { [invalidProperty]: true });
24+
} catch (error) {
25+
if (error instanceof Error) {
26+
expect(error.message).toBe(`${invalidProperty} is not a valid option for generateSecret()`);
27+
}
28+
}
29+
});
30+
1331
test("should return an error if an invalid algorithm is placed as an argument", async () => {
1432
try {
1533
await generateSecret('RS256');

0 commit comments

Comments
 (0)