Skip to content

Commit

Permalink
Add email in config_change_event_value.proto (#221)
Browse files Browse the repository at this point in the history
* Add email in config_change_event_value.proto

* remove blank link

* add tests

* moved test
  • Loading branch information
siddhant2001 authored Jul 25, 2024
1 parent b3d20f4 commit 12b471f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ private void produceDeleteNotification(

private void populateUserDetails(RequestContext requestContext, Builder builder) {
requestContext.getUserId().ifPresent(builder::setUserId);
requestContext.getName().or(requestContext::getEmail).ifPresent(builder::setUserName);
requestContext.getName().ifPresent(builder::setUserName);
requestContext.getEmail().ifPresent(builder::setUserEmail);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class ConfigChangeEventGeneratorImplTest {
private static final String TEST_CONTEXT = "test-context";
private static final String TEST_VALUE = "test-value";
private static final String TEST_NEW_VALUE = "test-new-value";
private static final String TEST_USER_ID = "test-user-id";
private static final String TEST_USER_NAME = "test-user-name";
private static final String TEST_USER_EMAIL = "test-user-email";
private static final long CURRENT_TIME_MILLIS = 1000;

@Mock EventProducer<ConfigChangeEventKey, ConfigChangeEventValue> eventProducer;
Expand All @@ -45,7 +48,8 @@ void setup() {
mockClock = mock(Clock.class);
when(mockClock.millis()).thenReturn(CURRENT_TIME_MILLIS);
changeEventGenerator = new ConfigChangeEventGeneratorImpl(eventProducer, mockClock);
requestContext = RequestContext.forTenantId(TEST_TENANT_ID_1);
requestContext = mock(RequestContext.class);
when(requestContext.getTenantId()).thenReturn(Optional.of(TEST_TENANT_ID_1));
}

@Test
Expand All @@ -65,6 +69,30 @@ void sendCreateNotification() throws InvalidProtocolBufferException {
.build());
}

@Test
void sendCreateNotificationWithUserDetailsInRequestContext()
throws InvalidProtocolBufferException {
Value config = createStringValue();
when(requestContext.getUserId()).thenReturn(Optional.of(TEST_USER_ID));
when(requestContext.getName()).thenReturn(Optional.of(TEST_USER_NAME));
when(requestContext.getEmail()).thenReturn(Optional.of(TEST_USER_EMAIL));
changeEventGenerator.sendCreateNotification(
requestContext, TEST_CONFIG_TYPE, TEST_CONTEXT, config);
verify(eventProducer)
.send(
KeyUtil.getKey(TEST_TENANT_ID_1, TEST_CONFIG_TYPE, Optional.of(TEST_CONTEXT)),
ConfigChangeEventValue.newBuilder()
.setUserId(TEST_USER_ID)
.setUserEmail(TEST_USER_EMAIL)
.setUserName(TEST_USER_NAME)
.setEventTimeMillis(CURRENT_TIME_MILLIS)
.setCreateEvent(
ConfigCreateEvent.newBuilder()
.setCreatedConfigJson(ConfigProtoConverter.convertToJsonString(config))
.build())
.build());
}

@Test
void sendCreateNotificationWithNoContext() throws InvalidProtocolBufferException {
Value config = createStringValue();
Expand Down

0 comments on commit 12b471f

Please sign in to comment.