From e440fef70fd50c5d237be82e32ba90c9a9ae3afd Mon Sep 17 00:00:00 2001 From: David Gerber Date: Sat, 16 Nov 2024 10:49:10 +0100 Subject: [PATCH] Fix tests --- .../connection/ConnectionControllerTest.java | 19 +++++++++++++++++++ .../messaging/MessagingWindowController.java | 6 +++--- .../main/resources/i18n/messages.properties | 5 ----- .../resources/i18n/messages_fr.properties | 4 ---- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/app/src/test/java/io/xeres/app/api/controller/connection/ConnectionControllerTest.java b/app/src/test/java/io/xeres/app/api/controller/connection/ConnectionControllerTest.java index 2cc22635..9367f399 100644 --- a/app/src/test/java/io/xeres/app/api/controller/connection/ConnectionControllerTest.java +++ b/app/src/test/java/io/xeres/app/api/controller/connection/ConnectionControllerTest.java @@ -21,7 +21,9 @@ import io.xeres.app.api.controller.AbstractControllerTest; import io.xeres.app.database.model.location.LocationFakes; +import io.xeres.app.job.PeerConnectionJob; import io.xeres.app.service.LocationService; +import io.xeres.common.rest.connection.ConnectionRequest; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -30,6 +32,7 @@ import org.springframework.test.web.servlet.MockMvc; import java.util.List; +import java.util.Optional; import static io.xeres.common.rest.PathConfig.CONNECTIONS_PATH; import static org.hamcrest.Matchers.is; @@ -47,6 +50,9 @@ class ConnectionControllerTest extends AbstractControllerTest @MockBean private LocationService locationService; + @MockBean + private PeerConnectionJob peerConnectionJob; + @Autowired public MockMvc mvc; @@ -65,4 +71,17 @@ void GetConnectedProfiles_Success() throws Exception verify(locationService).getConnectedLocations(); } + + @Test + void AttemptToConnect_Success() throws Exception + { + var location = LocationFakes.createLocation(); + when(locationService.findLocationByLocationId(location.getLocationId())).thenReturn(Optional.of(location)); + + mvc.perform(putJson(BASE_URL + "/connect", new ConnectionRequest(location.getLocationId().toString(), -1))) + .andExpect(status().isOk()); + + verify(locationService).findLocationByLocationId(location.getLocationId()); + verify(peerConnectionJob).connectImmediately(location, -1); + } } diff --git a/ui/src/main/java/io/xeres/ui/controller/messaging/MessagingWindowController.java b/ui/src/main/java/io/xeres/ui/controller/messaging/MessagingWindowController.java index 46b806e6..6fca3c28 100644 --- a/ui/src/main/java/io/xeres/ui/controller/messaging/MessagingWindowController.java +++ b/ui/src/main/java/io/xeres/ui/controller/messaging/MessagingWindowController.java @@ -360,12 +360,12 @@ private String getAvailability() setUserOnline(true); yield ""; } - case AWAY -> " (" + bundle.getString("messaging.status.away") + ")"; - case BUSY -> " (" + bundle.getString("messaging.status.busy") + ")"; + case AWAY -> " (" + Availability.AWAY + ")"; + case BUSY -> " (" + Availability.BUSY + ")"; case OFFLINE -> { setUserOnline(false); - yield " (" + bundle.getString("messaging.status.offline") + ")"; + yield " (" + Availability.OFFLINE + ")"; } }; } diff --git a/ui/src/main/resources/i18n/messages.properties b/ui/src/main/resources/i18n/messages.properties index 69e7d266..f152824d 100644 --- a/ui/src/main/resources/i18n/messages.properties +++ b/ui/src/main/resources/i18n/messages.properties @@ -256,11 +256,6 @@ messaging.file-requester.send-file=Select File to Send messaging.send-picture=Select an image to send inline messaging.send.file=Select a file to send - -messaging.status.away=Away -messaging.status.busy=Busy -messaging.status.offline=Disconnected - messaging.warning.title=Warning messaging.warning.description=The user is currently offline and cannot receive messages. diff --git a/ui/src/main/resources/i18n/messages_fr.properties b/ui/src/main/resources/i18n/messages_fr.properties index 840c8787..486e73e6 100644 --- a/ui/src/main/resources/i18n/messages_fr.properties +++ b/ui/src/main/resources/i18n/messages_fr.properties @@ -238,10 +238,6 @@ messaging.prompt=Ecrivez un message messaging.file-requester.send-picture=Selectionnez une image à envoyer dans le chat messaging.file-requester.send-file=Sélectionnez un fichier à transmettre -messaging.status.away=Absent -messaging.status.busy=Occupé -messaging.status.offline=Déconnecté - messaging.warning.title=Attention messaging.warning.description=L'utilisateur est actuellement déconnecté et ne peut recevoir de messages.