Skip to content

Commit

Permalink
test: ajustando casos de teste para o service do inbound e outbound
Browse files Browse the repository at this point in the history
  • Loading branch information
oLeoBarreto committed Mar 9, 2024
1 parent 4023d96 commit f33cc9a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.barreto.stockmanagement.useCases.inbound;

import com.barreto.stockmanagement.domains.documents.DocumentStatus;
import com.barreto.stockmanagement.domains.documents.Inbound;
import com.barreto.stockmanagement.domains.Product;
import com.barreto.stockmanagement.infra.DTOs.inbound.InboundPostRequestBody;
import com.barreto.stockmanagement.infra.DTOs.inbound.InboundStatusPutRequestBody;
import com.barreto.stockmanagement.infra.database.repository.InboundRepository;
import com.barreto.stockmanagement.useCases.product.ProductService;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -97,6 +99,20 @@ void testCreateNewInbound() {
Inbound inbound = inboundService.createInbound(inboundPostRequestBody);

assertNotNull(inbound);
assertTrue(inbound.getProduct().getStockQuantity() == 0F);
assertEquals("productId", inbound.getProduct().getId());
assertEquals(DocumentStatus.WAITING, inbound.getStatus());
}

@Test
@DisplayName("Should be able to change the status of a inbound document")
void testChangeDocStatus() {
InboundPostRequestBody inboundPostRequestBody = new InboundPostRequestBody(1F, "productId");
Inbound inbound = inboundService.createInbound(inboundPostRequestBody);

var docStatus = new InboundStatusPutRequestBody(inbound.getId(), DocumentStatus.COMPLETED);

assertDoesNotThrow(() -> inboundService.updateInboundStatus(docStatus));
assertTrue(inbound.getProduct().getStockQuantity() == 1F);
}

Expand All @@ -106,9 +122,7 @@ void testDeleteInbound() {
InboundPostRequestBody inboundPostRequestBody = new InboundPostRequestBody(1F, "productId");
Inbound inbound = inboundService.createInbound(inboundPostRequestBody);

inboundService.deleteInbound(inbound.id);

assertDoesNotThrow(() -> inboundService.deleteInbound(inbound.id));
assertTrue(repository.findAll().isEmpty());
assertTrue(inbound.getProduct().getStockQuantity() == 0F);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.barreto.stockmanagement.useCases.outbound;

import com.barreto.stockmanagement.domains.documents.DocumentStatus;
import com.barreto.stockmanagement.domains.documents.Outbound;
import com.barreto.stockmanagement.domains.Product;
import com.barreto.stockmanagement.infra.DTOs.outbound.OutboundPostRequestBody;
import com.barreto.stockmanagement.infra.DTOs.outbound.OutboundStatusPutRequestBody;
import com.barreto.stockmanagement.infra.database.repository.OutboundRepository;
import com.barreto.stockmanagement.useCases.product.ProductService;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -109,6 +111,23 @@ void testCreateNewOutbound() {
Outbound outbound = outboundService.createNewOutbound(outboundPostRequestBody);

assertNotNull(outbound);
assertTrue(outbound.getProduct().getStockQuantity() == 1F);
assertEquals(DocumentStatus.WAITING, outbound.getStatus());
assertEquals("productId", outbound.getProduct().getId());
}

@Test
@DisplayName("Should be able to change the status of a outbound document")
void testChangeDocStatus() {
OutboundPostRequestBody outboundPostRequestBody = new OutboundPostRequestBody(
1F,
"productId"
);
Outbound outbound = outboundService.createNewOutbound(outboundPostRequestBody);

var outboundStatusPutRequestBody = new OutboundStatusPutRequestBody(outbound.getId(), DocumentStatus.COMPLETED);

assertDoesNotThrow(() -> outboundService.updateOutboundStatus(outboundStatusPutRequestBody));
assertTrue(outbound.getProduct().getStockQuantity() == 0F);
}

Expand All @@ -121,9 +140,7 @@ void testDeleteOutbound() {
);
Outbound outbound = outboundService.createNewOutbound(outboundPostRequestBody);

outboundService.deleteOutbound(outbound.id);

assertDoesNotThrow(() -> outboundService.deleteOutbound(outbound.id));
assertTrue(repository.findAll().isEmpty());
assertTrue(outbound.getProduct().getStockQuantity() == 1F);
}
}

0 comments on commit f33cc9a

Please sign in to comment.