Skip to content

Commit

Permalink
feat: new statisticsservice.yaml with changes in create message stati…
Browse files Browse the repository at this point in the history
…stics event
  • Loading branch information
daho4b committed Sep 13, 2021
1 parent d5b3190 commit 3ddfd15
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 29 deletions.
29 changes: 5 additions & 24 deletions services/statisticsservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ components:
enum:
- "ASSIGN_SESSION"
- "CREATE_MESSAGE"
- "UPLOAD_FILE"

StatisticsEventMessage:
type: object
Expand Down Expand Up @@ -86,6 +85,7 @@ components:
required:
- rcUserId
- rcGroupId
- hasAttachment
- timestamp
allOf:
- $ref: '#/components/schemas/StatisticsEventMessage'
Expand All @@ -99,29 +99,10 @@ components:
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
example: hzt766asas
hasAttachment:
type: boolean
description: indicates whether the message has an attachment
example: true
timestamp:
type: string
description: "Full qualified timestamp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void postGroupMessage(

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class CreateMessageStatisticsEvent implements StatisticsEvent {

private @NonNull String consultantId;
private @NonNull String rcGroupId;
private @NonNull Boolean hasAttachment;

/** {@inheritDoc} */
@Override
Expand All @@ -39,6 +40,7 @@ private CreateMessageStatisticsEventMessage createCreateMessageStatisticsEventMe
.eventType(EVENT_TYPE)
.consultantId(consultantId)
.rcGroupId(rcGroupId)
.hasAttachment(hasAttachment)
.timestamp(TIMESTAMP);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,13 @@ public void postGroupMessage_Should_FireCreateMessageStatisticsEvent()
verify(statisticsService, times(1)).fireEvent(captor.capture());
String consultantId = Objects.requireNonNull(
ReflectionTestUtils.getField(captor.getValue(), "consultantId")).toString();
assertThat(consultantId, Matchers.is(CONSULTANT_ID));
assertThat(consultantId, is(CONSULTANT_ID));
String rcGroupId = Objects.requireNonNull(
ReflectionTestUtils.getField(captor.getValue(), "rcGroupId")).toString();
assertThat(rcGroupId, Matchers.is(RC_GROUP_ID));
assertThat(rcGroupId, is(RC_GROUP_ID));
boolean hasAttachment = Boolean.parseBoolean(Objects.requireNonNull(
ReflectionTestUtils.getField(captor.getValue(), "hasAttachment")).toString());
assertThat(hasAttachment, is(false));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void fireEvent_Should_Send_ExpectedCreateMessageStatisticsEventMessageToQ
throws IOException {

CreateMessageStatisticsEvent createMessageStatisticsEvent =
new CreateMessageStatisticsEvent(CONSULTANT_ID, RC_GROUP_ID);
new CreateMessageStatisticsEvent(CONSULTANT_ID, RC_GROUP_ID, false);
String staticTimestamp =
Objects.requireNonNull(
ReflectionTestUtils.getField(
Expand All @@ -57,6 +57,7 @@ public void fireEvent_Should_Send_ExpectedCreateMessageStatisticsEventMessageToQ
.eventType(EventType.CREATE_MESSAGE)
.consultantId(CONSULTANT_ID)
.rcGroupId(RC_GROUP_ID)
.hasAttachment(false)
.timestamp(staticTimestamp);

statisticsService.fireEvent(createMessageStatisticsEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class CreateMessageStatisticsEventTest {

@Before
public void setup() throws NoSuchFieldException, IllegalAccessException {
createMessageStatisticsEvent = new CreateMessageStatisticsEvent(CONSULTANT_ID, RC_GROUP_ID);
createMessageStatisticsEvent = new CreateMessageStatisticsEvent(CONSULTANT_ID, RC_GROUP_ID, false);
staticTimestamp = Objects.requireNonNull(ReflectionTestUtils
.getField(createMessageStatisticsEvent,
CreateMessageStatisticsEvent.class,
Expand All @@ -44,6 +44,7 @@ public void getPayload_Should_ReturnValidJsonPayload() {
String expectedJson = "{"
+ " \"rcGroupId\":\"" + RC_GROUP_ID + "\","
+ " \"consultantId\":\"" + CONSULTANT_ID + "\","
+ " \"hasAttachment\": false,"
+ " \"timestamp\":\"" + staticTimestamp + "\","
+ " \"eventType\":\"" + EventType.CREATE_MESSAGE + "\""
+ "}";
Expand Down

0 comments on commit 3ddfd15

Please sign in to comment.