Hello from MCP server
import { check, getApi, getPb, wait, waitMs, users } from "./common.js";
export async function updateActiveOrgTests(api) {
const testUser = {
email: "updateorg.test@planetexpress.com",
password: "testpassword123",
name: "Update Org Test User",
};
const orgAOwner = {
email: "firsta@company.com",
password: "firstpassword123",
name: "First Company CEO",
org: "First Company",
orgId: "",
};
const orgBOwner = {
email: "seconda@company.com",
password: "secondpassword123",
name: "Second Company CEO",
org: "Second Company",
orgId: "",
};
// Setup: Register users and create organizations
await check(async () => {
await api.register(testUser);
await api.register(orgAOwner);
await api.register(orgBOwner);
const responseA = await api.createOrg(orgAOwner, orgAOwner.org);
const responseB = await api.createOrg(orgBOwner, orgBOwner.org);
console.log(responseA.id);
orgAOwner.orgId = responseA.id;
orgBOwner.orgId = responseB.id;
// User joins both organizations
console.log(orgAOwner.orgId);
await api.joinOrg(testUser, orgAOwner.orgId);
await api.joinOrg(testUser, orgBOwner.orgId); // activeOrg should be Second Company
//
return true;
}, "Setup users and organizations, user joins both");
await check(async () => {
// Test user manually changes activeOrg back to First Company via PocketBase client
await api.login(testUser);
const pb = api.pb;
const updatedUser = await pb
.collection("users")
.update(pb.authStore.record.id, {
activeOrg: orgAOwner.orgId,
});
if (updatedUser.activeOrg !== orgAOwner.orgId) {
throw new Error("Failed to update user's activeOrg to First Company");
}
return updatedUser;
}, "User can manually update activeOrg via PocketBase client");
await check(async () => {
// Verify the change persists after re-login
await api.login(testUser);
const pb = api.pb;
if (pb.authStore.record.activeOrg !== orgAOwner.orgId) {
throw new Error("activeOrg change should persist after re-login");
}
return pb.authStore.record;
}, "activeOrg change persists after re-login");
}