All files / src/api/student StudentAssignmentAPI.js

66.66% Statements 8/12
100% Branches 0/0
66.66% Functions 4/6
66.66% Lines 8/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47          3x 2x       3x 2x       3x 2x       3x 2x                                                  
import axios from "axios";
import { API_ENDPOINTS } from "@/api/endpoints";
 
export class StudentAssignmentAPI {
    async fetchAllAssignments(classCode) {
        const response = await axios.get(API_ENDPOINTS.student.assignment.fetchAll(classCode));
        return response;
    }
 
    async fetchSpecificAssignmentById(assignmentId) {
        const response = await axios.get(API_ENDPOINTS.student.assignment.fetch(assignmentId));
        return response;
    }
 
    async fetchSpecificAssignmentQuestions(assignmentId) {
        const response = await axios.get(API_ENDPOINTS.student.assignment.questions(assignmentId));
        return response;
    }
 
    async studentFetchSubmission(assignmentId) {
        const response = await axios.get(API_ENDPOINTS.student.assignment.submission(assignmentId));
        return response;
    }
 
    async fetchClassGradeAverage(classCode) {
        const response = await axios.get(API_ENDPOINTS.student.assignment.gradeAverage(classCode));
        return response;
    }
 
    /**
     * Reports one browser-lockdown violation for the current attempt. The backend is the
     * source of truth for the running count — see docs/implementation/browser_lockdown_violation_tracking.md
     * — and its response tells the caller whether the max-violations threshold (3) has
     * been exceeded and whether the UI should auto-submit.
     *
     * @param {string} assignmentId
     * @param {string} violationType - e.g. "tab_hidden", "fullscreen_exit" — see useAssessmentLockdown.js
     * @returns {Promise<{data: {violation_count: number, max_violations: number, threshold_exceeded: boolean, auto_submit: boolean}}>}
     */
    async reportViolation(assignmentId, violationType) {
        const response = await axios.post(API_ENDPOINTS.student.assignment.reportViolation(assignmentId), {
            type: violationType,
        });
        return response;
    }
}