V1.2.0: archive/delete campaigns and encounters, encounter sorting, change password, fuller seed

- Campaigns: DM can archive/restore; owner can delete. Archived campaigns
  move off the main list and stop accepting invite codes.
- Encounters: DM can archive/restore and delete, and arrange the campaign's
  own order; the list can also be sorted by name, status, type or date.
  Archived encounters are hidden from players' lists.
- Account page with change password (POST /auth/password).
- Seed is now additive (safe on a live database; --reset for the old wipe)
  and builds a fuller Aldenfell: earned weapons, item pool, spells, NPCs,
  and 28 battle/quest scenes with descriptions, DM notes and rewards.
- Vite preview host config for the deployed site.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-06 08:58:54 +02:00
co-authored by Claude Opus 5.5
parent 4a6a09bae8
commit 28e1a84b64
22 changed files with 1340 additions and 94 deletions
+130
View File
@@ -1521,3 +1521,133 @@ describe('encounter combat info', () => {
expect(typeof participant.characterCombatInfo.weapons[0].attackBonus).toBe('number');
});
});
describe('changing a password', () => {
itIfDb('needs the current password, then only the new one logs in', async () => {
const email = uniqueEmail('pw');
const registerRes = await request(app).post('/auth/register').send({ email, password: 'password123', displayName: 'Pw' });
cleanupUserIds.push(registerRes.body.user.id);
const auth = { Authorization: `Bearer ${registerRes.body.token}` };
expect((await request(app).post('/auth/password').send({ currentPassword: 'password123', newPassword: 'new-password1' })).status).toBe(401);
const wrong = await request(app).post('/auth/password').set(auth).send({ currentPassword: 'nope', newPassword: 'new-password1' });
expect(wrong.status).toBe(400);
const short = await request(app).post('/auth/password').set(auth).send({ currentPassword: 'password123', newPassword: 'short' });
expect(short.status).toBe(400);
const same = await request(app).post('/auth/password').set(auth).send({ currentPassword: 'password123', newPassword: 'password123' });
expect(same.status).toBe(400);
const changed = await request(app).post('/auth/password').set(auth).send({ currentPassword: 'password123', newPassword: 'new-password1' });
expect(changed.status).toBe(204);
expect((await request(app).post('/auth/login').send({ email, password: 'password123' })).status).toBe(401);
expect((await request(app).post('/auth/login').send({ email, password: 'new-password1' })).status).toBe(200);
});
});
describe('archiving and deleting a campaign', () => {
itIfDb('the DM archives and restores; an archived campaign keeps its contents but takes no new members', async () => {
const { dmAuth, playerAuth, campaign } = await setupCampaign('archive');
const c = `/campaigns/${campaign.id}`;
expect(campaign.archivedAt).toBeNull();
expect((await request(app).patch(c).set(playerAuth).send({ archived: true })).status).toBe(403);
const archived = await request(app).patch(c).set(dmAuth).send({ archived: true });
expect(archived.status).toBe(200);
expect(archived.body.campaign.archivedAt).toBeTruthy();
// Still there for its members, and flagged in their lists.
const playerList = await request(app).get('/campaigns').set(playerAuth);
expect(playerList.body.campaigns.find((x) => x.id === campaign.id).archivedAt).toBeTruthy();
expect((await request(app).get(c).set(playerAuth)).status).toBe(200);
const outsider = await request(app)
.post('/auth/register')
.send({ email: uniqueEmail('archive-outsider'), password: 'password123', displayName: 'Outsider' });
cleanupUserIds.push(outsider.body.user.id);
const outsiderAuth = { Authorization: `Bearer ${outsider.body.token}` };
expect((await request(app).post(`/campaigns/join/${campaign.inviteCode}`).set(outsiderAuth)).status).toBe(403);
// Other settings can change without un-archiving it.
const renamed = await request(app).patch(c).set(dmAuth).send({ startingGold: 7 });
expect(renamed.body.campaign.archivedAt).toBeTruthy();
const restored = await request(app).patch(c).set(dmAuth).send({ archived: false });
expect(restored.body.campaign.archivedAt).toBeNull();
expect(restored.body.campaign.startingGold).toBe(7);
expect((await request(app).post(`/campaigns/join/${campaign.inviteCode}`).set(outsiderAuth)).status).toBe(201);
});
itIfDb('only the owner deletes, and everything in the campaign goes with it', async () => {
const { dmAuth, playerAuth, campaign } = await setupCampaign('delete');
const c = `/campaigns/${campaign.id}`;
const heroId = await buildCharacter(campaign.id, playerAuth, 'Doomed');
const encounterRes = await request(app).post(`${c}/encounters`).set(dmAuth).send({ name: 'Last Stand' });
const encounterId = encounterRes.body.encounter.id;
await request(app).post(`/encounters/${encounterId}/participants`).set(dmAuth).send({ characterId: heroId });
await request(app).post('/notes').set(dmAuth).send({ campaignId: campaign.id, body: 'Secret', visibility: 'DM_ONLY' });
expect((await request(app).delete(c).set(playerAuth)).status).toBe(403);
expect((await request(app).get(c).set(dmAuth)).status).toBe(200);
expect((await request(app).delete(c).set(dmAuth)).status).toBe(204);
expect((await request(app).get(c).set(dmAuth)).status).toBe(404);
expect((await request(app).get(`/characters/${heroId}`).set(playerAuth)).status).toBe(404);
expect((await request(app).get(`/encounters/${encounterId}`).set(dmAuth)).status).toBe(404);
expect(await prisma.note.count({ where: { campaignId: campaign.id } })).toBe(0);
const dmList = await request(app).get('/campaigns').set(dmAuth);
expect(dmList.body.campaigns.find((x) => x.id === campaign.id)).toBeUndefined();
});
});
describe('ordering, archiving and deleting encounters', () => {
itIfDb('the DM arranges the list, archives out of players\' sight, and deletes without undoing rewards', async () => {
const { dmAuth, playerAuth, campaign } = await setupCampaign('encorder');
const c = `/campaigns/${campaign.id}`;
const heroId = await buildCharacter(campaign.id, playerAuth, 'Keeper');
const ids = {};
for (const name of ['One', 'Two', 'Three']) {
ids[name] = (await request(app).post(`${c}/encounters`).set(dmAuth).send({ name })).body.encounter.id;
}
const names = async (auth) => (await request(app).get(`${c}/encounters`).set(auth)).body.encounters.map((e) => e.name);
// New encounters go to the top.
expect(await names(dmAuth)).toEqual(['Three', 'Two', 'One']);
const order = (encounterIds, auth = dmAuth) => request(app).put(`${c}/encounters/order`).set(auth).send({ encounterIds });
expect((await order([ids.One, ids.Two, ids.Three], playerAuth)).status).toBe(403);
expect((await order([ids.One, ids.One])).status).toBe(400);
expect((await order([ids.One, 'not-an-encounter'])).status).toBe(400);
expect((await order([ids.One, ids.Two, ids.Three])).status).toBe(204);
expect(await names(playerAuth)).toEqual(['One', 'Two', 'Three']);
// Archived: the DM still lists it, players don't, and it can still be opened.
expect((await request(app).patch(`/encounters/${ids.Two}`).set(playerAuth).send({ archived: true })).status).toBe(403);
const archived = await request(app).patch(`/encounters/${ids.Two}`).set(dmAuth).send({ archived: true });
expect(archived.body.encounter.archivedAt).toBeTruthy();
expect(await names(playerAuth)).toEqual(['One', 'Three']);
expect(await names(dmAuth)).toEqual(['One', 'Two', 'Three']);
expect((await request(app).get(`/encounters/${ids.Two}`).set(playerAuth)).status).toBe(200);
const restored = await request(app).patch(`/encounters/${ids.Two}`).set(dmAuth).send({ archived: false });
expect(restored.body.encounter.archivedAt).toBeNull();
expect(await names(playerAuth)).toEqual(['One', 'Two', 'Three']);
// Deleting takes the scene but leaves what it already gave out.
await request(app).post(`/encounters/${ids.One}/participants`).set(dmAuth).send({ characterId: heroId });
const rewardRes = await request(app).post(`/encounters/${ids.One}/rewards`).set(dmAuth).send({ type: 'GOLD', gold: 12 });
await request(app).post(`/encounters/${ids.One}/rewards/${rewardRes.body.reward.id}/award`).set(dmAuth).send({ characterId: heroId });
const goldBefore = (await request(app).get(`/characters/${heroId}`).set(playerAuth)).body.character.gold;
expect((await request(app).delete(`/encounters/${ids.One}`).set(playerAuth)).status).toBe(403);
expect((await request(app).delete(`/encounters/${ids.One}`).set(dmAuth)).status).toBe(204);
expect((await request(app).get(`/encounters/${ids.One}`).set(dmAuth)).status).toBe(404);
expect(await names(dmAuth)).toEqual(['Two', 'Three']);
const after = (await request(app).get(`/characters/${heroId}`).set(playerAuth)).body.character;
expect(after.gold).toBe(goldBefore);
expect(goldBefore).toBeGreaterThanOrEqual(12);
});
});