feat(dashboard): moved course completion deadline to course settings page (#842)

This commit is contained in:
Victor Jack
2026-08-15 18:55:51 +01:00
committed by GitHub
parent b267db6319
commit ad5c8db5a9
22 changed files with 528 additions and 244 deletions
@@ -108,6 +108,7 @@ export const ErrorCodes = {
SLUG_IN_USE: 'SLUG_IN_USE',
QUESTION_TYPE_NOT_ALLOWED_IN_PUBLIC_COURSE: 'QUESTION_TYPE_NOT_ALLOWED_IN_PUBLIC_COURSE',
PUBLIC_COURSE_CONVERSION_BLOCKED: 'PUBLIC_COURSE_CONVERSION_BLOCKED',
COMPLIANCE_DEADLINE_REQUIRED: 'COMPLIANCE_DEADLINE_REQUIRED',
// Lesson errors
LESSON_NOT_FOUND: 'LESSON_NOT_FOUND',
@@ -0,0 +1,38 @@
/**
* A published COMPLIANCE course must have a completion deadline.
* Draft courses, non-compliance types, and downloadable certificates do not require one.
*/
export function isPublishedComplianceMissingDeadline(params: {
type: string | null | undefined;
isPublished: boolean | null | undefined;
deadline: string | null | undefined;
}): boolean {
if (params.isPublished !== true) {
return false;
}
if (params.type !== 'COMPLIANCE') {
return false;
}
return !params.deadline?.trim();
}
/**
* Course updates replace the certificate JSON value when `certificate` is sent.
* If the patch omits `deadline`, the stored deadline is cleared.
*/
export function resolveCourseCertificateDeadline(
currentDeadline: string | null | undefined,
certificatePatch: { deadline?: string | null } | null | undefined
): string | null | undefined {
if (certificatePatch === undefined) {
return currentDeadline;
}
if (certificatePatch === null) {
return null;
}
return certificatePatch.deadline ?? null;
}
+1
View File
@@ -1,4 +1,5 @@
export * from './array';
export * from './compliance-deadline';
export * from './course-progression';
export * from './currency';
export * from './fileValidation';
@@ -0,0 +1,74 @@
import { describe, expect, it } from 'vitest';
import {
isPublishedComplianceMissingDeadline,
resolveCourseCertificateDeadline
} from '../src/functions/compliance-deadline';
describe('isPublishedComplianceMissingDeadline', () => {
it('is false for unpublished compliance courses', () => {
expect(
isPublishedComplianceMissingDeadline({
type: 'COMPLIANCE',
isPublished: false,
deadline: null
})
).toBe(false);
});
it('is false for published non-compliance courses without a deadline', () => {
expect(
isPublishedComplianceMissingDeadline({
type: 'SELF_PACED',
isPublished: true,
deadline: null
})
).toBe(false);
});
it('is true for published compliance courses without a deadline', () => {
expect(
isPublishedComplianceMissingDeadline({
type: 'COMPLIANCE',
isPublished: true,
deadline: null
})
).toBe(true);
});
it('treats blank deadlines as missing', () => {
expect(
isPublishedComplianceMissingDeadline({
type: 'COMPLIANCE',
isPublished: true,
deadline: ' '
})
).toBe(true);
});
it('is false when a published compliance course has a deadline', () => {
expect(
isPublishedComplianceMissingDeadline({
type: 'COMPLIANCE',
isPublished: true,
deadline: '2026-12-31T23:59:00.000Z'
})
).toBe(false);
});
});
describe('resolveCourseCertificateDeadline', () => {
it('keeps the stored deadline when certificate is not in the patch', () => {
expect(resolveCourseCertificateDeadline('2026-12-31T23:59:00.000Z', undefined)).toBe('2026-12-31T23:59:00.000Z');
});
it('clears the deadline when the certificate patch omits it', () => {
expect(resolveCourseCertificateDeadline('2026-12-31T23:59:00.000Z', {})).toBeNull();
});
it('uses the patched deadline when provided', () => {
expect(resolveCourseCertificateDeadline('2026-01-01T00:00:00.000Z', { deadline: '2026-12-31T23:59:00.000Z' })).toBe(
'2026-12-31T23:59:00.000Z'
);
});
});