@Test
public void shouldTurnInconsistentPreparationToConsistentState() throws Exception {

    // given
    final String preparationId = createPreparation("1234", "My preparation");
    clientTest.addStep(preparationId, step(null, action("copy", paramsColAction("0001", "lastname"))));
    clientTest.addStep(preparationId, step(null, action("uppercase", paramsColAction("0005", "lastname_copy"))));
    clientTest.addStep(preparationId, step(null, action("uppercase", paramsColAction("0005", "lastname_copy"))));
    final Preparation preparation = repository.get(preparationId, Preparation.class);
    final List<String> stepIds = preparationUtils.listStepsIds(preparation.getHeadId(), repository);
    assertEquals(4, stepIds.size());
    final Step step4 = repository.get(stepIds.get(3), Step.class);
    final Step step3 = repository.get(stepIds.get(2), Step.class);
    final PreparationActions actionStep4 = repository.get(step4.getContent(), PreparationActions.class);
    final PreparationActions actionStep3 = repository.get(step3.getContent(), PreparationActions.class);
    repository.remove(actionStep4);
    repository.remove(actionStep3);
    // when
    Response response = when().get("/preparations/{id}/details", preparationId);
    // then
    Preparation newPreparation = repository.get(preparationId, Preparation.class);
    String newHead = stepIds.get(1);
    assertEquals(newHead, newPreparation.getHeadId());
}