Commit a331fac9 authored by Morten Nordseth's avatar Morten Nordseth
Browse files

fix comment permissions and test workout data access

parent df53110c
Pipeline #116693 passed with stages
in 3 minutes and 34 seconds
......@@ -40,6 +40,7 @@ describe("Testing workouts according to FR5", () => {
function postComment(name, comment) {
cy.visit("/workouts.html");
cy.get("h5").contains(name).click();
cy.wait(1000);
cy.get("#comment-area").invoke("text", comment);
cy.get("#post-comment").click();
}
......@@ -51,6 +52,14 @@ describe("Testing workouts according to FR5", () => {
cy.get("#btn-delete-workout").click();
}
function checkWorkoutContent(workoutName) {
cy.get("#form-workout").get('input[name="name"]').should('have.value', workoutName);
cy.get("#form-workout").get('input[name="date"]').should('have.value', '2022-12-03T08:30:00');
cy.get("#form-workout").get('textarea[name="notes"]').should('have.value', 'a note for a workout');
cy.get("#form-workout").get('#uploaded-files').children().should('have.length', 1);
cy.get("#comment-list").children().should('have.length.greaterThan', 0);
}
before(() => {
// Athlete data
cy.visit("/login.html");
......@@ -125,6 +134,7 @@ describe("Testing workouts according to FR5", () => {
cy.visit("/workouts.html");
cy.get("h5").contains("Athlete private").click();
cy.get("#form-workout").children().should("have.length", 16);
checkWorkoutContent("Athlete private");
});
//For athletes, this means that the workout needs to be either their own or public
it("Athlete find public workouts", () => {
......@@ -132,6 +142,7 @@ describe("Testing workouts according to FR5", () => {
cy.visit("/workouts.html");
cy.get("h5").contains("Coach public").click();
cy.get("#form-workout").children().should("have.length", 16);
checkWorkoutContent("Coach public");
});
//For coaches, this means that the workout is at least one of their athletes' non-private workouts
it("Coach finds their athletes' workout", () => {
......@@ -139,6 +150,7 @@ describe("Testing workouts according to FR5", () => {
cy.visit("/workouts.html");
cy.get("h5").contains("Athlete coach").click();
cy.get("#form-workout").children().should("have.length", 16);
checkWorkoutContent("Athlete coach");
});
//OR the workout is public.
it("Coach finds public workouts", () => {
......@@ -146,6 +158,7 @@ describe("Testing workouts according to FR5", () => {
cy.visit("/workouts.html");
cy.get("h5").contains("Athlete public").click();
cy.get("#form-workout").children().should("have.length", 16);
checkWorkoutContent("Athlete public");
});
it("Coach finds own private workout", () => {
......@@ -153,5 +166,6 @@ describe("Testing workouts according to FR5", () => {
cy.visit("/workouts.html");
cy.get("h5").contains("Coach private").click();
cy.get("#form-workout").children().should("have.length", 16);
checkWorkoutContent("Coach private");
});
});
\ No newline at end of file
......@@ -298,7 +298,6 @@ async function createComment(workoutid) {
let commentArea = document.querySelector("#comment-area");
let content = commentArea.value;
let body = {workout: `${HOST}/api/workouts/${workoutid}/`, content: content};
let response = await sendRequest("POST", `${HOST}/api/comments/`, body);
if (response.ok) {
addComment(sessionStorage.getItem("username"), content, "Now", false);
......@@ -347,13 +346,12 @@ window.addEventListener("DOMContentLoaded", async () => {
const id = urlParams.get('id');
let workoutData = await retrieveWorkout(id);
await retrieveComments(id);
postCommentButton.addEventListener("click", (async (id) => await createComment(id)).bind(undefined, id));
if (workoutData["owner"] == currentUser.url) {
editWorkoutButton.classList.remove("hide");
editWorkoutButton.addEventListener("click", handleEditWorkoutButtonClick);
deleteWorkoutButton.addEventListener("click", (async (id) => await deleteWorkout(id)).bind(undefined, id));
okWorkoutButton.addEventListener("click", (async (id) => await updateWorkout(id)).bind(undefined, id));
postCommentButton.addEventListener("click", (async (id) => await createComment(id)).bind(undefined, id));
divCommentRow.className = divCommentRow.className.replace(" hide", "");
}
} else {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment