@Test public void undosAWontVote() throws Exception { User user = user().withWriteAccess(true).build(); Ern recordVote = Ern.valueOf("E05001221-PD-123-1"); Ward ward = ward().withWardCode("E05001221").build(); UUID contactId = UUID.randomUUID(); ImmutableSuccess success = ImmutableSuccess.builder().withCode("GEN-SUCCESS").withHttpCode(200).withMessage("Vote recorded").build(); Call<DeleteContactResponse> call = CallStub.success(ImmutableDeleteContactResponse.builder().withSuccess( success).build()); given(pafClient.deleteContact("E05001221-PD-123-1", contactId)).willReturn(call); given(wardService.getByCode(recordVote.getWardCode(), user)).willReturn(Try.success(ward)); Try<DeleteContactResponse> response = underTest.undoWontVote(user, recordVote, contactId); assertThat(response.isSuccess(), is(true)); assertThat(response.get().success(), is(success)); }
public Try<DeleteContactResponse> undoWontVote(User user, Ern ern, UUID contactId) { if (!user.getWriteAccess()) { log.warn("User={} tried to delete contact for ern={} but does not have write access", user, ern); return Try.failure(new NotAuthorizedFailure("Forbidden")); } else { return wardService .getByCode(ern.getWardCode(), user) .flatMap(ward -> { Call<DeleteContactResponse> call = pafClient.deleteContact(ern.longForm(), contactId); return pafRequestExecutor.execute(call); }).map(deleteResponse -> { log.info("User={} deleted recorded contact for ern={} (won't vote)", user, ern); return deleteResponse; }); } }
RecordVotedService { public Try<DeleteContactResponse> undoWontVote(User user, Ern ern, UUID contactId) { if (!user.getWriteAccess()) { log.warn("User={} tried to delete contact for ern={} but does not have write access", user, ern); return Try.failure(new NotAuthorizedFailure("Forbidden")); } else { return wardService .getByCode(ern.getWardCode(), user) .flatMap(ward -> { Call<DeleteContactResponse> call = pafClient.deleteContact(ern.longForm(), contactId); return pafRequestExecutor.execute(call); }).map(deleteResponse -> { log.info("User={} deleted recorded contact for ern={} (won't vote)", user, ern); return deleteResponse; }); } } }
RecordVotedService { public Try<DeleteContactResponse> undoWontVote(User user, Ern ern, UUID contactId) { if (!user.getWriteAccess()) { log.warn("User={} tried to delete contact for ern={} but does not have write access", user, ern); return Try.failure(new NotAuthorizedFailure("Forbidden")); } else { return wardService .getByCode(ern.getWardCode(), user) .flatMap(ward -> { Call<DeleteContactResponse> call = pafClient.deleteContact(ern.longForm(), contactId); return pafRequestExecutor.execute(call); }).map(deleteResponse -> { log.info("User={} deleted recorded contact for ern={} (won't vote)", user, ern); return deleteResponse; }); } } @Autowired  RecordVotedService(WardService wardService,
                              PafClient pafClient,
                              PafRequestExecutor pafRequestExecutor,
                              Auditor auditor); }
RecordVotedService { public Try<DeleteContactResponse> undoWontVote(User user, Ern ern, UUID contactId) { if (!user.getWriteAccess()) { log.warn("User={} tried to delete contact for ern={} but does not have write access", user, ern); return Try.failure(new NotAuthorizedFailure("Forbidden")); } else { return wardService .getByCode(ern.getWardCode(), user) .flatMap(ward -> { Call<DeleteContactResponse> call = pafClient.deleteContact(ern.longForm(), contactId); return pafRequestExecutor.execute(call); }).map(deleteResponse -> { log.info("User={} deleted recorded contact for ern={} (won't vote)", user, ern); return deleteResponse; }); } } @Autowired  RecordVotedService(WardService wardService,
                              PafClient pafClient,
                              PafRequestExecutor pafRequestExecutor,
                              Auditor auditor); Try<RecordVoteResponse> recordVote(User user, Ern ern); Try<RecordVoteResponse> wontVote(User user, Ern ern); Try<RecordVoteResponse> undoVote(User user, Ern ern); Try<DeleteContactResponse> undoWontVote(User user, Ern ern, UUID contactId); }
RecordVotedService { public Try<DeleteContactResponse> undoWontVote(User user, Ern ern, UUID contactId) { if (!user.getWriteAccess()) { log.warn("User={} tried to delete contact for ern={} but does not have write access", user, ern); return Try.failure(new NotAuthorizedFailure("Forbidden")); } else { return wardService .getByCode(ern.getWardCode(), user) .flatMap(ward -> { Call<DeleteContactResponse> call = pafClient.deleteContact(ern.longForm(), contactId); return pafRequestExecutor.execute(call); }).map(deleteResponse -> { log.info("User={} deleted recorded contact for ern={} (won't vote)", user, ern); return deleteResponse; }); } } @Autowired  RecordVotedService(WardService wardService,
                              PafClient pafClient,
                              PafRequestExecutor pafRequestExecutor,
                              Auditor auditor); Try<RecordVoteResponse> recordVote(User user, Ern ern); Try<RecordVoteResponse> wontVote(User user, Ern ern); Try<RecordVoteResponse> undoVote(User user, Ern ern); Try<DeleteContactResponse> undoWontVote(User user, Ern ern, UUID contactId);  }