Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method for Slack API's migration.exchange endpoint. #235

Merged
merged 6 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.hubspot.slack.client.methods.params.migration;

import java.util.Optional;
import java.util.Set;

import org.immutables.value.Value;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.hubspot.immutables.style.HubSpotStyle;

@Value.Immutable
@HubSpotStyle
@JsonNaming(SnakeCaseStrategy.class)
public interface MigrationExchangeParamsIF {
@JsonProperty("users")
Set<String> getUserIds();

Optional<String> getTeamId();

Optional<Boolean> getToOld();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.hubspot.slack.client.models.response.migration;

import java.util.Map;
import java.util.Set;

import org.immutables.value.Value.Immutable;

import com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.hubspot.immutables.style.HubSpotStyle;
import com.hubspot.slack.client.models.response.SlackResponse;

@Immutable
@HubSpotStyle
@JsonNaming(SnakeCaseStrategy.class)
public interface MigrationExchangeResponseIF extends SlackResponse {
String getTeamId();

String getEnterpriseId();

Map<String, String> getUserIdMap();
omotnyk marked this conversation as resolved.
Show resolved Hide resolved

Set<String> getInvalidUserIds();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.hubspot.slack.client.methods.params.migration;

import java.io.IOException;

import org.junit.Test;

import com.hubspot.slack.client.SerializationTestBase;

public class MigrationExchangeParamsSerializationTest extends SerializationTestBase {
@Test
public void testMigrationExchangeSerialization() throws IOException {
testSerialization("migration_exchange_params.json", MigrationExchangeParams.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.hubspot.slack.client.models.migration;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
import java.util.Map;
import java.util.Set;

import org.junit.Test;

import com.hubspot.slack.client.jackson.ObjectMapperUtils;
import com.hubspot.slack.client.models.JsonLoader;
import com.hubspot.slack.client.models.response.migration.MigrationExchangeResponse;

public class MigrationExchangeParamsDeserializationTest {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first three comments in this file depend on the last one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, you'll need to use import static org.assertj.core.api.Assertions.assertThat; in order to change the assertions as I suggested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!


private static final String VALID_USER_OLD_ID = "U1X3XFPJL";
private static final String VALID_USER_MIGRATED_ID = "U01SZDTN10E";
private static final String INVALID_USER_ID = "INVALID_ID";

@Test
public void itDeserializesMigrationExchangeResponseWithValidAndinvalidUserIds() throws IOException {
MigrationExchangeResponse migrationExchangeResponse =
fetchAndDeserializeMigrationExchangeResponse("migration_exchange_response_with_valid_and_invalid_user_ids.json");
Map<String, String> userIdMap = migrationExchangeResponse.getUserIdMap();
Set<String> invalidUserIds = migrationExchangeResponse.getInvalidUserIds();
assertMainResponseFields(migrationExchangeResponse);
assertThat(userIdMap).containsKey(VALID_USER_OLD_ID);
assertThat(userIdMap).containsValue(VALID_USER_MIGRATED_ID);
assertThat(invalidUserIds).containsExactly(INVALID_USER_ID);
}

@Test
public void itDeserializesMigrationExchangeResponseWithOnlyValidUserIds() throws IOException {
MigrationExchangeResponse migrationExchangeResponse =
fetchAndDeserializeMigrationExchangeResponse("migration_exchange_response_with_only_valid_user_ids.json");
Map<String, String> userIdMap = migrationExchangeResponse.getUserIdMap();
Set<String> invalidUserIds = migrationExchangeResponse.getInvalidUserIds();
assertMainResponseFields(migrationExchangeResponse);
assertThat(userIdMap).containsKey(VALID_USER_OLD_ID);
assertThat(userIdMap).containsValue(VALID_USER_MIGRATED_ID);
assertThat(invalidUserIds.isEmpty());
}

@Test
public void itDeserializesMigrationExchangeResponseWithOnlyInvalidUserIds() throws IOException {
MigrationExchangeResponse migrationExchangeResponse =
fetchAndDeserializeMigrationExchangeResponse("migration_exchange_response_with_only_invalid_user_ids.json");
Map<String, String> userIdMap = migrationExchangeResponse.getUserIdMap();
Set<String> invalidUserIds = migrationExchangeResponse.getInvalidUserIds();
assertMainResponseFields(migrationExchangeResponse);
assertThat(userIdMap.isEmpty());
assertThat(invalidUserIds).containsExactly(INVALID_USER_ID);
}

private MigrationExchangeResponse fetchAndDeserializeMigrationExchangeResponse(String jsonFileName) throws IOException {
String rawJson = JsonLoader.loadJsonFromFile(jsonFileName);
return ObjectMapperUtils.mapper().readValue(rawJson, MigrationExchangeResponse.class);
}

private void assertMainResponseFields(MigrationExchangeResponse migrationExchangeResponse) {
assertThat(migrationExchangeResponse.isOk()).isTrue();
assertThat(migrationExchangeResponse.getTeamId()).isEqualTo("T024G0P55");
assertThat(migrationExchangeResponse.getEnterpriseId()).isEqualTo("E01L6J4CPS8");
}
}
7 changes: 7 additions & 0 deletions slack-base/src/test/resources/migration_exchange_params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"users": [
"U1X3XFPJL"
],
"team_id": "T024G0P55",
"to_old": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"ok": true,
"team_id": "T024G0P55",
"enterprise_id": "E01L6J4CPS8",
"user_id_map": {},
"invalid_user_ids": [
"INVALID_ID"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"ok": true,
"team_id": "T024G0P55",
"enterprise_id": "E01L6J4CPS8",
"user_id_map": {
"U1X3XFPJL": "U01SZDTN10E"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"ok": true,
"team_id": "T024G0P55",
"enterprise_id": "E01L6J4CPS8",
"user_id_map": {
"U1X3XFPJL": "U01SZDTN10E"
},
"invalid_user_ids": [
"INVALID_ID"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.hubspot.slack.client.methods.params.group.GroupsKickParams;
import com.hubspot.slack.client.methods.params.group.GroupsListParams;
import com.hubspot.slack.client.methods.params.im.ImOpenParams;
import com.hubspot.slack.client.methods.params.migration.MigrationExchangeParams;
import com.hubspot.slack.client.methods.params.reactions.ReactionsAddParams;
import com.hubspot.slack.client.methods.params.search.SearchMessagesParams;
import com.hubspot.slack.client.methods.params.usergroups.UsergroupCreateParams;
Expand Down Expand Up @@ -94,6 +95,7 @@
import com.hubspot.slack.client.models.response.files.FilesUploadResponse;
import com.hubspot.slack.client.models.response.group.GroupsKickResponse;
import com.hubspot.slack.client.models.response.im.ImOpenResponse;
import com.hubspot.slack.client.models.response.migration.MigrationExchangeResponse;
import com.hubspot.slack.client.models.response.reactions.AddReactionResponse;
import com.hubspot.slack.client.models.response.search.SearchMessageResponse;
import com.hubspot.slack.client.models.response.team.TeamInfoResponse;
Expand Down Expand Up @@ -253,6 +255,9 @@ CompletableFuture<Result<DndSnoozeResponse, SlackError>> setDndSnooze(
CompletableFuture<Result<ModalViewCommandResponse, SlackError>> pushView(OpenViewParams params);
CompletableFuture<Result<HomeTabViewCommandResponse, SlackError>> publishView(PublishViewParams params);

// migration.exchange
CompletableFuture<Result<MigrationExchangeResponse, SlackError>> migrationExchange(MigrationExchangeParams params);

// extension
<T extends SlackResponse> CompletableFuture<Result<T, SlackError>> postSlackCommand(
SlackMethod method,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
import com.hubspot.slack.client.methods.params.group.GroupsKickParams;
import com.hubspot.slack.client.methods.params.group.GroupsListParams;
import com.hubspot.slack.client.methods.params.im.ImOpenParams;
import com.hubspot.slack.client.methods.params.migration.MigrationExchangeParams;
import com.hubspot.slack.client.methods.params.reactions.ReactionsAddParams;
import com.hubspot.slack.client.methods.params.search.SearchMessagesParams;
import com.hubspot.slack.client.methods.params.usergroups.UsergroupCreateParams;
Expand Down Expand Up @@ -145,6 +146,7 @@
import com.hubspot.slack.client.models.response.group.GroupsKickResponse;
import com.hubspot.slack.client.models.response.group.GroupsListResponse;
import com.hubspot.slack.client.models.response.im.ImOpenResponse;
import com.hubspot.slack.client.models.response.migration.MigrationExchangeResponse;
import com.hubspot.slack.client.models.response.reactions.AddReactionResponse;
import com.hubspot.slack.client.models.response.search.SearchMessageResponse;
import com.hubspot.slack.client.models.response.team.TeamInfoResponse;
Expand Down Expand Up @@ -1445,6 +1447,15 @@ public CompletableFuture<Result<HomeTabViewCommandResponse, SlackError>> publish
);
}

@Override
public CompletableFuture<Result<MigrationExchangeResponse, SlackError>> migrationExchange(MigrationExchangeParams params) {
return postSlackCommand(
SlackMethods.migration_exchange,
params,
MigrationExchangeResponse.class
);
}

@Override
public <T extends SlackResponse> CompletableFuture<Result<T, SlackError>> postSlackCommand(
SlackMethod method,
Expand Down