feat: custom widgets (#5889)
This commit is contained in:
1 parent
48e1844b5b
commit
aecbca2b81
69 files changed
+14620
-142
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import { createServer } from "node:http";
|
||||
|
||||
import type { Server } from "node:http";
|
||||
|
||||
export interface MockApiServer {
|
||||
url: string;
|
||||
port: number;
|
||||
close: () => Promise<void>;
|
||||
}
|
||||
|
||||
export const startMockApiServerAsync = async (responseBody: unknown): Promise<MockApiServer> => {
|
||||
const body = JSON.stringify(responseBody);
|
||||
|
||||
const server: Server = await new Promise((resolve) => {
|
||||
const s = createServer((_req, res) => {
|
||||
res.writeHead(200, { "Content-Type": "application/json" });
|
||||
res.end(body);
|
||||
});
|
||||
s.listen(0, "0.0.0.0", () => resolve(s));
|
||||
});
|
||||
|
||||
const address = server.address();
|
||||
if (!address || typeof address === "string") {
|
||||
throw new Error("Failed to start mock API server");
|
||||
}
|
||||
|
||||
return {
|
||||
port: address.port,
|
||||
url: `http://host.docker.internal:${address.port}`,
|
||||
close: () =>
|
||||
new Promise((resolve, reject) => {
|
||||
server.close((error) => (error ? reject(error) : resolve()));
|
||||
}),
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,59 @@
|
||||
import { createId } from "@paralleldrive/cuid2";
|
||||
|
||||
import { hashPasswordAsync } from "../../packages/auth/security";
|
||||
import { getMaxGroupPositionAsync } from "../../packages/db/queries";
|
||||
import * as sqliteSchema from "../../packages/db/schema/sqlite";
|
||||
import { credentialsAdminGroup } from "../../packages/definitions/src/group";
|
||||
|
||||
import type { SqliteDatabase } from "./e2e-db";
|
||||
|
||||
export interface SeedAdminUserInput {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export const seedAdminUserAsync = async (db: SqliteDatabase, input: SeedAdminUserInput) => {
|
||||
const existingOnboarding = await db.query.onboarding.findFirst();
|
||||
if (existingOnboarding) {
|
||||
await db.update(sqliteSchema.onboarding).set({
|
||||
step: "finish",
|
||||
previousStep: "settings",
|
||||
});
|
||||
} else {
|
||||
await db.insert(sqliteSchema.onboarding).values({
|
||||
id: createId(),
|
||||
step: "finish",
|
||||
previousStep: "settings",
|
||||
});
|
||||
}
|
||||
|
||||
const userId = createId();
|
||||
const groupId = createId();
|
||||
const maxPosition = await getMaxGroupPositionAsync(db);
|
||||
|
||||
await db.insert(sqliteSchema.users).values({
|
||||
id: userId,
|
||||
name: input.username,
|
||||
provider: "credentials",
|
||||
password: await hashPasswordAsync(input.password),
|
||||
});
|
||||
|
||||
await db.insert(sqliteSchema.groups).values({
|
||||
id: groupId,
|
||||
name: credentialsAdminGroup,
|
||||
ownerId: userId,
|
||||
position: maxPosition + 1,
|
||||
});
|
||||
|
||||
await db.insert(sqliteSchema.groupPermissions).values({
|
||||
groupId,
|
||||
permission: "admin",
|
||||
});
|
||||
|
||||
await db.insert(sqliteSchema.groupMembers).values({
|
||||
groupId,
|
||||
userId,
|
||||
});
|
||||
|
||||
return { userId, groupId };
|
||||
};
|
||||
Reference in new issue
Block a user