Skip to content

Commit

Permalink
fix: fixed notification and event type
Browse files Browse the repository at this point in the history
  • Loading branch information
Troha7 committed Mar 13, 2024
1 parent aee275f commit 67d7e73
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.chat.yourway.listener;

import static com.chat.yourway.model.event.EventType.ONLINE;
import static com.chat.yourway.model.event.EventType.SUBSCRIBED;
import static com.chat.yourway.model.event.EventType.UNSUBSCRIBED;

import com.chat.yourway.config.websocket.WebsocketProperties;
import com.chat.yourway.dto.response.LastMessageResponseDto;
Expand Down Expand Up @@ -46,10 +46,11 @@ public void handleWebSocketSubscribeListener(SessionSubscribeEvent event) {
.getLastMessage();
var contactEvent = new ContactEvent(email, getTopicId(event), SUBSCRIBED,
getTimestamp(event), lastMessageDto);
contactEventService.updateEventTypeByEmail(ONLINE, email);
contactEventService.save(contactEvent);
}

chatNotificationService.notifyTopicSubscribers(getTopicId(event));
chatNotificationService.notifyAllWhoSubscribedToSameUserTopic(email);
chatNotificationService.notifyAllWhoSubscribedToTopic(getTopicId(event));

} catch (NumberFormatException e) {
Expand All @@ -70,7 +71,7 @@ public void handleWebSocketUnsubscribeListener(SessionUnsubscribeEvent event) {

try {
if (isTopicDestination(destination)) {
var contactEvent = new ContactEvent(email, getTopicId(event), UNSUBSCRIBED,
var contactEvent = new ContactEvent(email, getTopicId(event), ONLINE,
getTimestamp(event), lastMessageDto);
contactEventService.save(contactEvent);
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/chat/yourway/model/event/EventType.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
public enum EventType {
ONLINE,
OFFLINE,
SUBSCRIBED,
UNSUBSCRIBED
SUBSCRIBED
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.chat.yourway.unit.listener;

import static com.chat.yourway.model.event.EventType.ONLINE;
import static com.chat.yourway.model.event.EventType.SUBSCRIBED;
import static com.chat.yourway.model.event.EventType.UNSUBSCRIBED;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.mockito.ArgumentMatchers.anyInt;
Expand Down Expand Up @@ -108,7 +108,7 @@ public void handleWebSocketSubscribeListener_shouldNotifyTopicSubscribers() {
stompSubscriptionListener.handleWebSocketSubscribeListener(event);

// Then
verify(chatNotificationService, times(1)).notifyTopicSubscribers(topicId);
verify(chatNotificationService, times(1)).notifyAllWhoSubscribedToSameUserTopic(email);
}

@Test
Expand All @@ -132,7 +132,7 @@ public void handleWebSocketUnsubscribeListener_shouldSaveEvent() {
assertThat(capturedEvent.getTopicId()).isEqualTo(topicId);
assertThat(capturedEvent.getEmail()).isEqualTo(email);
assertThat(capturedEvent.getTimestamp()).isInstanceOfAny(LocalDateTime.class);
assertThat(capturedEvent.getEventType()).isEqualTo(UNSUBSCRIBED);
assertThat(capturedEvent.getEventType()).isEqualTo(ONLINE);
}

@Test
Expand Down

0 comments on commit 67d7e73

Please sign in to comment.