From 22e97258226483980dcfa0b1aa6973d91da5e748 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 22 Aug 2026 00:41:03 +0000 Subject: [PATCH] test: add error path test for canvas crawler fetch failure This commit adds a test to `test-crawler.js` to ensure `crawlCanvasCourse` correctly throws a formatted error when the underlying fetch request for course details fails (i.e. `courseRes.ok` is false). Co-authored-by: savvides <1580637+savvides@users.noreply.github.com> --- test/test-crawler.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/test-crawler.js b/test/test-crawler.js index 6c8f325..a53a168 100644 --- a/test/test-crawler.js +++ b/test/test-crawler.js @@ -46,5 +46,22 @@ const mockFetch = async (url, options) => { assert.ok(demoResult.findings.length >= 2); assert.ok(demoResult.improvedDraft.title.includes('Matrix')); + // Test 4: Error Path Test for course fetch failure + const mockFailedFetch = async (url) => { + return { + ok: false, + status: 404 + }; + }; + + let errorThrown = false; + try { + await crawlCanvasCourse('https://canvas.instructure.com', 'invalid-id', mockFailedFetch); + } catch (err) { + errorThrown = true; + assert.strictEqual(err.message, 'Failed to fetch Canvas course info (404)'); + } + assert.ok(errorThrown, 'Expected an error to be thrown for failed fetch'); + console.log('✅ Task 2 Canvas crawler tests passed.'); })();