Fix vitest unit tests
This commit is contained in:
parent
a7cc07cc80
commit
0d80df2a23
|
|
@ -1,8 +1,6 @@
|
|||
import { itGetCached, itPost } from "@/fetchHelpers";
|
||||
import type { CourseSession } from "@/types";
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { beforeEach, describe, expect, vi } from "vitest";
|
||||
import { useRoute } from "vue-router";
|
||||
import { useCourseSessionsStore } from "../courseSessions";
|
||||
import { useUserStore } from "../user";
|
||||
|
||||
|
|
@ -53,38 +51,44 @@ describe("CourseSession Store", () => {
|
|||
competence_url: "/course/test-course/competence/",
|
||||
course_url: "/course/test-course/",
|
||||
media_library_url: "/course/test-course/media/",
|
||||
attendance_days: [],
|
||||
additional_json_data: {},
|
||||
documents: [],
|
||||
users: [],
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
it("normal user has no cockpit", () => {
|
||||
const userStore = useUserStore();
|
||||
const courseSessionsStore = useCourseSessionsStore();
|
||||
userStore.$patch(user);
|
||||
courseSessionsStore.$patch({ courseSessions });
|
||||
|
||||
const courseSessionsStore = useCourseSessionsStore();
|
||||
courseSessionsStore.currentCourseSlug = "test-course";
|
||||
courseSessionsStore.courseSessions = courseSessions;
|
||||
|
||||
expect(courseSessionsStore.hasCockpit).toBeFalsy();
|
||||
});
|
||||
|
||||
it("superuser has cockpit", () => {
|
||||
const userStore = useUserStore();
|
||||
const courseSessionsStore = useCourseSessionsStore();
|
||||
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();
|
||||
});
|
||||
|
||||
it("expert has cockpit", () => {
|
||||
const userStore = useUserStore();
|
||||
const courseSessionsStore = useCourseSessionsStore();
|
||||
userStore.$patch(
|
||||
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();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -224,7 +224,6 @@ export const useCourseSessionsStore = defineStore("courseSessions", () => {
|
|||
}
|
||||
|
||||
return {
|
||||
currentCourseSlug,
|
||||
uniqueCourseSessionsByCourse,
|
||||
currentCourseSession,
|
||||
currentCourseSessions,
|
||||
|
|
@ -238,5 +237,11 @@ export const useCourseSessionsStore = defineStore("courseSessions", () => {
|
|||
startUpload,
|
||||
removeDocument,
|
||||
findAttendanceDay,
|
||||
|
||||
// TODO: only used to be changed by router.afterEach
|
||||
currentCourseSlug,
|
||||
|
||||
// TODO: only used for unit testing
|
||||
courseSessions,
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue