Skip to content

Commit

Permalink
feat: update of statisticsservice.yaml and corresponding changes
Browse files Browse the repository at this point in the history
  • Loading branch information
daho4b committed Sep 13, 2021
1 parent 97947cb commit 0afd784
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 17 deletions.
30 changes: 27 additions & 3 deletions services/statisticsservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ components:
enum:
- "ASSIGN_SESSION"
- "CREATE_MESSAGE"
- "UPLOAD_FILE"

StatisticsEventMessage:
type: object
Expand Down Expand Up @@ -90,10 +91,33 @@ components:
- $ref: '#/components/schemas/StatisticsEventMessage'
- type: object
properties:
rcUserId:
consultantId:
type: string
description: The Rocket.Chat Id of the consultant
example: yD764hjhz
description: The keycloak id of the consultant
example: d63f4cc0-215d-40e2-a866-2d3e910f0590
rcGroupId:
type: string
description: The Rocket.Chat id of the group from the session
example: hzt766asas
timestamp:
type: string
description: "Full qualified timestamp"
example: "2018-11-15T09:33:00.057Z"

UploadFileStatisticsEventMessage:
type: object
required:
- rcUserId
- rcGroupId
- timestamp
allOf:
- $ref: '#/components/schemas/StatisticsEventMessage'
- type: object
properties:
consultantId:
type: string
description: The keycloak id of the consultant
example: d63f4cc0-215d-40e2-a866-2d3e910f0590
rcGroupId:
type: string
description: The Rocket.Chat id of the group from the session
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public void postGroupMessage(
}

