Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/test speedup #523

Merged
merged 16 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Feature
- add test data cleanup on server after test fails cause them to not be deleted [#522](https://github.com/upb-uc4/ui-web/pull/522)
- speed up tests by removing cypress procedures that were used for creating test objects [#523](https://github.com/upb-uc4/ui-web/pull/523)

## Bugfix
- fix mobile presentation of matriculation settings in account page [#507](https://github.com/upb-uc4/ui-web/issues/507)
Expand Down
16 changes: 9 additions & 7 deletions tests/e2e/adminAccountManagement.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ import Lecturer from "@/api/api_models/user_management/Lecturer";
import Admin from "@/api/api_models/user_management/Admin";
import { loginAsDefaultAdmin, logout } from "./helpers/AuthHelper";
import { navigateToAccountList } from "./helpers/NavigationHelper";
import { createNewStudent, createNewAdmin, createNewLecturer, deleteUsers, deleteUser } from "./helpers/UserHelper";
import {
createNewStudent,
createNewAdmin,
createNewLecturer,
deleteUsers,
deleteUser,
getRandomMatriculationId,
} from "./helpers/UserHelper";

const random = Math.floor(Math.random() * 9999);
let admin: Admin;
Expand Down Expand Up @@ -60,12 +67,7 @@ describe("Account creation, edition and deletion", function () {
cy.fixture("student.json").then((s) => {
(s as Student).username += random;
student = s as Student;
var today = new Date();
var monthPadded = ("00" + (today.getMonth() + 1)).substr(-2);
var dayPadded = ("00" + today.getDate()).substr(-2);
var random2 = Math.floor(Math.random() * 999).toString();
var randomPadded = ("000" + random2).substr(-3);
student.matriculationId = monthPadded + dayPadded + randomPadded;
student.matriculationId = getRandomMatriculationId();
});
cy.fixture("studentAuthUser.json").then((s) => {
(s as Account).username += random;
Expand Down
50 changes: 32 additions & 18 deletions tests/e2e/adminCourseManagement.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import Course from "@/api/api_models/course_management/Course";
import { Account } from "@/entities/Account";
import { loginAsDefaultAdmin, loginAsDefaultLecturer, logout } from "./helpers/AuthHelper";
import { getMachineUserAuth, loginAsDefaultAdmin, loginAsDefaultLecturer, logout } from "./helpers/AuthHelper";
import { navigateToCourseListAdmin, navigateToMyCoursesLecturer } from "./helpers/NavigationHelper";
import { createCourseAdmin, deleteCourseAdmin, deleteCourses } from "./helpers/CourseHelper";
import { createNewLecturer, deleteUsers } from "./helpers/UserHelper";
import { createNewLecturer, createUsers, deleteUsers } from "./helpers/UserHelper";
import Lecturer from "@/api/api_models/user_management/Lecturer";
import { UserWithAuth } from "./helpers/UserWithAuth";
import { Role } from "@/entities/Role";

describe("Course creation, edition and deletion", () => {
const random = Math.floor(Math.random() * 9999);
Expand All @@ -14,6 +16,7 @@ describe("Course creation, edition and deletion", () => {
let secondLecturerAuth: Account;
let adminAuth: Account;
let lecturerAuth: Account;
let usersWithAuth: UserWithAuth[] = [];

before(function () {
cy.clearCookies();
Expand All @@ -25,37 +28,48 @@ describe("Course creation, edition and deletion", () => {
course.courseName += random;
});

cy.fixture("logins/admin.json").then((admin) => {
adminAuth = admin;
});
cy.fixture("logins/admin.json")
.then((admin) => {
adminAuth = admin;
})
.then(async () => {
await getMachineUserAuth(adminAuth);
})
.then(() => {
cy.fixture("lecturer.json").then((l) => {
(l as Lecturer).username += random;
secondLecturer = l as Lecturer;
});
})
.then(() => {
cy.fixture("lecturerAuthUser.json").then((lAuth) => {
(lAuth as Account).username += random;
secondLecturerAuth = lAuth as Account;
usersWithAuth.push({ userInfo: secondLecturer, auth: secondLecturerAuth });
});
})
.then(async () => {
await createUsers(usersWithAuth);
})
.then(() => {
console.log("Setup finished");
});

cy.fixture("logins/lecturer.json").then((lecturer) => {
lecturerAuth = lecturer;
});
cy.fixture("lecturer.json").then((l) => {
(l as Lecturer).username += random;
secondLecturer = l as Lecturer;
});
cy.fixture("lecturerAuthUser.json").then((l) => {
(l as Account).username += random;
secondLecturerAuth = l as Account;
});
});

after(() => {
deleteUsers([secondLecturerAuth], adminAuth);
deleteCourses([course], adminAuth);
deleteCourses([course]);
logout();
});

it("Login as admin", () => {
loginAsDefaultAdmin();
});

it("Create second lecturer", () => {
createNewLecturer(secondLecturer, secondLecturerAuth);
});

it("Navigate to course list", () => {
navigateToCourseListAdmin();
});
Expand Down
56 changes: 32 additions & 24 deletions tests/e2e/courseListFiltering.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import Course from "@/api/api_models/course_management/Course";
import { Account } from "@/entities/Account";
import { loginAsDefaultLecturer, logout } from "./helpers/AuthHelper";
import { createCourse, deleteCourses } from "./helpers/CourseHelper";
import { loginAsDefaultLecturer, logout, getMachineUserAuth } from "./helpers/AuthHelper";
import { createCourse, createCourses, deleteCourses } from "./helpers/CourseHelper";
import { CourseType } from "@/entities/CourseType";
import { Role } from "@/entities/Role";
import { navigateToCourseListLecturer } from "./helpers/NavigationHelper";

describe("Course Filtering", function () {
const random1 = Math.floor(Math.random() * 9999);
Expand All @@ -20,41 +22,47 @@ describe("Course Filtering", function () {
preserve: ["refresh", "login"],
});

cy.fixture("course.json").then((course) => {
course1 = { ...(course as Course) };
course1.courseName += random1;
course1.courseType = CourseType.LECTURE;
cy.fixture("course.json")
.then((course) => {
course1 = { ...(course as Course) };
course1.courseName += random1;
course1.courseType = CourseType.LECTURE;

course2 = { ...(course as Course) };
course2.courseName += random2;
course2.courseType = CourseType.SEMINAR;
course2 = { ...(course as Course) };
course2.courseName += random2;
course2.courseType = CourseType.SEMINAR;

course3 = { ...(course as Course) };
course3.courseName += random3;
course3.courseType = CourseType.PG;
});

cy.fixture("logins/lecturer.json").then((lecturer) => {
lecturerAuth = lecturer;
});
course3 = { ...(course as Course) };
course3.courseName += random3;
course3.courseType = CourseType.PG;
})
.then(() => {
cy.fixture("logins/lecturer.json").then((lecturer) => {
lecturerAuth = lecturer;
});
})
.then(async () => {
await getMachineUserAuth(lecturerAuth);
})
.then(async () => {
await createCourses([course1, course2, course3]);
})
.then(() => {
console.log("Setup finished");
});
});

after(() => {
deleteCourses([course1, course2, course3], lecturerAuth);
deleteCourses([course1, course2, course3]);
logout();
});

it("Login as Lecturer", function () {
loginAsDefaultLecturer();
});

it("Create Courses of each Type", function () {
createCourse(course1);
createCourse(course2);
createCourse(course3);
});

it("Lecture filter working", function () {
navigateToCourseListLecturer();
cy.get("button[id='courseType-Lecture']").click();
cy.get("div").contains(course1.courseName).should("exist");
cy.get("div").contains(course2.courseName).should("not.exist");
Expand Down
6 changes: 6 additions & 0 deletions tests/e2e/helpers/AuthHelper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Account } from "@/entities/Account";
import MachineUserAuthenticationManagement from "tests/helper/MachineUserAuthenticationManagement";

export async function getMachineUserAuth(userAuth: Account) {
MachineUserAuthenticationManagement.setVueEnvVariable();
await MachineUserAuthenticationManagement._getRefreshToken(userAuth);
}

export function loginAsDefaultAdmin() {
cy.fixture("logins/admin.json").then((a) => {
Expand Down
13 changes: 8 additions & 5 deletions tests/e2e/helpers/CourseHelper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Course from "@/api/api_models/course_management/Course";
import { Account } from "@/entities/Account";
import { clear } from "console";
import MachineUserAuthenticationManagement from "tests/helper/MachineUserAuthenticationManagement";
import CourseManagement from "@/api/CourseManagement";
import { loginAsUser } from "./AuthHelper";
import {
Expand Down Expand Up @@ -46,6 +45,13 @@ export function createCourseAdmin(course: Course) {
cy.get("div").contains(course.courseName).should("exist");
}

export async function createCourses(courses: Course[]) {
const course_management = new CourseManagement();
courses.forEach(async (course) => {
await course_management.createCourse(course);
});
}

export function loginAndCreateCourse(course: Course, lecturer: Account) {
loginAsUser(lecturer);
cy.wait(100);
Expand Down Expand Up @@ -88,10 +94,7 @@ export function deleteCourseAdmin(course: Course) {
cy.get("div").contains(course.courseName).should("not.exist");
}

export async function deleteCourses(courses: Course[], userAuth: Account) {
MachineUserAuthenticationManagement.setVueEnvVariable();
await MachineUserAuthenticationManagement._getRefreshToken(userAuth);

export async function deleteCourses(courses: Course[]) {
const course_management = new CourseManagement();
const existingCourses = (await course_management.getCourses()).returnValue;

Expand Down
17 changes: 17 additions & 0 deletions tests/e2e/helpers/UserHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Admin from "@/api/api_models/user_management/Admin";
import UserManagement from "@/api/UserManagement";
import MachineUserAuthenticationManagement from "../../helper/MachineUserAuthenticationManagement";
import { readFileSync } from "fs";
import { UserWithAuth } from "./UserWithAuth";

export function createNewLecturer(lecturer: Lecturer, lecturerAuthUser: Account) {
navigateToAccountForm();
Expand Down Expand Up @@ -130,6 +131,13 @@ export function loginAndDeleteUser(user: User, adminAuth: Account) {
deleteUser(user);
}

export async function createUsers(users: UserWithAuth[]) {
const user_management = new UserManagement();
users.forEach(async (user) => {
await user_management.createUser(user.auth, user.userInfo);
});
}

export async function deleteUsers(users: Account[], adminAuth: Account) {
let userNames: string[] = [];
users.forEach((user) => userNames.push(user.username));
Expand All @@ -144,3 +152,12 @@ export async function deleteUsers(users: Account[], adminAuth: Account) {
await user_management.deleteUser(user.username);
});
}

export function getRandomMatriculationId(): string {
var today = new Date();
var monthPadded = ("00" + (today.getMonth() + 1)).substr(-2);
var dayPadded = ("00" + today.getDate()).substr(-2);
var random2 = Math.floor(Math.random() * 999).toString();
var randomPadded = ("000" + random2).substr(-3);
return monthPadded + dayPadded + randomPadded;
}
9 changes: 9 additions & 0 deletions tests/e2e/helpers/UserWithAuth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Admin from "@/api/api_models/user_management/Admin";
import Lecturer from "@/api/api_models/user_management/Lecturer";
import Student from "@/api/api_models/user_management/Student";
import { Account } from "@/entities/Account";

export interface UserWithAuth {
userInfo: Admin | Lecturer | Student;
auth: Account;
}
Loading