From 049fb2715f21ddd0ca4ed99944f8b1af9087fcd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobi=20T=C3=B6gel?= <71888952+TobiTgl@users.noreply.github.com> Date: Sat, 17 Feb 2024 09:56:38 +0100 Subject: [PATCH] clear feedback socket test --- .../socket/LiveFeedbackSocketTest.java | 69 ++++++++++++++++++- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/backend/src/test/java/de/htwg_konstanz/mobilelearning/services/feedback/socket/LiveFeedbackSocketTest.java b/backend/src/test/java/de/htwg_konstanz/mobilelearning/services/feedback/socket/LiveFeedbackSocketTest.java index d8e15874..013a9149 100644 --- a/backend/src/test/java/de/htwg_konstanz/mobilelearning/services/feedback/socket/LiveFeedbackSocketTest.java +++ b/backend/src/test/java/de/htwg_konstanz/mobilelearning/services/feedback/socket/LiveFeedbackSocketTest.java @@ -243,6 +243,69 @@ public void stopFeedback() { Assertions.fail(e.getMessage()); } + } + + @Test + @TestSecurity(user = "Prof", roles = { UserRole.PROF}) + @JwtSecurity(claims = { @Claim(key = "email", value = "prof@htwg-konstanz.de") }) + public void clearFeedback() { + //create & get courses + ids + List courses = createCourse(); + String courseId = courses.get(0).getId().toString(); + String formId = courses.get(0).getFeedbackForms().get(0).getId().toString(); + String questionId = courses.getFirst().feedbackForms.get(0).questions.get(0).getId().toString(); + + // create a websocket client + // (@ServerEndpoint("/course/{courseId}/feedback/form/{formId}/subscribe/{userId}/{jwt}") + try { + LiveFeedbackSocketClient client = new LiveFeedbackSocketClient(); + Session session = ContainerProvider.getWebSocketContainer().connectToServer( + client, + URI.create("ws://localhost:8081/course/" + courseId + "/feedback/form/" + formId + "/subscribe/" + profId + "/" + profJwt) + ); + client.sendMessage(""" + { + "action": "CHANGE_FORM_STATUS", + "formStatus": "STARTED", + "roles": [Prof] + } + """); + // adds result to feedbackform + client.sendMessage(String.format(""" + { + "action": "ADD_RESULT", + "resultElementId": %s, + "resultValues": [5], + "role": "STUDENT" + } + """, questionId)); + Thread.sleep(100); + client.sendMessage(""" + { + "action": "CHANGE_FORM_STATUS", + "formStatus": "FINISHED", + "roles": [Prof] + } + """); + Assertions.assertEquals(1, feedbackFormService.getFeedbackForms(courseId).get(0).getQuestions().get(0).results.size()); + client.sendMessage(""" + { + "action": "CHANGE_FORM_STATUS", + "formStatus": "NOT_STARTED", + "roles": [Prof] + } + """); + Thread.sleep(1000); + session.close(); + + // form status should not change because user student + Assertions.assertTrue(courseService.getCourse(courseId).getFeedbackForms().get(0).getStatus().toString().equals("NOT_STARTED")); + Assertions.assertEquals(0, feedbackFormService.getFeedbackForms(courseId).get(0).getQuestions().get(0).results.size()); + } catch (Exception e) { + System.out.println(e); + Assertions.fail(e.getMessage()); + } + } @Test @@ -286,9 +349,9 @@ public void stopFeedbackNotOwner() { session.close(); session2.close(); - // form status should not change because user student - Assertions.assertTrue(courseService.getCourse(courseId).getFeedbackForms().get(0).getStatus().toString().equals("STARTED")); - } catch (Exception e) { + // form status should not change because user student + Assertions.assertTrue(courseService.getCourse(courseId).getFeedbackForms().get(0).getStatus().toString().equals("STARTED")); + } catch (Exception e) { System.out.println(e); Assertions.fail(e.getMessage()); }