Remove inter-session waiting period for immediate sequential access

- Set SESSION_UNLOCK_INTERVAL_MS to 0 in backend and frontend.
- Allow immediate access to next eligible session upon completing previous sessions.
- Preserve all session prerequisites, assignment unlock logic, and participant progress.
- Update tests to verify immediate session unlock and assignment availability.
This commit is contained in:
ar.badiei
2026-10-14 19:42:54 +03:30
parent 8c37c15697
commit a3a9f2664b
5 changed files with 294 additions and 40 deletions
+26 -34
View File
@@ -143,14 +143,7 @@ describe('assignments API', () => {
});
assert.equal((list.body.data?.assignments as unknown[]).length, 1);
// Backdate session 2 completion so session 3 unlocks (24h gate for order >= 3)
await prisma.sessionProgress.update({
where: {
userId_sessionOrder: { userId: owner.user.id, sessionOrder: 2 },
},
data: { completedAt: new Date(Date.now() - 25 * 60 * 60 * 1000) },
});
// Session 3 is unlocked immediately (no 24h waiting period)
// Incomplete homework must NOT block starting session 3
const chat3 = await requestJson(app, '/chat/sessions', {
method: 'POST',
@@ -363,12 +356,8 @@ describe('assignments API', () => {
await openChatAndComplete(token, 1);
await openChatAndComplete(token, 2);
// Unlock sessions 3–10 by backdating previous completions as we go
// Unlock sessions 3–10 sequentially without cooldown delays
for (let order = 3; order <= 10; order += 1) {
await prisma.sessionProgress.updateMany({
where: { userId: user.id, sessionOrder: order - 1 },
data: { completedAt: new Date(Date.now() - 25 * 60 * 60 * 1000) },
});
await openChatAndComplete(token, order);
}
@@ -472,13 +461,13 @@ describe('assignments API', () => {
await openChatAndComplete(token, 2);
// completeSession helper only asserts 200 — fetch progress for cooldown fields
// With waiting period removed, no cooldown is set
const progress = await requestJson(app, '/sessions/progress', {
headers: authHeader(token),
});
assert.equal(progress.status, 200);
assert.ok(progress.body.data?.waitingForSessionOrder === 3);
assert.ok(progress.body.data?.nextSessionUnlocksAt);
assert.equal(progress.body.data?.waitingForSessionOrder, null);
assert.equal(progress.body.data?.nextSessionUnlocksAt, null);
// Re-complete to read unlockedAssignments payload from complete endpoint
const redo = await requestJson(app, '/sessions/2/complete', {
@@ -508,7 +497,7 @@ describe('assignments API', () => {
assert.equal(joy.lockReason, null);
assert.ok(joy.userAssignment?.id);
// Session 3 still locked by cooldown — must NOT block assignment 1
// Session 3 is unlocked immediately (no 24h wait)
const sessions = await requestJson(app, '/sessions', {
headers: authHeader(token),
});
@@ -518,18 +507,19 @@ describe('assignments API', () => {
unlocksAt?: string | null;
}>;
const s3 = sessionList.find((s) => s.order === 3)!;
assert.equal(s3.unlocked, false);
assert.ok(s3.unlocksAt);
assert.equal(s3.unlocked, true);
assert.equal(s3.unlocksAt, null);
// Opening cooldown (simulate later unlock of session 3) must not change assignment-1 state
await prisma.sessionProgress.update({
where: { userId_sessionOrder: { userId: user.id, sessionOrder: 2 } },
data: { completedAt: new Date(Date.now() - 25 * 60 * 60 * 1000) },
});
const sessionsAfter = await requestJson(app, '/sessions', {
// Prerequisites still hold: Session 4 is NOT unlocked yet
const s4 = sessionList.find((s) => s.order === 4)!;
assert.equal(s4.unlocked, false);
// Complete session 3 immediately without any time delay
await openChatAndComplete(token, 3);
const sessionsAfter3 = await requestJson(app, '/sessions', {
headers: authHeader(token),
});
const s3After = (sessionsAfter.body.data as typeof sessionList).find((s) => s.order === 3)!;
const s3After = (sessionsAfter3.body.data as typeof sessionList).find((s) => s.order === 3)!;
assert.equal(s3After.unlocked, true);
catalog = await requestJson(app, '/assignments/catalog', {
@@ -539,18 +529,18 @@ describe('assignments API', () => {
const joyAfter = items.find((i) => i.definition.key === 'joy-activities')!;
assert.equal(joyAfter.unlocked, true);
assert.equal(joyAfter.userAssignment?.id, joy.userAssignment?.id);
// Assignment 2 (meaning) is now unlocked immediately on session 3 complete
const meaningAfter3 = items.find((i) => i.definition.key === 'meaning-purpose')!;
assert.equal(meaningAfter3.unlocked, true);
assert.equal(
items.filter((i) => i.unlocked).length,
1,
'unlocking session 3 must not unlock later assignments',
2,
'unlocking session 3 must not unlock later assignments (session 4+)',
);
// Mid assignment: تکلیف پنجم (displayOrder 5 / sessionOrder 6) after completing session 6
for (let order = 3; order <= 6; order += 1) {
await prisma.sessionProgress.updateMany({
where: { userId: user.id, sessionOrder: order - 1 },
data: { completedAt: new Date(Date.now() - 25 * 60 * 60 * 1000) },
});
for (let order = 4; order <= 6; order += 1) {
await openChatAndComplete(token, order);
}
@@ -568,7 +558,9 @@ describe('assignments API', () => {
headers: authHeader(token),
});
const s7 = (sessionsMid.body.data as typeof sessionList).find((s) => s.order === 7)!;
assert.equal(s7.unlocked, false, 'session 7 may still be on cooldown');
assert.equal(s7.unlocked, true, 'session 7 unlocks immediately after session 6 completion');
const s8 = (sessionsMid.body.data as typeof sessionList).find((s) => s.order === 8)!;
assert.equal(s8.unlocked, false, 'session 8 remains locked until session 7 is completed');
assert.equal(
items.find((i) => i.definition.sessionOrder === 7)?.unlocked,
false,