Skip to content

Commit

Permalink
live-event-done
Browse files Browse the repository at this point in the history
  • Loading branch information
yacekmm committed Dec 6, 2024
1 parent 7590409 commit 904e543
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@

public class FakeEventPublisher implements EventPublisher {

private List<Event> events = new ArrayList<>();

@Override
public Either<ErrorResult, String> publish(Event event) {
//TODO store events for later assertion
events.add(event);
return Either.right(null);
}

public Event singleEvent() {
//TODO assert that there is only one event
//TODO return it
return null;
assertThat(events).hasSize(1);
return events.getFirst();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public Either<ErrorResult, Concert> createConcert(String title, String dateTime,
}
return concertFactory.createConcert(title, dateTime, promoterAgreement.promoterId())
.peek(concert -> concert.initNewConcert(tagService, categoryService))
.map(concertRepo::save);
//TODO publish event
.map(concertRepo::save)
.peek(concert -> eventPublisher.publish(concertCreated(concert, promoterAgreement.profitMarginPercentage())));
}

public Either<ErrorResult, List<Price>> discountConcert(String concertId, int percentage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.bottega.promoter.agreements.PromoterAgreement;
import com.bottega.promoter.concert.domain.Concert;
import com.bottega.promoter.concert.fixtures.*;
import com.bottega.promoter.concert.fixtures.ConcertLogicTestBase;
import com.bottega.promoter.concert.fixtures.clients.ConcertHttpClient;
import com.bottega.sharedlib.fixtures.RepoEntries;
import com.bottega.sharedlib.vo.error.ErrorResult;
Expand Down Expand Up @@ -68,12 +68,17 @@ void createConcert_returnsError_onPromoterIdNotFound() {
@Test
void createConcert_publishesEvent_onValidInput() {
//given
//TODO implement
PromoterAgreement promoterAgreement = builders.aPromoterAgreement().build();
given(concertFixtures.promoterService.getPromoterAgreement(anyString())).willReturn(promoterAgreement);

//when
Either<ErrorResult, Concert> result = concertFixtures.concertService.createConcert("Woodstock 2000", TEST_TIME_PLUS_30_DAYS.toString(), promoterAgreement.promoterId().asString());

//then
//TODO use ConcertCreatedEventAssert
assertThat(result).hasRightValueSatisfying(concert ->
assertThatEvent(sharedFixtures.fakeEventPublisher().singleEvent())
.isConcertCreatedV1(concert, promoterAgreement.profitMarginPercentage())
);
}

}

0 comments on commit 904e543

Please sign in to comment.