-
Notifications
You must be signed in to change notification settings - Fork 0
/
captchaLogic.test.ts
31 lines (24 loc) · 1.07 KB
/
captchaLogic.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* @jest-environment node
*/
import { createCapcha, solveCaptcha } from "./captchaLogic";
describe("emailCaptcha.ts", () => {
beforeAll(() => {
const { TextEncoder, TextDecoder } = require('util');
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;
global.crypto = require("crypto").webcrypto;
})
it("can create captchas and returns the answer again when solved correctly", async () => {
const secret = "You've revealed the secret!";
const captcha = await createCapcha({ enUs: "What's 2*9?", deDe: "Was ist 2*9?" }, "18", secret);
const retrievedSecret = await solveCaptcha(captcha, "18");
expect(retrievedSecret).toBe(secret);
});
it("fails to decrypt without the right answer", async () => {
const secret = "You've revealed the secret!";
const captcha = await createCapcha({ enUs: "What's 2*9?", deDe: "Was ist 2*9?" }, "18", secret);
const retrievedSecret = await solveCaptcha(captcha, "Keine Ahnung");
expect(retrievedSecret).toBeNull();
});
});