test(server): add server tests

This commit is contained in:
2025-07-06 18:41:41 +02:00
parent 4fa46488c8
commit a744d97bb9
3 changed files with 39 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
/** @type {import('jest').Config} */
module.exports = {
transform: {
"^.+\\.(t|j)sx?$": "@swc/jest",
},
};

View File

@@ -4,7 +4,8 @@
"module": "dist/lib.js", "module": "dist/lib.js",
"types": "dist/lib.d.ts", "types": "dist/lib.d.ts",
"scripts": { "scripts": {
"build": "tsc -p tsconfig.build.json" "build": "tsc -p tsconfig.build.json",
"test": "jest"
}, },
"dependencies": { "dependencies": {
"@pow-captcha/solver": "workspace:*", "@pow-captcha/solver": "workspace:*",

View File

@@ -0,0 +1,31 @@
import { describe, it, expect } from "@jest/globals";
import { wire } from "@pow-captcha/shared";
import * as server from "./lib";
const SECRET = "e2c0b4ab-a215-4b36-bba8-19fae1601045";
describe("server", () => {
it("createChallenges ok", async () => {
const challengesSigned = await server.createChallenges({}, SECRET);
await wire.verifyAndDeserializeData(
challengesSigned,
wire.challengeSchema,
SECRET,
);
});
it("createChallenges wrong secret", async () => {
const challengesSigned = await server.createChallenges({}, SECRET);
await expect(
(async () => {
await wire.verifyAndDeserializeData(
challengesSigned,
wire.challengeSchema,
"wrong-secret",
);
})(),
).rejects.toThrow("Signed data verification failed, hash mismatch");
});
});