Fix vitest unit tests

This commit is contained in:
Daniel Egger 2023-04-04 11:30:50 +02:00
parent a7cc07cc80
commit 0d80df2a23
2 changed files with 19 additions and 10 deletions

View File

@ -1,8 +1,6 @@
import { itGetCached, itPost } from "@/fetchHelpers";
import type { CourseSession } from "@/types"; import type { CourseSession } from "@/types";
import { createPinia, setActivePinia } from "pinia"; import { createPinia, setActivePinia } from "pinia";
import { beforeEach, describe, expect, vi } from "vitest"; import { beforeEach, describe, expect, vi } from "vitest";
import { useRoute } from "vue-router";
import { useCourseSessionsStore } from "../courseSessions"; import { useCourseSessionsStore } from "../courseSessions";
import { useUserStore } from "../user"; import { useUserStore } from "../user";
@ -53,38 +51,44 @@ describe("CourseSession Store", () => {
competence_url: "/course/test-course/competence/", competence_url: "/course/test-course/competence/",
course_url: "/course/test-course/", course_url: "/course/test-course/",
media_library_url: "/course/test-course/media/", media_library_url: "/course/test-course/media/",
attendance_days: [],
additional_json_data: {}, additional_json_data: {},
documents: [], documents: [],
users: [],
}, },
]; ];
}); });
it("normal user has no cockpit", () => { it("normal user has no cockpit", () => {
const userStore = useUserStore(); const userStore = useUserStore();
const courseSessionsStore = useCourseSessionsStore();
userStore.$patch(user); userStore.$patch(user);
courseSessionsStore.$patch({ courseSessions });
const courseSessionsStore = useCourseSessionsStore();
courseSessionsStore.currentCourseSlug = "test-course";
courseSessionsStore.courseSessions = courseSessions;
expect(courseSessionsStore.hasCockpit).toBeFalsy(); expect(courseSessionsStore.hasCockpit).toBeFalsy();
}); });
it("superuser has cockpit", () => { it("superuser has cockpit", () => {
const userStore = useUserStore(); const userStore = useUserStore();
const courseSessionsStore = useCourseSessionsStore();
userStore.$patch(Object.assign(user, { is_superuser: true })); userStore.$patch(Object.assign(user, { is_superuser: true }));
courseSessionsStore.$patch({ courseSessions });
const courseSessionsStore = useCourseSessionsStore();
courseSessionsStore.currentCourseSlug = "test-course";
courseSessionsStore.courseSessions = courseSessions;
expect(courseSessionsStore.hasCockpit).toBeTruthy(); expect(courseSessionsStore.hasCockpit).toBeTruthy();
}); });
it("expert has cockpit", () => { it("expert has cockpit", () => {
const userStore = useUserStore(); const userStore = useUserStore();
const courseSessionsStore = useCourseSessionsStore();
userStore.$patch( userStore.$patch(
Object.assign(user, { course_session_experts: [courseSessions[0].id] }) Object.assign(user, { course_session_experts: [courseSessions[0].id] })
); );
courseSessionsStore.$patch({ courseSessions });
const courseSessionsStore = useCourseSessionsStore();
courseSessionsStore.currentCourseSlug = "test-course";
courseSessionsStore.courseSessions = courseSessions;
expect(courseSessionsStore.hasCockpit).toBeTruthy(); expect(courseSessionsStore.hasCockpit).toBeTruthy();
}); });

View File

@ -224,7 +224,6 @@ export const useCourseSessionsStore = defineStore("courseSessions", () => {
} }
return { return {
currentCourseSlug,
uniqueCourseSessionsByCourse, uniqueCourseSessionsByCourse,
currentCourseSession, currentCourseSession,
currentCourseSessions, currentCourseSessions,
@ -238,5 +237,11 @@ export const useCourseSessionsStore = defineStore("courseSessions", () => {
startUpload, startUpload,
removeDocument, removeDocument,
findAttendanceDay, findAttendanceDay,
// TODO: only used to be changed by router.afterEach
currentCourseSlug,
// TODO: only used for unit testing
courseSessions,
}; };
}); });