Skip to content

Commit 6b60eb6

Browse files
committed
Temporarily disable audit log migrator in prod because it's causing problems and isn't super necessary.
1 parent 24849e1 commit 6b60eb6

File tree

3 files changed

+118
-1
lines changed

3 files changed

+118
-1
lines changed

data-migration/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async function main() {
5252

5353
// Register migrators in any order (they'll be sorted by priority)
5454
const migrators = [
55-
new AuditLogMigrator(),
55+
// new AuditLogMigrator(),
5656
new ChallengeConstraintMigrator(),
5757
new ChallengeDiscussionOptionMigrator(),
5858
new ChallengeEventMigrator(),

src/services/ChallengePhaseService.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,25 @@ async function partiallyUpdateChallengePhase(currentUser, challengeId, id, data)
243243
}
244244
}
245245

246+
const isOpeningPhase = "isOpen" in data && data["isOpen"] === true;
247+
const predecessorId = data["predecessor"] || challengePhase.predecessor;
248+
if (isOpeningPhase && predecessorId) {
249+
const predecessorPhase = await prisma.challengePhase.findFirst({
250+
where: { challengeId, id: predecessorId },
251+
});
252+
253+
if (
254+
!predecessorPhase ||
255+
predecessorPhase.isOpen ||
256+
_.isNil(predecessorPhase.actualStartDate) ||
257+
_.isNil(predecessorPhase.actualEndDate)
258+
) {
259+
throw new errors.BadRequestError(
260+
"Cannot open phase because predecessor phase must be closed with both actualStartDate and actualEndDate set"
261+
);
262+
}
263+
}
264+
246265
if (data["scheduledStartDate"] || data["scheduledEndDate"]) {
247266
const startDate = data["scheduledStartDate"] || challengePhase.scheduledStartDate;
248267
const endDate = data["scheduledEndDate"] || challengePhase.scheduledEndDate;

test/unit/ChallengePhaseService.test.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,104 @@ describe('challenge phase service unit tests', () => {
335335
}
336336
throw new Error('should not reach here')
337337
})
338+
339+
it('partially update challenge phase - cannot open phase when predecessor is not closed', async () => {
340+
await prisma.challengePhase.update({
341+
where: { id: data.challengePhase1Id },
342+
data: { isOpen: true }
343+
})
344+
345+
try {
346+
await service.partiallyUpdateChallengePhase(authUser, data.challenge.id, data.challengePhase2Id, { isOpen: true })
347+
} catch (e) {
348+
should.equal(
349+
e.message,
350+
'Cannot open phase because predecessor phase must be closed with both actualStartDate and actualEndDate set'
351+
)
352+
return
353+
}
354+
throw new Error('should not reach here')
355+
})
356+
357+
it('partially update challenge phase - cannot open phase when predecessor has no actualEndDate', async () => {
358+
const startDate = new Date('2025-01-01T00:00:00.000Z')
359+
await prisma.challengePhase.update({
360+
where: { id: data.challengePhase1Id },
361+
data: {
362+
isOpen: false,
363+
actualStartDate: startDate,
364+
actualEndDate: null
365+
}
366+
})
367+
368+
try {
369+
await service.partiallyUpdateChallengePhase(authUser, data.challenge.id, data.challengePhase2Id, { isOpen: true })
370+
} catch (e) {
371+
should.equal(
372+
e.message,
373+
'Cannot open phase because predecessor phase must be closed with both actualStartDate and actualEndDate set'
374+
)
375+
return
376+
}
377+
throw new Error('should not reach here')
378+
})
379+
380+
it('partially update challenge phase - cannot open phase when predecessor has no actualStartDate', async () => {
381+
const endDate = new Date('2025-01-02T00:00:00.000Z')
382+
await prisma.challengePhase.update({
383+
where: { id: data.challengePhase1Id },
384+
data: {
385+
isOpen: false,
386+
actualStartDate: null,
387+
actualEndDate: endDate
388+
}
389+
})
390+
391+
try {
392+
await service.partiallyUpdateChallengePhase(authUser, data.challenge.id, data.challengePhase2Id, { isOpen: true })
393+
} catch (e) {
394+
should.equal(
395+
e.message,
396+
'Cannot open phase because predecessor phase must be closed with both actualStartDate and actualEndDate set'
397+
)
398+
return
399+
}
400+
throw new Error('should not reach here')
401+
})
402+
403+
it('partially update challenge phase - can open phase when predecessor is properly closed', async () => {
404+
const startDate = new Date('2025-02-01T00:00:00.000Z')
405+
const endDate = new Date('2025-02-02T00:00:00.000Z')
406+
await prisma.challengePhase.update({
407+
where: { id: data.challengePhase1Id },
408+
data: {
409+
isOpen: false,
410+
actualStartDate: startDate,
411+
actualEndDate: endDate
412+
}
413+
})
414+
await prisma.challengePhase.update({
415+
where: { id: data.challengePhase2Id },
416+
data: { isOpen: false }
417+
})
418+
419+
const challengePhase = await service.partiallyUpdateChallengePhase(authUser, data.challenge.id, data.challengePhase2Id, { isOpen: true })
420+
should.equal(challengePhase.isOpen, true)
421+
})
422+
423+
it('partially update challenge phase - can open phase without predecessor', async () => {
424+
await prisma.challengePhase.update({
425+
where: { id: data.challengePhase1Id },
426+
data: {
427+
isOpen: false,
428+
actualStartDate: null,
429+
actualEndDate: null
430+
}
431+
})
432+
433+
const challengePhase = await service.partiallyUpdateChallengePhase(authUser, data.challenge.id, data.challengePhase1Id, { isOpen: true })
434+
should.equal(challengePhase.isOpen, true)
435+
})
338436
})
339437

340438
describe('delete challenge phase tests', () => {

0 commit comments

Comments
 (0)