Skip to content

Commit

Permalink
Merge pull request #562 from colbya/bulkDeleteUsers
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreBtz authored Mar 13, 2023
2 parents 366da49 + 460c5b8 commit eeb1ba3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/zendesk/client/v2/Zendesk.java
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,11 @@ public void deleteUser(long id) {
complete(submit(req("DELETE", tmpl("/users/{id}.json").set("id", id)), handleStatus()));
}

public JobStatus deleteUsers(long... ids) {
return complete(submit(req("DELETE", tmpl("/users/destroy_many.json{?ids}").set("ids", ids)),
handleJobStatus()));
}

public User permanentlyDeleteUser(User user) {
checkHasId(user);
return permanentlyDeleteUser(user.getId());
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/org/zendesk/client/v2/RealSmokeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,25 @@ public void updateUsers() throws Exception {
}
}

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

final List<User> users = createTestUsersInZendesk();
final long[] ids = users.stream().mapToLong(User::getId).toArray();
final JobStatus status = waitJobCompletion(instance.deleteUsers(ids));

assertThat("Job is completed", status.getStatus(), is(JobStatus.JobStatusEnum.completed));
assertThat("The good number of users were processed", status.getTotal(), is(users.size()));
assertThat("We have a result for each user", status.getResults(), hasSize(users.size()));
assertThat("Job reports that the same users requested to be deleted were deleted",
status.getResults()
.stream()
.map(JobResult::getId)
.collect(Collectors.toList()),
containsInAnyOrder(Arrays.stream(ids).boxed().toArray()));
}

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

0 comments on commit eeb1ba3

Please sign in to comment.