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

fix: Remove length constraint from organization external id lookup #597

Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions src/main/java/org/zendesk/client/v2/Zendesk.java
Original file line number Diff line number Diff line change
Expand Up @@ -1423,8 +1423,8 @@ public JobStatus deleteOrganizations(long... ids) {
}

public Iterable<Organization> lookupOrganizationsByExternalId(String externalId) {
if (externalId == null || externalId.length() < 2) {
throw new IllegalArgumentException("Name must be at least 2 characters long");
if (externalId == null || externalId.length() == 0) {
throw new IllegalArgumentException("External ID must not be null or length 0");
}
return new PagedIterable<>(
tmpl("/organizations/search.json{?external_id}").set("external_id", externalId),
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/org/zendesk/client/v2/RealSmokeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assume.assumeThat;
Expand Down Expand Up @@ -1583,6 +1584,21 @@ public void createOrganizationMemberships() throws Exception {
}
}

@Test
public void lookupOrganizationByExternalId() throws Exception {
createClientWithTokenOrPassword();

Organization newOrganization = newTestOrganization();
newOrganization.setExternalId("i");
Organization resultOrganization = instance.createOrganization(newOrganization);
assertNotNull(resultOrganization);

Iterable<Organization> or = instance.lookupOrganizationsByExternalId("i");
assertTrue(or.iterator().hasNext());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Only makes sure something is returned, we should also make sure the size is ok, what about the following?

Suggested change
assertTrue(or.iterator().hasNext());
assertEquals(1, StreamSupport.stream(or.spliterator(), false).count());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the change in the test.


assertThrows(IllegalArgumentException.class, () -> instance.lookupOrganizationsByExternalId(""));
}

@Test
public void getGroups() throws Exception {
createClientWithTokenOrPassword();
Expand Down