import assert from 'node:assert/strict'; import { describe, it } from 'node:test'; import { formatGradeState } from '../src/mcp/tools/submissions.ts'; /** * The schema has no textual grade — `grade` is a 0-100 percentage and * `gradeComment` is free text — but teachers commonly grade with the comment * alone. These cases keep the wording honest about which of those happened. */ describe('formatGradeState', () => { it('reports a percentage as a percentage, not a bare number', () => { assert.equal(formatGradeState({ isGraded: true, grade: 85 }, false), 'graded **85%**'); }); it('keeps 0% distinct from "no grade given"', () => { assert.equal(formatGradeState({ isGraded: true, grade: 0 }, false), 'graded **0%**'); }); it('treats feedback alone as the verdict, not as missing data', () => { // The real case: teacher wrote "OK" and set no percentage. assert.equal( formatGradeState({ isGraded: true, grade: null }, true), 'graded by feedback, with no percentage given', ); }); it('mentions both when a percentage and feedback are present', () => { assert.equal(formatGradeState({ isGraded: true, grade: 70 }, true), 'graded **70%**, with feedback'); }); it('falls back to the percentage read off the page when the API omits it', () => { assert.equal(formatGradeState({ isGraded: true, grade: null }, false, 40), 'graded **40%**'); }); it('says plainly when graded but nothing at all was found', () => { assert.match( formatGradeState({ isGraded: true, grade: null }, false), /neither a percentage nor feedback was found/, ); }); it('does not claim a grade for an ungraded submission', () => { assert.equal(formatGradeState({ isGraded: false, grade: null }, false), 'not graded yet'); assert.equal(formatGradeState({ isGraded: false, grade: null }, true), 'not graded yet'); }); });