1 files changed, 35 insertions, 0 deletions
diff --git a/src/util/jwtUtils.test.js b/src/util/jwtUtils.test.js
new file mode 100644
index 0000000..94a7d99
--- /dev/null
+++ b/src/util/jwtUtils.test.js
@@ -0,0 +1,35 @@
+import { it } from 'node:test';
+import { initJwt, generateJwtToken, validateJwtToken } from './jwtUtils.js';
+import * as dotenv from 'dotenv';
+import { tmpdir } from 'node:os';
+import { mkdtemp } from 'node:fs/promises';
+import * as assert from 'node:assert';
+dotenv.config();
+
+const user = {
+ _id: 'meow',
+ username: 'testuser'
+};
+
+await it('Should be able to generate new secrets', async () => {
+ process.env.JWT_SECRET_PATH = await mkdtemp(tmpdir());
+ await initJwt();
+});
+
+await it('Should be able to load the JWT utils', async () => {
+ process.env.JWT_SECRET_PATH = await mkdtemp(tmpdir());
+ await initJwt();
+ await initJwt();
+});
+
+it('Should be able to create a JWT token', async () => {
+ await initJwt();
+ await generateJwtToken(user);
+});
+
+it('Should be able to validate a JWT token', async () => {
+ await initJwt();
+ const token = await generateJwtToken(user);
+ const result = await validateJwtToken(token);
+ console.log(result);
+});
|