-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testing and fixing GetPendingTerminations
- Loading branch information
1 parent
53b435a
commit 4ff78ef
Showing
3 changed files
with
140 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
services/contracts/src/test/java/com/workup/contracts/GetPendingTerminationsTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package com.workup.contracts; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import com.workup.contracts.models.TerminationRequest; | ||
import com.workup.contracts.repositories.TerminationRequestRepository; | ||
import com.workup.shared.commands.contracts.requests.GetPendingTerminationsRequest; | ||
import com.workup.shared.commands.contracts.requests.InitiateContractRequest; | ||
import com.workup.shared.commands.contracts.responses.GetPendingTerminationsResponse; | ||
import com.workup.shared.commands.contracts.responses.InitiateContractResponse; | ||
import com.workup.shared.enums.HttpStatusCode; | ||
import com.workup.shared.enums.ServiceQueueNames; | ||
import com.workup.shared.enums.contracts.TerminationRequestStatus; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.UUID; | ||
import org.springframework.amqp.core.AmqpTemplate; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class GetPendingTerminationsTests { | ||
|
||
@Autowired TerminationRequestRepository terminationRequestRepository; | ||
|
||
public void invalidContract(AmqpTemplate template) { | ||
GetPendingTerminationsRequest request = | ||
GetPendingTerminationsRequest.builder() | ||
.withContractId(UUID.randomUUID().toString()) | ||
.build(); | ||
|
||
GetPendingTerminationsResponse response = | ||
(GetPendingTerminationsResponse) | ||
template.convertSendAndReceive(ServiceQueueNames.CONTRACTS, request); | ||
assertNotNull(response); | ||
assertEquals(HttpStatusCode.BAD_REQUEST, response.getStatusCode()); | ||
} | ||
|
||
public void successTest(AmqpTemplate template) { | ||
// create contract | ||
String clientId = UUID.randomUUID().toString(), freelancerId = UUID.randomUUID().toString(); | ||
InitiateContractRequest initiateContractRequest = | ||
InitiateContractRequest.builder() | ||
.withClientId(clientId) | ||
.withFreelancerId(freelancerId) | ||
.withJobId("789") | ||
.withProposalId("bruh") | ||
.withJobTitle("very happy guc worker :)") | ||
.withJobMilestones(new ArrayList<>()) | ||
.build(); | ||
|
||
InitiateContractResponse contractResponse = | ||
(InitiateContractResponse) | ||
template.convertSendAndReceive(ServiceQueueNames.CONTRACTS, initiateContractRequest); | ||
|
||
assertNotNull(contractResponse); | ||
assertEquals(HttpStatusCode.CREATED, contractResponse.getStatusCode()); | ||
|
||
String request1 = UUID.randomUUID().toString(), request2 = UUID.randomUUID().toString(); | ||
TerminationRequest clientTerminationRequest = | ||
TerminationRequest.builder() | ||
.withRequestId(UUID.fromString(request1)) | ||
.withReason("m4 3agebny el 4o8l da1") | ||
.withContractId(contractResponse.getContractId()) | ||
.withRequesterId(clientId) | ||
.withStatus(TerminationRequestStatus.PENDING) | ||
.build(); | ||
|
||
TerminationRequest freelancerTerminationRequest = | ||
TerminationRequest.builder() | ||
.withRequestId(UUID.fromString(request2)) | ||
.withReason("m4 3agebny el 4o8l da2") | ||
.withContractId(contractResponse.getContractId()) | ||
.withRequesterId(freelancerId) | ||
.withStatus(TerminationRequestStatus.PENDING) | ||
.build(); | ||
|
||
HashMap<String, TerminationRequest> expectedTerminationRequests = new HashMap<>(); | ||
expectedTerminationRequests.put(freelancerId, freelancerTerminationRequest); | ||
expectedTerminationRequests.put(clientId, clientTerminationRequest); | ||
|
||
try { | ||
terminationRequestRepository.save(freelancerTerminationRequest); | ||
terminationRequestRepository.save(clientTerminationRequest); | ||
|
||
// Now Get the pending requests :D | ||
GetPendingTerminationsRequest request = | ||
GetPendingTerminationsRequest.builder() | ||
.withContractId(contractResponse.getContractId()) | ||
.build(); | ||
|
||
GetPendingTerminationsResponse response = | ||
(GetPendingTerminationsResponse) | ||
template.convertSendAndReceive(ServiceQueueNames.CONTRACTS, request); | ||
|
||
assertNotNull(response); | ||
assertEquals(HttpStatusCode.OK, response.getStatusCode()); | ||
|
||
response | ||
.getTerminationRequests() | ||
.forEach( | ||
req -> { | ||
TerminationRequest correspondent = | ||
expectedTerminationRequests.get(req.getRequesterId()); | ||
assertEquals(correspondent.getStatus(), req.getStatus()); | ||
assertEquals(correspondent.getContractId(), req.getContractId()); | ||
assertEquals(correspondent.getReason(), req.getReason()); | ||
assertEquals(correspondent.getRequestId().toString(), req.getRequestId()); | ||
assertEquals(correspondent.getRequesterId(), req.getRequesterId()); | ||
}); | ||
} catch (Exception e) { | ||
fail("Error has occurred in the GetPending TerminationRequests Tests"); | ||
} | ||
} | ||
} |