|
| 1 | +package test_locally.api.model.event; |
| 2 | + |
| 3 | +import com.google.gson.Gson; |
| 4 | +import com.slack.api.model.event.UserConnectionEvent; |
| 5 | +import org.junit.Test; |
| 6 | +import test_locally.unit.GsonFactory; |
| 7 | + |
| 8 | +import static org.hamcrest.CoreMatchers.is; |
| 9 | +import static org.hamcrest.CoreMatchers.nullValue; |
| 10 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 11 | + |
| 12 | +public class UserConnectionEventTest { |
| 13 | + |
| 14 | + @Test |
| 15 | + public void typeName() { |
| 16 | + assertThat(UserConnectionEvent.TYPE_NAME, is("user_connection")); |
| 17 | + } |
| 18 | + |
| 19 | + @Test |
| 20 | + public void deserializeConnect() { |
| 21 | + String json = "{\"type\":\"user_connection\",\"subtype\":\"connect\",\"user\":\"U123ABC456\"," + |
| 22 | + "\"trigger_id\":\"1293638028594.1249184885746.0d121a0e01d2e7a795ecc7a62880a406\"," + |
| 23 | + "\"event_ts\":\"1764264284.841251\"}"; |
| 24 | + UserConnectionEvent event = GsonFactory.createSnakeCase().fromJson(json, UserConnectionEvent.class); |
| 25 | + assertThat(event.getType(), is("user_connection")); |
| 26 | + assertThat(event.getSubtype(), is("connect")); |
| 27 | + assertThat(event.getUser(), is("U123ABC456")); |
| 28 | + assertThat(event.getTriggerId(), is("1293638028594.1249184885746.0d121a0e01d2e7a795ecc7a62880a406")); |
| 29 | + assertThat(event.getEnterpriseId(), is(nullValue())); |
| 30 | + assertThat(event.getEventTs(), is("1764264284.841251")); |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + public void deserializeDisconnect() { |
| 35 | + String json = "{\"type\":\"user_connection\",\"subtype\":\"disconnect\",\"user\":\"U123ABC456\"," + |
| 36 | + "\"enterprise_id\":\"E123ABC456\",\"event_ts\":\"1764264317.061589\"}"; |
| 37 | + UserConnectionEvent event = GsonFactory.createSnakeCase().fromJson(json, UserConnectionEvent.class); |
| 38 | + assertThat(event.getSubtype(), is("disconnect")); |
| 39 | + assertThat(event.getUser(), is("U123ABC456")); |
| 40 | + assertThat(event.getTriggerId(), is(nullValue())); |
| 41 | + assertThat(event.getEnterpriseId(), is("E123ABC456")); |
| 42 | + assertThat(event.getEventTs(), is("1764264317.061589")); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void serialize() { |
| 47 | + Gson gson = GsonFactory.createSnakeCase(); |
| 48 | + UserConnectionEvent event = new UserConnectionEvent(); |
| 49 | + event.setUser("U123ABC456"); |
| 50 | + String generatedJson = gson.toJson(event); |
| 51 | + String expectedJson = "{\"type\":\"user_connection\",\"user\":\"U123ABC456\"}"; |
| 52 | + assertThat(generatedJson, is(expectedJson)); |
| 53 | + } |
| 54 | +} |
0 commit comments