if (AuthenticatedUserHelper.isConsultant(authenticatedUser)) {
statisticsService.fireEvent(new CreateMessageStatisticsEvent(rcUserId, rcGroupId));
statisticsService.fireEvent(
new CreateMessageStatisticsEvent(authenticatedUser.getUserId(), rcGroupId));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class CreateMessageStatisticsEvent implements StatisticsEvent {
private static final EventType EVENT_TYPE = EventType.CREATE_MESSAGE;
private static final String TIMESTAMP = CustomLocalDateTime.nowAsFullQualifiedTimestamp();

private @NonNull String rcUserId;
private @NonNull String consultantId;
private @NonNull String rcGroupId;

/** {@inheritDoc} */
Expand All @@ -34,7 +34,7 @@ public EventType getEventType() {
private CreateMessageStatisticsEventMessage createCreateMessageStatisticsEventMessage() {
return new CreateMessageStatisticsEventMessage()
.eventType(EVENT_TYPE)
.rcUserId(rcUserId)
.consultantId(consultantId)
.rcGroupId(rcGroupId)
.timestamp(TIMESTAMP);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class PostGroupMessageFacadeTest {

private static final String RC_TOKEN = "r94qMDk8gtgVNzqCq9zD2hELK-eXGB5VHlUVBgE8a8f";
private static final String RC_USER_ID = "pptLwARyTMzbTTRdg";
private static final String CONSULTANT_ID = "d63f4cc0-215d-40e2-a866-2d3e910f0590";
private static final String RC_GROUP_ID = "fR2Rz7dmWmHdXE8uz";
private static final String RC_FEEDBACK_GROUP_ID = "fR2Rz7dmWmHdXE8uz";
private static final String MESSAGE = "Lorem ipsum";
Expand Down Expand Up @@ -324,6 +325,8 @@ public void setPostGroupMessage_Should_FireCreateMessageStatisticsEvent()

when(authenticatedUser.getRoles())
.thenReturn(SetUtils.unmodifiableSet(Role.CONSULTANT.getRoleName()));
when(authenticatedUser.getUserId())
.thenReturn(CONSULTANT_ID);
when(rocketChatService.postGroupMessage(RC_TOKEN, RC_USER_ID, RC_GROUP_ID, MESSAGE, null))
.thenReturn(POST_MESSAGE_RESPONSE_DTO);

Expand All @@ -336,9 +339,9 @@ public void setPostGroupMessage_Should_FireCreateMessageStatisticsEvent()
ArgumentCaptor<CreateMessageStatisticsEvent> captor = ArgumentCaptor.forClass(
CreateMessageStatisticsEvent.class);
verify(statisticsService, times(1)).fireEvent(captor.capture());
String rcUserId = Objects.requireNonNull(
ReflectionTestUtils.getField(captor.getValue(), "rcUserId")).toString();
assertThat(rcUserId, Matchers.is(RC_USER_ID));
String consultantId = Objects.requireNonNull(
ReflectionTestUtils.getField(captor.getValue(), "consultantId")).toString();
assertThat(consultantId, Matchers.is(CONSULTANT_ID));
String rcGroupId = Objects.requireNonNull(
ReflectionTestUtils.getField(captor.getValue(), "rcGroupId")).toString();
assertThat(rcGroupId, Matchers.is(RC_GROUP_ID));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.caritas.cob.messageservice.api.helper;

import static de.caritas.cob.messageservice.testhelper.TestConstants.RC_GROUP_ID;
import static de.caritas.cob.messageservice.testhelper.TestConstants.RC_USER_ID;
import static de.caritas.cob.messageservice.testhelper.TestConstants.CONSULTANT_ID;
import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -42,7 +42,7 @@ public void serialize_Should_returnOptionalWithSerializedObject() throws JsonPro
new CreateMessageStatisticsEventMessage()
.eventType(EventType.CREATE_MESSAGE)
.rcGroupId(RC_GROUP_ID)
.rcUserId(RC_USER_ID)
.consultantId(CONSULTANT_ID)
.timestamp(CustomLocalDateTime.nowAsFullQualifiedTimestamp());

Optional<String> result =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.caritas.cob.messageservice.api.service.statistics;

import static de.caritas.cob.messageservice.testhelper.TestConstants.CONSULTANT_ID;
import static de.caritas.cob.messageservice.testhelper.TestConstants.RC_GROUP_ID;
import static de.caritas.cob.messageservice.testhelper.TestConstants.RC_USER_ID;
import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
import static org.apache.commons.codec.CharEncoding.UTF_8;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -44,7 +44,7 @@ public void fireEvent_Should_Send_ExpectedCreateMessageStatisticsEventMessageToQ
throws IOException {

CreateMessageStatisticsEvent createMessageStatisticsEvent =
new CreateMessageStatisticsEvent(RC_USER_ID, RC_GROUP_ID);
new CreateMessageStatisticsEvent(CONSULTANT_ID, RC_GROUP_ID);
String staticTimestamp =
Objects.requireNonNull(
ReflectionTestUtils.getField(
Expand All @@ -55,7 +55,7 @@ public void fireEvent_Should_Send_ExpectedCreateMessageStatisticsEventMessageToQ
CreateMessageStatisticsEventMessage createMessageStatisticsEventMessage =
new CreateMessageStatisticsEventMessage()
.eventType(EventType.CREATE_MESSAGE)
.rcUserId(RC_USER_ID)
.consultantId(CONSULTANT_ID)
.rcGroupId(RC_GROUP_ID)
.timestamp(staticTimestamp);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.caritas.cob.messageservice.api.service.statistics.event;

import static de.caritas.cob.messageservice.testhelper.TestConstants.RC_GROUP_ID;
import static de.caritas.cob.messageservice.testhelper.TestConstants.RC_USER_ID;
import static de.caritas.cob.messageservice.testhelper.TestConstants.CONSULTANT_ID;
import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
Expand All @@ -24,7 +24,7 @@ public class CreateMessageStatisticsEventTest {

@Before
public void setup() throws NoSuchFieldException, IllegalAccessException {
createMessageStatisticsEvent = new CreateMessageStatisticsEvent(RC_USER_ID, RC_GROUP_ID);
createMessageStatisticsEvent = new CreateMessageStatisticsEvent(CONSULTANT_ID, RC_GROUP_ID);
staticTimestamp = Objects.requireNonNull(ReflectionTestUtils
.getField(createMessageStatisticsEvent,
CreateMessageStatisticsEvent.class,
Expand All @@ -43,7 +43,7 @@ public void getPayload_Should_ReturnValidJsonPayload() {

String expectedJson = "{"
+ " \"rcGroupId\":\"" + RC_GROUP_ID + "\","
+ " \"rcUserId\":\"" + RC_USER_ID + "\","
+ " \"consultantId\":\"" + CONSULTANT_ID + "\","
+ " \"timestamp\":\"" + staticTimestamp + "\","
+ " \"eventType\":\"" + EventType.CREATE_MESSAGE + "\""
+ "}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public class TestConstants {
public static final String USERNAME_ENCODED = ENCODING_PREFIX + "OVZWK4TOMFWWK...";
public static final String USERNAME_DECODED = "username";

/* Consultant */
public static final String CONSULTANT_ID = "d63f4cc0-215d-40e2-a866-2d3e910f0590";

/*
* Messages
*/
Expand Down

0 comments on commit 0afd784

Please sign in to comment.