refactor(db): migrate to libsql
This commit is contained in:
52 files changed
+523
-1450
No files matched your search
@@ -4,7 +4,7 @@ import { describe, expect, test, vi } from "vitest";
|
||||
import { createId } from "@homarr/common";
|
||||
import type { InferInsertModel } from "@homarr/db";
|
||||
import { boardGroupPermissions, boards, boardUserPermissions, groupMembers, groups, users } from "@homarr/db/schema";
|
||||
import { createDb } from "@homarr/db/test";
|
||||
import { createDbAsync } from "@homarr/db/test";
|
||||
|
||||
import * as integrationPermissions from "../integration-permissions";
|
||||
import { hasQueryAccessToIntegrationsAsync } from "../integration-query-permissions";
|
||||
@@ -22,7 +22,7 @@ const createSession = (user: Partial<Session["user"]>): Session => ({
|
||||
describe("hasQueryAccessToIntegrationsAsync should check if the user has query access to the specified integrations", () => {
|
||||
test("should return true if the user has the board-view-all permission and the integrations are used anywhere", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const session = createSession({
|
||||
permissions: ["board-view-all"],
|
||||
});
|
||||
@@ -50,7 +50,7 @@ describe("hasQueryAccessToIntegrationsAsync should check if the user has query a
|
||||
|
||||
test("should return true if the user has the board-view-all permission, the first integration is used and the second one he has use access", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const session = createSession({
|
||||
permissions: ["board-view-all"],
|
||||
});
|
||||
@@ -84,7 +84,7 @@ describe("hasQueryAccessToIntegrationsAsync should check if the user has query a
|
||||
|
||||
test("should return true if the user has use access to all integrations", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const session = createSession({});
|
||||
const spy = vi.spyOn(integrationPermissions, "constructIntegrationPermissions");
|
||||
spy.mockReturnValue({
|
||||
@@ -116,7 +116,7 @@ describe("hasQueryAccessToIntegrationsAsync should check if the user has query a
|
||||
|
||||
test("should return true if the user has user permission to access to at least one board of each integration", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const session = createSession({});
|
||||
await db.insert(users).values({ id: session.user.id });
|
||||
const spy = vi.spyOn(integrationPermissions, "constructIntegrationPermissions");
|
||||
@@ -168,7 +168,7 @@ describe("hasQueryAccessToIntegrationsAsync should check if the user has query a
|
||||
|
||||
test("should return false if the user has user permission to access board of first integration but not of second one", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const session = createSession({});
|
||||
await db.insert(users).values({ id: session.user.id });
|
||||
const spy = vi.spyOn(integrationPermissions, "constructIntegrationPermissions");
|
||||
@@ -215,7 +215,7 @@ describe("hasQueryAccessToIntegrationsAsync should check if the user has query a
|
||||
|
||||
test("should return true if the user has group permission to access to at least one board of each integration", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const session = createSession({});
|
||||
await db.insert(users).values({ id: session.user.id });
|
||||
const spy = vi.spyOn(integrationPermissions, "constructIntegrationPermissions");
|
||||
@@ -269,7 +269,7 @@ describe("hasQueryAccessToIntegrationsAsync should check if the user has query a
|
||||
|
||||
test("should return false if the user has group permission to access board of first integration but not of second one", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const session = createSession({});
|
||||
await db.insert(users).values({ id: session.user.id });
|
||||
const spy = vi.spyOn(integrationPermissions, "constructIntegrationPermissions");
|
||||
@@ -318,7 +318,7 @@ describe("hasQueryAccessToIntegrationsAsync should check if the user has query a
|
||||
|
||||
test("should return true if the user has user permission to access first board and group permission to access second one", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const session = createSession({});
|
||||
await db.insert(users).values({ id: session.user.id });
|
||||
const spy = vi.spyOn(integrationPermissions, "constructIntegrationPermissions");
|
||||
@@ -369,7 +369,7 @@ describe("hasQueryAccessToIntegrationsAsync should check if the user has query a
|
||||
|
||||
test("should return true if one of the boards the integration is used is public", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const session = createSession({});
|
||||
const integrations = [
|
||||
{
|
||||
@@ -413,7 +413,7 @@ describe("hasQueryAccessToIntegrationsAsync should check if the user has query a
|
||||
|
||||
test("should return true if the user is creator of the board the integration is used", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const session = createSession({});
|
||||
await db.insert(users).values({ id: session.user.id });
|
||||
const integrations = [
|
||||
@@ -458,7 +458,7 @@ describe("hasQueryAccessToIntegrationsAsync should check if the user has query a
|
||||
|
||||
test("should return false if the user has no access to any of the integrations", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const session = createSession({});
|
||||
const integrations = [
|
||||
{
|
||||
@@ -496,7 +496,7 @@ describe("hasQueryAccessToIntegrationsAsync should check if the user has query a
|
||||
|
||||
test("should return false if the user is anonymous and the board is not public", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const integrations = [
|
||||
{
|
||||
id: "1",
|
||||
@@ -534,7 +534,7 @@ describe("hasQueryAccessToIntegrationsAsync should check if the user has query a
|
||||
|
||||
test("should return true if the user is anonymous and the board is public", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const integrations = [
|
||||
{
|
||||
id: "1",
|
||||
|
||||
@@ -2,7 +2,7 @@ import { describe, expect, test } from "vitest";
|
||||
|
||||
import { createId } from "@homarr/common";
|
||||
import { users } from "@homarr/db/schema";
|
||||
import { createDb } from "@homarr/db/test";
|
||||
import { createDbAsync } from "@homarr/db/test";
|
||||
|
||||
import { createSaltAsync, hashPasswordAsync } from "../../security";
|
||||
import { authorizeWithBasicCredentialsAsync } from "../credentials/authorization/basic-authorization";
|
||||
@@ -12,7 +12,7 @@ const defaultUserId = createId();
|
||||
describe("authorizeWithBasicCredentials", () => {
|
||||
test("should authorize user with correct credentials", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const salt = await createSaltAsync();
|
||||
await db.insert(users).values({
|
||||
id: defaultUserId,
|
||||
@@ -33,7 +33,7 @@ describe("authorizeWithBasicCredentials", () => {
|
||||
|
||||
test("should not authorize user with incorrect credentials", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const salt = await createSaltAsync();
|
||||
await db.insert(users).values({
|
||||
id: defaultUserId,
|
||||
@@ -54,7 +54,7 @@ describe("authorizeWithBasicCredentials", () => {
|
||||
|
||||
test("should not authorize user with incorrect username", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const salt = await createSaltAsync();
|
||||
await db.insert(users).values({
|
||||
id: defaultUserId,
|
||||
@@ -75,7 +75,7 @@ describe("authorizeWithBasicCredentials", () => {
|
||||
|
||||
test("should not authorize user when password is not set", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
await db.insert(users).values({
|
||||
id: defaultUserId,
|
||||
name: "test",
|
||||
|
||||
@@ -5,7 +5,7 @@ import { createId } from "@homarr/common";
|
||||
import type { Database } from "@homarr/db";
|
||||
import { and, eq } from "@homarr/db";
|
||||
import { groups, users } from "@homarr/db/schema";
|
||||
import { createDb } from "@homarr/db/test";
|
||||
import { createDbAsync } from "@homarr/db/test";
|
||||
|
||||
import { authorizeWithLdapCredentialsAsync } from "../credentials/authorization/ldap-authorization";
|
||||
import * as ldapClient from "../credentials/ldap-client";
|
||||
@@ -123,7 +123,7 @@ describe("authorizeWithLdapCredentials", () => {
|
||||
|
||||
test("should authorize user with correct credentials and create user", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const spy = vi.spyOn(ldapClient, "LdapClient");
|
||||
spy.mockImplementation(function () {
|
||||
return {
|
||||
@@ -161,7 +161,7 @@ describe("authorizeWithLdapCredentials", () => {
|
||||
|
||||
test("should authorize user with correct credentials and create user with same email when credentials user already exists", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const spy = vi.spyOn(ldapClient, "LdapClient");
|
||||
spy.mockImplementation(function () {
|
||||
return {
|
||||
@@ -230,7 +230,7 @@ describe("authorizeWithLdapCredentials", () => {
|
||||
});
|
||||
|
||||
const userId = createId();
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
await db.insert(users).values({
|
||||
id: userId,
|
||||
name: "test-old",
|
||||
@@ -281,7 +281,7 @@ describe("authorizeWithLdapCredentials", () => {
|
||||
disconnectAsync: vi.fn(),
|
||||
} as unknown as ldapClient.LdapClient;
|
||||
});
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const userId = createId();
|
||||
await db.insert(users).values({
|
||||
id: userId,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { users } from "@homarr/db/schema";
|
||||
import { createDb } from "@homarr/db/test";
|
||||
import { createDbAsync } from "@homarr/db/test";
|
||||
|
||||
import { createAdapter } from "../adapter";
|
||||
|
||||
@@ -10,7 +10,7 @@ describe("createAdapter should create drizzle adapter", () => {
|
||||
"createAdapter getUserByEmail should return user for provider %s when this provider provided",
|
||||
async (provider) => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const adapter = createAdapter(db, provider);
|
||||
const email = "test@example.com";
|
||||
await db.insert(users).values({ id: "1", name: "test", email, provider });
|
||||
@@ -37,7 +37,7 @@ describe("createAdapter should create drizzle adapter", () => {
|
||||
"createAdapter getUserByEmail should return null if only for other providers than %s exist",
|
||||
async (requestedProvider, existingProviders) => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const adapter = createAdapter(db, requestedProvider);
|
||||
const email = "test@example.com";
|
||||
for (const provider of existingProviders) {
|
||||
@@ -54,7 +54,7 @@ describe("createAdapter should create drizzle adapter", () => {
|
||||
|
||||
test("createAdapter getUserByEmail should throw error if provider is unknown", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const adapter = createAdapter(db, "unknown");
|
||||
const email = "test@example.com";
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { JWT } from "next-auth/jwt";
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
|
||||
import { groupMembers, groupPermissions, groups, users } from "@homarr/db/schema";
|
||||
import { createDb } from "@homarr/db/test";
|
||||
import { createDbAsync } from "@homarr/db/test";
|
||||
import * as definitions from "@homarr/definitions";
|
||||
|
||||
import { createSessionCallback, getCurrentUserPermissionsAsync } from "../callbacks";
|
||||
@@ -20,7 +20,7 @@ vi.mock("next/headers", () => ({
|
||||
describe("getCurrentUserPermissions", () => {
|
||||
test("should return empty permissions when non existing user requested", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
|
||||
await db.insert(groups).values({
|
||||
id: "2",
|
||||
@@ -46,7 +46,7 @@ describe("getCurrentUserPermissions", () => {
|
||||
|
||||
test("should return empty permissions when user has no groups", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const userId = "1";
|
||||
|
||||
await db.insert(groups).values({
|
||||
@@ -71,7 +71,7 @@ describe("getCurrentUserPermissions", () => {
|
||||
|
||||
test("should return permissions for user", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const getPermissionsWithChildrenMock = vi
|
||||
.spyOn(definitions, "getPermissionsWithChildren")
|
||||
.mockReturnValue(["board-create"]);
|
||||
@@ -113,7 +113,7 @@ describe("session callback", () => {
|
||||
emailVerified: new Date("2023-01-13"),
|
||||
};
|
||||
const token: JWT = {};
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
const callback = createSessionCallback(db);
|
||||
|
||||
// Act
|
||||
|
||||
@@ -6,7 +6,7 @@ import { describe, expect, test, vi } from "vitest";
|
||||
import { eq } from "@homarr/db";
|
||||
import type { Database } from "@homarr/db";
|
||||
import { groupMembers, groups, users } from "@homarr/db/schema";
|
||||
import { createDb } from "@homarr/db/test";
|
||||
import { createDbAsync } from "@homarr/db/test";
|
||||
import { colorSchemeCookieKey, everyoneGroup } from "@homarr/definitions";
|
||||
|
||||
import { createSignInEventHandler } from "../events";
|
||||
@@ -39,7 +39,7 @@ describe("createSignInEventHandler should create signInEventHandler", () => {
|
||||
describe("signInEventHandler should add users to everyone group", () => {
|
||||
test("should add user to everyone group if he isn't already", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
await createUserAsync(db);
|
||||
await createGroupAsync(db, everyoneGroup);
|
||||
const eventHandler = createSignInEventHandler(db);
|
||||
@@ -62,7 +62,7 @@ describe("createSignInEventHandler should create signInEventHandler", () => {
|
||||
describe("signInEventHandler should synchronize ldap groups", () => {
|
||||
test("should add missing group membership", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
await createUserAsync(db);
|
||||
await createGroupAsync(db);
|
||||
const eventHandler = createSignInEventHandler(db);
|
||||
@@ -82,7 +82,7 @@ describe("createSignInEventHandler should create signInEventHandler", () => {
|
||||
});
|
||||
test("should remove group membership", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
await createUserAsync(db);
|
||||
await createGroupAsync(db);
|
||||
await db.insert(groupMembers).values({
|
||||
@@ -106,7 +106,7 @@ describe("createSignInEventHandler should create signInEventHandler", () => {
|
||||
});
|
||||
test("should not remove group membership for everyone group", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
await createUserAsync(db);
|
||||
await createGroupAsync(db, everyoneGroup);
|
||||
await db.insert(groupMembers).values({
|
||||
@@ -132,7 +132,7 @@ describe("createSignInEventHandler should create signInEventHandler", () => {
|
||||
describe("signInEventHandler should synchronize oidc groups", () => {
|
||||
test("should add missing group membership", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
await createUserAsync(db);
|
||||
await createGroupAsync(db);
|
||||
const eventHandler = createSignInEventHandler(db);
|
||||
@@ -152,7 +152,7 @@ describe("createSignInEventHandler should create signInEventHandler", () => {
|
||||
});
|
||||
test("should remove group membership", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
await createUserAsync(db);
|
||||
await createGroupAsync(db);
|
||||
await db.insert(groupMembers).values({
|
||||
@@ -176,7 +176,7 @@ describe("createSignInEventHandler should create signInEventHandler", () => {
|
||||
});
|
||||
test("should not remove group membership for everyone group", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
await createUserAsync(db);
|
||||
await createGroupAsync(db, everyoneGroup);
|
||||
await db.insert(groupMembers).values({
|
||||
@@ -205,7 +205,7 @@ describe("createSignInEventHandler should create signInEventHandler", () => {
|
||||
["oidc" as const, { name: "test" }, { preferred_username: "test@example.com", name: "test-new" }],
|
||||
])("signInEventHandler should update username for %s provider", async (_provider, user, profile) => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
await createUserAsync(db);
|
||||
const eventHandler = createSignInEventHandler(db);
|
||||
|
||||
@@ -227,7 +227,7 @@ describe("createSignInEventHandler should create signInEventHandler", () => {
|
||||
});
|
||||
test("signInEventHandler should set color-scheme cookie", async () => {
|
||||
// Arrange
|
||||
const db = createDb();
|
||||
const db = await createDbAsync();
|
||||
await createUserAsync(db);
|
||||
const eventHandler = createSignInEventHandler(db);
|
||||
|
||||
|
||||
Reference in new issue
Block a user