Skip to content

feat: add unit tests for model classes (HeuristicQuestionAnswer, StudyAnswer, UserStudyEvaluatorAnswer)#1834

Open
AAdIprog wants to merge 2 commits intoruxailab:developfrom
AAdIprog:feat1
Open

feat: add unit tests for model classes (HeuristicQuestionAnswer, StudyAnswer, UserStudyEvaluatorAnswer)#1834
AAdIprog wants to merge 2 commits intoruxailab:developfrom
AAdIprog:feat1

Conversation

@AAdIprog
Copy link

@AAdIprog AAdIprog commented Mar 7, 2026

Closes #1831

Summary

Adds unit test coverage for 3 model classes that previously had zero tests. These models handle Firestore serialization — bugs here can silently corrupt stored data.

Changes

  • tests/unit/HeuristicQuestionAnswer.spec.js — 10 tests covering constructor, toFirestore(), and the toHeuristicQuestionAnswer() hotfix behavior
  • tests/unit/StudyAnswer.spec.js — 6 tests covering constructor and toFirestore() null/undefined edge cases
  • tests/unit/UserStudyEvaluatorAnswer.spec.js — 8 tests covering constructor defaults, toFirestore() with TaskAnswer serialization, and toModel() factory

Testing

All 117 tests pass (93 existing + 24 new):
![
Screenshot 2026-03-08 at 12 43 07 AM
]

Copilot AI review requested due to automatic review settings March 7, 2026 19:27
@github-actions github-actions bot added medium-complexity new-feature New feature or request size/M testing ui/ux user-test Issues related to user test labels Mar 7, 2026
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 7, 2026

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds new Jest unit tests for key Firestore-serialization model classes and also hardens several v-html rendering points in the UserTest UX by sanitizing HTML via DOMPurify.

Changes:

  • Add unit tests for HeuristicQuestionAnswer, StudyAnswer, and UserStudyEvaluatorAnswer model behaviors (constructors/factories/toFirestore).
  • Sanitize several UI fields rendered with v-html using DOMPurify to reduce XSS risk.
  • Add dompurify as an application dependency (updates lockfile accordingly).

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/unit/UserStudyEvaluatorAnswer.spec.js New unit tests for defaults, toFirestore() task serialization, and toModel().
tests/unit/StudyAnswer.spec.js New unit tests for constructor + toFirestore() null/undefined handling.
tests/unit/HeuristicQuestionAnswer.spec.js New unit tests for constructor, toFirestore(), and toHeuristicQuestionAnswer() hotfix behavior.
src/ux/UserTest/components/transcription/ExportPanel.vue Sanitize executive summary HTML before rendering in preview.
src/ux/UserTest/components/task-steps/TaskPreview.vue Sanitize task description HTML before rendering.
src/ux/UserTest/components/steps/WelcomeStep.vue Sanitize welcome message HTML before rendering.
src/ux/UserTest/components/steps/TaskStep.vue Sanitize task description HTML before rendering in both places it’s displayed.
src/ux/UserTest/components/steps/FinishStep.vue Sanitize “congratulations” HTML before rendering.
src/ux/UserTest/components/steps/ConsentStep.vue Sanitize consent HTML before rendering.
package.json Add dompurify dependency.
package-lock.json Lockfile updates for DOMPurify and dependency graph changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 43 to 47
"chartjs-adapter-date-fns": "^3.0.0",
"crypto-browserify": "^3.12.1",
"date-fns": "^4.1.0",
"dompurify": "^3.3.2",
"firebase": "^9.23.0",
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR’s title/description focuses on adding unit tests, but this change also introduces DOMPurify as a new runtime dependency (and several UI sanitization changes). Please update the PR description/title to reflect the broader scope, or split the sanitization work into a separate PR to keep review/rollback risk isolated.

Copilot uses AI. Check for mistakes.
Comment on lines 45 to 47
"date-fns": "^4.1.0",
"dompurify": "^3.3.2",
"firebase": "^9.23.0",
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DOMPurify v3.3.2 declares an engines constraint of Node >=20 (see package-lock.json). Since package.json doesn’t specify an engines field, developers/CI using older Node versions may get hard-to-diagnose install failures. Consider declaring a minimum supported Node version in package.json (or using a DOMPurify version compatible with your supported Node range).

Copilot uses AI. Check for mistakes.

const controller = new TranscriptionController()
const sanitizedPdfSummaryHtml = computed(() => DOMPurify.sanitize(pdfSummaryHtml.value || ''))

Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The preview now uses DOMPurify, but the PDF generation path still calls stripHtml(pdfSummaryHtml.value) which assigns the (unsanitized) HTML into innerHTML. To keep a single trust boundary, consider reusing the sanitized HTML for all downstream processing (preview + strip-to-text), or sanitize inside stripHtml before assigning to innerHTML.

Suggested change
// Ensure pdfSummaryHtml is always sanitized before any downstream usage (e.g. stripHtml / PDF export)
watch(
pdfSummaryHtml,
newVal => {
const safeHtml = DOMPurify.sanitize(newVal || '')
if (safeHtml !== (newVal || '')) {
pdfSummaryHtml.value = safeHtml
}
},
{ immediate: true },
)

Copilot uses AI. Check for mistakes.
@github-actions github-actions bot added stale and removed stale labels Mar 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

medium-complexity new-feature New feature or request size/M testing ui/ux user-test Issues related to user test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[✨ FEATURE]: Add unit tests for model classes (toFirestore, factory methods)

2 participants