update ui and other frontend updates
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
const HONO = "http://192.168.1.225:3456";
|
||||
|
||||
async function main() {
|
||||
// Signup
|
||||
const signup = await fetch(`${HONO}/api/admin/signup`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ email: "admin2@test.com", password: "password1234", famName: "Admin Test" }),
|
||||
});
|
||||
const s = await signup.json();
|
||||
console.log("Signup:", s.famId, s.famSlug);
|
||||
const famId = s.famId;
|
||||
|
||||
// Test admin authenticated calls
|
||||
const headers = {
|
||||
"x-session-famid": famId,
|
||||
"x-session-role": "admin",
|
||||
"x-session-userid": s.userId,
|
||||
"Content-Type": "application/json",
|
||||
};
|
||||
|
||||
// Create a chore template
|
||||
console.log("\nCreate template...");
|
||||
const tmpl = await fetch(`${HONO}/api/admin/${famId}/chore-templates`, {
|
||||
method: "POST", headers, body: JSON.stringify({
|
||||
name: "Make Bed", defaultFrequency: "daily", defaultType: "points", defaultValue: 10,
|
||||
}),
|
||||
});
|
||||
const t = await tmpl.json();
|
||||
console.log("Template:", t.id, t.name);
|
||||
|
||||
// List templates
|
||||
console.log("\nList templates...");
|
||||
const list = await fetch(`${HONO}/api/admin/${famId}/chore-templates`, { headers });
|
||||
console.log("Templates:", (await list.json()).length);
|
||||
|
||||
// Create a member
|
||||
console.log("\nCreate member...");
|
||||
const mem = await fetch(`${HONO}/api/admin/${famId}/members`, {
|
||||
method: "POST", headers, body: JSON.stringify({ name: "Kid", color: "#6366f1" }),
|
||||
});
|
||||
const m = await mem.json();
|
||||
console.log("Member:", m.id, m.name);
|
||||
|
||||
// Assign chore
|
||||
console.log("\nAssign chore...");
|
||||
const assign = await fetch(`${HONO}/api/admin/${famId}/assigned-chores`, {
|
||||
method: "POST", headers, body: JSON.stringify({
|
||||
memberId: m.id, templateId: t.id, frequency: "daily", type: "points", value: 10,
|
||||
}),
|
||||
});
|
||||
const a = await assign.json();
|
||||
console.log("Assigned:", a.id);
|
||||
|
||||
// Test device token auth
|
||||
console.log("\nTest completion toggle with device token...");
|
||||
const devHeaders = {
|
||||
"x-device-token": "dev-token-test",
|
||||
"x-device-famid": famId,
|
||||
"Content-Type": "application/json",
|
||||
};
|
||||
// First need to join with this device token
|
||||
const join = await fetch(`${HONO}/api/members/join`, {
|
||||
method: "POST", headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ inviteCode: s.famSlug, ...(await (await fetch(`${HONO}/api/admin/${famId}/members`, { headers })).json()).length > 1 ? {} : { name: "Test", deviceToken: "dev-token-test" } }),
|
||||
});
|
||||
// Actually, just use the member we already created but we can't use device token with it since it has no token
|
||||
// Let's join a new one
|
||||
console.log("Joining with device token...");
|
||||
const j = await fetch(`${HONO}/api/members/join`, {
|
||||
method: "POST", headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ inviteCode: "TEST", name: "Test Kid", deviceToken: "dev-token-test" }),
|
||||
});
|
||||
const joinData = await j.json();
|
||||
console.log("Join result:", JSON.stringify(joinData));
|
||||
|
||||
if (joinData.famId) {
|
||||
// Toggle completion
|
||||
console.log("\nToggle completion...");
|
||||
const toggle = await fetch(`${HONO}/api/completions/toggle`, {
|
||||
method: "POST",
|
||||
headers: { "x-device-token": "dev-token-test", "x-device-famid": famId, "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ assignedChoreId: a.id, date: "2026-06-24" }),
|
||||
});
|
||||
console.log("Toggle:", await toggle.json());
|
||||
|
||||
// Toggle again (should undo)
|
||||
const toggle2 = await fetch(`${HONO}/api/completions/toggle`, {
|
||||
method: "POST",
|
||||
headers: { "x-device-token": "dev-token-test", "x-device-famid": famId, "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ assignedChoreId: a.id, date: "2026-06-24" }),
|
||||
});
|
||||
console.log("Toggle undo:", await toggle2.json());
|
||||
}
|
||||
|
||||
console.log("\n✅ All admin tests passed");
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
Reference in New Issue
Block a user