-
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.
- Loading branch information
1 parent
96b45ea
commit bba9713
Showing
3 changed files
with
167 additions
and
0 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
128 changes: 128 additions & 0 deletions
128
services/contracts/src/test/java/com/workup/contracts/EvaluateMilestoneTests.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,128 @@ | ||
package com.workup.contracts; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import com.workup.contracts.models.ContractMilestone; | ||
import com.workup.contracts.repositories.ContractMilestoneRepository; | ||
import com.workup.shared.commands.contracts.Milestone; | ||
import com.workup.shared.commands.contracts.requests.EvaluateMilestoneRequest; | ||
import com.workup.shared.commands.contracts.requests.InitiateContractRequest; | ||
import com.workup.shared.commands.contracts.responses.EvaluateMilestoneResponse; | ||
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.MilestoneState; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
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 EvaluateMilestoneTests { | ||
|
||
@Autowired ContractMilestoneRepository contractMilestoneRepository; | ||
|
||
public void milestoneNotFoundTest(AmqpTemplate template) { | ||
|
||
// Send the request with random milestone and it should not be found | ||
EvaluateMilestoneRequest request = | ||
EvaluateMilestoneRequest.builder() | ||
.withMilestoneId(String.valueOf(UUID.randomUUID())) | ||
.withEvaluatedState(MilestoneState.ACCEPTED) | ||
.build(); | ||
|
||
EvaluateMilestoneResponse response = | ||
(EvaluateMilestoneResponse) | ||
template.convertSendAndReceive(ServiceQueueNames.CONTRACTS, request); | ||
|
||
assertNotNull(response); | ||
|
||
assertEquals(HttpStatusCode.BAD_REQUEST, response.getStatusCode()); | ||
assertEquals("Milestone is not found", response.getErrorMessage()); | ||
} | ||
|
||
public void wrongMilestoneState(AmqpTemplate template) { | ||
// Create a Milestone and add it to the db and then check this milestone | ||
// In progress (not ready for evaluation) | ||
String milestoneId = UUID.randomUUID().toString(); | ||
|
||
EvaluateMilestoneRequest request = | ||
EvaluateMilestoneRequest.builder() | ||
.withMilestoneId(milestoneId) | ||
.withEvaluatedState(MilestoneState.ACCEPTED) | ||
.build(); | ||
|
||
ContractMilestone dbMilestone = | ||
ContractMilestone.builder() | ||
.withMilestoneId(UUID.fromString(milestoneId)) | ||
.withContractId(UUID.randomUUID().toString()) | ||
.withAmount(500) | ||
.withDescription("Backend Boi") | ||
.withDueDate(new Date()) | ||
.withStatus(MilestoneState.IN_PROGRESS) | ||
.build(); | ||
|
||
contractMilestoneRepository.save(dbMilestone); | ||
|
||
EvaluateMilestoneResponse response = | ||
(EvaluateMilestoneResponse) | ||
template.convertSendAndReceive(ServiceQueueNames.CONTRACTS, request); | ||
|
||
assertNotNull(response); | ||
assertEquals(HttpStatusCode.BAD_REQUEST, response.getStatusCode()); | ||
assertEquals( | ||
"Milestone cannot be evaluated as it has not progressed enough", | ||
response.getErrorMessage()); | ||
} | ||
|
||
// TODO: @Karim ElMosallamy | ||
public void successTest(AmqpTemplate template) throws ParseException { | ||
// create a milestone with it's contract, and evaluate this milestone | ||
String milestoneId = UUID.randomUUID().toString(); | ||
Milestone milestone = | ||
Milestone.builder() | ||
.withMilestoneId(milestoneId) | ||
.withDescription("make sure the students hate your admin system") | ||
.withDueDate(new SimpleDateFormat("yyyy-MM-dd").parse("2025-01-01")) | ||
.withAmount(30000) | ||
.withStatus(MilestoneState.IN_REVIEW) | ||
.build(); | ||
|
||
List<Milestone> milestones = new ArrayList<>(); | ||
milestones.add(milestone); | ||
|
||
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(milestones) | ||
.build(); | ||
InitiateContractResponse contractResponse = | ||
(InitiateContractResponse) | ||
template.convertSendAndReceive(ServiceQueueNames.CONTRACTS, initiateContractRequest); | ||
|
||
assertNotNull(contractResponse); | ||
|
||
EvaluateMilestoneRequest request = | ||
EvaluateMilestoneRequest.builder() | ||
.withMilestoneId(milestoneId) | ||
.withEvaluatedState(MilestoneState.ACCEPTED) | ||
.build(); | ||
|
||
EvaluateMilestoneResponse response = | ||
(EvaluateMilestoneResponse) | ||
template.convertSendAndReceive(ServiceQueueNames.CONTRACTS, request); | ||
|
||
assertNotNull(response); | ||
assertEquals(HttpStatusCode.OK, response.getStatusCode()); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
services/contracts/src/test/java/com/workup/contracts/PaymentsMockingListener.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,17 @@ | ||
package com.workup.contracts; | ||
|
||
import com.workup.shared.commands.payments.paymentrequest.requests.CreatePaymentRequestRequest; | ||
import com.workup.shared.commands.payments.paymentrequest.responses.CreatePaymentRequestResponse; | ||
import com.workup.shared.enums.HttpStatusCode; | ||
import com.workup.shared.enums.ServiceQueueNames; | ||
import org.springframework.amqp.rabbit.annotation.RabbitListener; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RabbitListener(queues = ServiceQueueNames.PAYMENTS) | ||
public class PaymentsMockingListener { | ||
|
||
CreatePaymentRequestResponse receive(CreatePaymentRequestRequest req) { | ||
return CreatePaymentRequestResponse.builder().withStatusCode(HttpStatusCode.OK).build(); | ||
} | ||
} |