1
0
silverbullet/packages/server/auth.test.ts
Zef Hemel 098a419ff3 Work
2022-04-29 18:54:27 +02:00

30 lines
722 B
TypeScript

import { beforeEach, afterEach, expect, test } from "@jest/globals";
import { unlink } from "fs/promises";
import knex, { Knex } from "knex";
import { Authenticator } from "./auth";
let db: Knex<any, unknown[]> | undefined;
beforeEach(async () => {
db = knex({
client: "better-sqlite3",
connection: {
filename: "test.db",
},
useNullAsDefault: true,
});
});
afterEach(async () => {
db!.destroy();
await unlink("test.db");
});
test("Test auth", async () => {
let auth = new Authenticator(db!);
await auth.ensureTables();
await auth.createAccount("admin", "admin");
expect(await auth.verify("admin", "admin")).toBe(true);
expect(await auth.verify("admin", "sup")).toBe(false);
});