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

Conversation

higityan
Copy link
Contributor

Add method for Slack API's migration.exchange endpoint. After migration slack ids has changed, this endpoint returns map of old to new ids.

Copy link

@lmargaryan lmargaryan left a comment

Choose a reason for hiding this comment

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

LGTM

@omotnyk just asking you to have another look at this in case I've missed something. Thanks!

@omotnyk
Copy link
Contributor

omotnyk commented Jun 29, 2021

Taking a look now 👀
I was OOO yesterday.

Copy link
Contributor

@omotnyk omotnyk left a comment

Choose a reason for hiding this comment

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

Left a few comments/questions. Also, I'd appreciate adding a few small integration tests like this one to check if request/response models are serialized/deserialized correctly.

… param name and add jsonProperty to correspond slack's expected json property name
Copy link
Contributor

@omotnyk omotnyk left a comment

Choose a reason for hiding this comment

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

Are you going to add the tests?

@higityan
Copy link
Contributor Author

Yes, I'm adding them. Will push them in a while.

@higityan
Copy link
Contributor Author

Updated.

Copy link
Contributor

@omotnyk omotnyk left a comment

Choose a reason for hiding this comment

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

LGTM. Dropped one small comment regarding the optional usage.


Map<String, String> getUserIdMap();

Optional<Set<String>> getInvalidUserIds();
Copy link
Contributor

Choose a reason for hiding this comment

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

One more thing. I wonder if it's easier to have Set<String> instead of Optional here. Set<String> getInvalidUserIds will be parsed as an empty set if no property is present in JSON at all. So we still can work with the entity but IMHO, it's a bit easier to work with a set that can be empty than with Optional. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that will be better. I just didn't now that json can deserialize without exception. when set property is missing. I'll update it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

Copy link
Contributor

@omotnyk omotnyk left a comment

Choose a reason for hiding this comment

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

Now that we've removed Optional, I think it's okay to rewrite the tests to make them easier to read/understand. I suggest using AssertJ for assertions and the lib is already connected to this project.

Overall, LGTM. Please, update the tests if you think my comments make sense and feel free to merge without further approval.

Thank you!

Comment on lines 59 to 63
private boolean doesMainParamsPresent(MigrationExchangeResponse migrationExchangeResponse) {
return migrationExchangeResponse.isOk() &&
!migrationExchangeResponse.getTeamId().isEmpty() &&
!migrationExchangeResponse.getEnterpriseId().isEmpty();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it makes sense to change this to

private void assertMainResponseFields(MigrationExchangeResponse migrationExchangeResponse) {
    assertThat(migrationExchangeResponse.isOk()).isTrue();
    assertThat(migrationExchangeResponse.getTeamId()).isEqualTo("T024G0P55");
    assertThat(migrationExchangeResponse.getEnterpriseId()).isEqualTo("E01L6J4CPS8");
  }

This way, we verify each field separately and will receive more meaningful error in case of failure. Also, we'll verify that the values from the json fixture are parsed correctly instead of simply checking that they are present.

Comment on lines 23 to 29
MigrationExchangeResponse migrationExchangeResponse =
fetchAndDeserializeMigrationExchangeResponse("migration_exchange_response_with_valid_and_invalid_user_ids.json");
Map<String, String> userIdMap = migrationExchangeResponse.getUserIdMap();
Set<String> invalidUserIds = migrationExchangeResponse.getInvalidUserIds();
assertTrue(doesMainParamsPresent(migrationExchangeResponse));
assertTrue(userIdMap.containsKey(VALID_USER_OLD_ID) && userIdMap.containsValue(VALID_USER_MIGRATED_ID));
assertTrue(invalidUserIds.contains(INVALID_USER_ID));
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks a bit better to me:

    assertMainResponseFields(migrationExchangeResponse);
    assertThat(userIdMap).containsKey(VALID_USER_OLD_ID);
    assertThat(userIdMap).containsValue(VALID_USER_MIGRATED_ID);
    assertThat(invalidUserIds).containsExactly(INVALID_USER_ID);

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes with assertThat it will return more precise errors.

Comment on lines 38 to 40
assertTrue(doesMainParamsPresent(migrationExchangeResponse));
assertTrue(userIdMap.containsKey(VALID_USER_OLD_ID) && userIdMap.containsValue(VALID_USER_MIGRATED_ID));
assertTrue(invalidUserIds.isEmpty());
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks a bit better to me:

    assertMainResponseFields(migrationExchangeResponse);
    assertThat(userIdMap).containsKey(VALID_USER_OLD_ID);
    assertThat(userIdMap).containsValue(VALID_USER_MIGRATED_ID);
    assertThat(invalidUserIds).isEmpty();

What do you think?

Comment on lines 49 to 51
assertTrue(doesMainParamsPresent(migrationExchangeResponse));
assertTrue(userIdMap.isEmpty());
assertTrue(invalidUserIds.contains(INVALID_USER_ID));
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks a bit better to me:

    assertMainResponseFields(migrationExchangeResponse);
    assertThat(userIdMap).isEmpty();
    assertThat(invalidUserIds).containsExactly(INVALID_USER_ID);

What do you think?

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!

@lmargaryan
Copy link

🚢

@higityan
Copy link
Contributor Author

I updated the test to use there assertj according to comments. Will merge it.
Thank you!

@higityan higityan merged commit 2c440df into master Jun 30, 2021
@higityan higityan deleted the add_method_for_slack_api_migration_exchange_endpoint branch June 30, 2021 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants