Skip to content

Commit

Permalink
EnsembleTimer now has a rotation that can be rotated.
Browse files Browse the repository at this point in the history
  • Loading branch information
tedyoung committed Feb 29, 2024
1 parent 835e854 commit b1b7170
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public Rotation rotation() {
}

public void rotateRoles() {

rotation.rotate();
}

public enum TimerState {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.jitterted.mobreg.adapter.in.web.admin;

import com.jitterted.mobreg.adapter.in.web.TestAdminConfiguration;
import com.jitterted.mobreg.application.TestEnsembleServiceBuilder;
import com.jitterted.mobreg.application.port.EnsembleRepository;
import com.jitterted.mobreg.domain.Ensemble;
import com.jitterted.mobreg.domain.EnsembleFactory;
import org.junit.jupiter.api.Disabled;
import com.jitterted.mobreg.domain.EnsembleBuilder;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -50,16 +50,22 @@ void getForTimerViewEndpointReturns200OK() throws Exception {
}

@Test
@Disabled("Until we properly create the timer before starting: see EnsembleTimerHolderTest.whenNoTimerExistsForEnsembleOneIsCreated")
void postToStartTimerEndpointReturns204NoContent() throws Exception {
createAndSaveEnsembleInRepositoryForId(113);
mockMvc.perform(post("/admin/timer-view/113").with(csrf()));

mockMvc.perform(post("/admin/start-timer/113")
.with(csrf()))
.andExpect(status().isNoContent());
}

private void createAndSaveEnsembleInRepositoryForId(long ensembleId) {
Ensemble ensemble = EnsembleFactory.withStartTimeNowAndIdOf(ensembleId);
ensembleRepository.save(ensemble);
Ensemble ensemble = new EnsembleBuilder().id(ensembleId)
.startsNow()
.build();
new TestEnsembleServiceBuilder()
.withEnsembleRepository(ensembleRepository)
.saveEnsemble(ensemble)
.withThreeParticipants();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class EnsembleBuilder {
private final List<MemberId> declinedMemberIds = new ArrayList<>();
private String name;
private boolean markAsCompleted;
private Integer id;
private Long id;
private boolean markAsCanceled;

public EnsembleBuilder() {
Expand Down Expand Up @@ -61,7 +61,7 @@ public EnsembleBuilder named(String name) {
return this;
}

public EnsembleBuilder id(int id) {
public EnsembleBuilder id(long id) {
this.id = id;
return this;
}
Expand Down
51 changes: 26 additions & 25 deletions src/test/java/com/jitterted/mobreg/domain/EnsembleTimerTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.jitterted.mobreg.domain;

import org.assertj.core.data.Offset;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -144,33 +143,36 @@ class ParticipantRotation {

@Test
void rolesAssignedUponCreation() {
MemberId driverId = MemberId.of(3L);
MemberId navigatorId = MemberId.of(7L);
MemberId nextDriverId = MemberId.of(2L);
MemberId participantId1 = MemberId.of(1L);
MemberId participantId2 = MemberId.of(9L);
EnsembleTimer ensembleTimer = new EnsembleTimer(EnsembleTimerFactory.IRRELEVANT_ENSEMBLE_ID,
EnsembleTimerFactory.IRRELEVANT_NAME,
List.of(nextDriverId,
driverId,
navigatorId,
participantId1,
participantId2));

assertThat(ensembleTimer.rotation().driver())
.as("Expected rotation.driver() to be " + driverId)
.isEqualTo(driverId);
RotationFixture fixture = createParticipantRotation();

assertThat(fixture.ensembleTimer().rotation().driver())
.as("Expected rotation.driver() to be " + fixture.driverId())
.isEqualTo(fixture.driverId());
}

@Test
void rolesDoNotRotateWhenTimerFinishes() {
RotationFixture fixture = createParticipantRotation();

// .as("rotate should not happen until we invoke #nextRound() explicitly")
pushTimerToFinishedState(fixture.ensembleTimer());

assertThat(fixture.ensembleTimer().rotation().driver())
.as("rotate should not happen until we invoke #nextRound() explicitly")
.isEqualTo(fixture.driverId());
}

@Test
@Disabled
void rolesRotateWhenNextRoundInvokedOnFinishedTimer() {
RotationFixture fixture = createParticipantRotation();
pushTimerToFinishedState(fixture.ensembleTimer());

fixture.ensembleTimer().rotateRoles();

assertThat(fixture.ensembleTimer().rotation().driver())
.isEqualTo(fixture.nextDriverId());
}

private RotationFixture createParticipantRotation() {
MemberId nextDriverId = MemberId.of(1L);
MemberId driverId = MemberId.of(2L);
MemberId navigatorId = MemberId.of(3L);
Expand All @@ -179,14 +181,13 @@ void rolesRotateWhenNextRoundInvokedOnFinishedTimer() {
EnsembleTimer ensembleTimer = new EnsembleTimer(
EnsembleTimerFactory.IRRELEVANT_ENSEMBLE_ID,
EnsembleTimerFactory.IRRELEVANT_NAME,
List.of(driverId, navigatorId, nextDriverId, participantId1, participantId2),
List.of(nextDriverId, driverId, navigatorId, participantId1, participantId2),
Duration.ofMinutes(4));
pushTimerToFinishedState(ensembleTimer);

ensembleTimer.rotateRoles();
return new RotationFixture(driverId, nextDriverId, ensembleTimer);
}

assertThat(ensembleTimer.rotation().driver())
.isEqualTo(nextDriverId);
private record RotationFixture(MemberId driverId, MemberId nextDriverId,
EnsembleTimer ensembleTimer) {
}

private void pushTimerToFinishedState(EnsembleTimer ensembleTimer) {
Expand Down

0 comments on commit b1b7170

Please sign in to comment.