Skip to content

Commit

Permalink
unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
manuraf committed Jan 19, 2024
1 parent e16f295 commit ad837fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void deleteOK(){
given()
.when()
.pathParam("onboardingId", onboardingId)
.put("/{onboardingId}/delete")
.put("/{onboardingId}/reject")
.then()
.statusCode(204);

Expand All @@ -259,7 +259,7 @@ void deleteInvalidOnboardingIdOrOnboardingNotFound(){
given()
.when()
.pathParam("onboardingId", onboardingId)
.put("/{onboardingId}/delete")
.put("/{onboardingId}/reject")
.then()
.statusCode(400);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1003,10 +1003,15 @@ private Onboarding createDummyOnboarding() {

@Test
void testOnboardingUpdateStatusOK() {
String onboardingId = "655df045dc52ea5f37c80955";
mockUpdateOnboarding(onboardingId, 1L);

Onboarding onboarding = createDummyOnboarding();
PanacheMock.mock(Onboarding.class);
when(Onboarding.findById(onboarding.getId()))
.thenReturn(Uni.createFrom().item(onboarding));

mockUpdateOnboarding(onboarding.getId().toHexString(), 1L);
UniAssertSubscriber<Long> subscriber = onboardingService
.rejectOnboarding(onboardingId)
.rejectOnboarding(onboarding.getId().toHexString())
.subscribe()
.withSubscriber(UniAssertSubscriber.create());

Expand All @@ -1026,20 +1031,25 @@ void testOnboardingUpdateStatusInvalidOnboardingId() {

@Test
void testOnboardingDeleteOnboardingNotFoundOrAlreadyDeleted() {
String onboardingId = "655df045dc52ea5f37c80955";
mockUpdateOnboarding(onboardingId, 0L);

Onboarding onboarding = createDummyOnboarding();
PanacheMock.mock(Onboarding.class);
when(Onboarding.findById(onboarding.getId()))
.thenReturn(Uni.createFrom().item(onboarding));
mockUpdateOnboarding(onboarding.getId().toHexString(), 0L);

UniAssertSubscriber<Long> subscriber = onboardingService
.rejectOnboarding(onboardingId)
.rejectOnboarding(onboarding.getId().toHexString())
.subscribe()
.withSubscriber(UniAssertSubscriber.create());

subscriber.assertFailedWith(InvalidRequestException.class, "Onboarding with id 655df045dc52ea5f37c80955 not found or already deleted");
subscriber.assertFailedWith(InvalidRequestException.class);
}

private void mockUpdateOnboarding(String onboardingId, Long updatedItemCount) {
ReactivePanacheUpdate query = mock(ReactivePanacheUpdate.class);
PanacheMock.mock(Onboarding.class);
when(Onboarding.update(Onboarding.Fields.status.name(), OnboardingStatus.DELETED)).thenReturn(query);
when(Onboarding.update(Onboarding.Fields.status.name(), OnboardingStatus.REJECTED)).thenReturn(query);
when(query.where("_id", onboardingId)).thenReturn(Uni.createFrom().item(updatedItemCount));
}

Expand Down

0 comments on commit ad837fb

Please sign in to comment.