test(server): add server tests
This commit is contained in:
6
pkgs/server/jest.config.js
Normal file
6
pkgs/server/jest.config.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
/** @type {import('jest').Config} */
|
||||||
|
module.exports = {
|
||||||
|
transform: {
|
||||||
|
"^.+\\.(t|j)sx?$": "@swc/jest",
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -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:*",
|
||||||
|
|||||||
31
pkgs/server/src/lib.spec.ts
Normal file
31
pkgs/server/src/lib.spec.ts
Normal 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");
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user