mirror of
https://github.com/3ybactuk/marketplace-go-service-project.git
synced 2025-10-30 14:03:45 +03:00
[hw-3] loms service
This commit is contained in:
130
loms/tests/integration/loms_integration_test.go
Normal file
130
loms/tests/integration/loms_integration_test.go
Normal file
@@ -0,0 +1,130 @@
|
||||
//go:build integration
|
||||
// +build integration
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/ozontech/allure-go/pkg/framework/provider"
|
||||
"github.com/ozontech/allure-go/pkg/framework/suite"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
|
||||
"route256/loms/internal/app/server"
|
||||
"route256/loms/internal/domain/entity"
|
||||
ordersRepository "route256/loms/internal/domain/repository/orders"
|
||||
stocksRepository "route256/loms/internal/domain/repository/stocks"
|
||||
lomsService "route256/loms/internal/domain/service"
|
||||
|
||||
pb "route256/pkg/api/loms/v1"
|
||||
)
|
||||
|
||||
const (
|
||||
// "total_count": 100,
|
||||
// "reserved": 35
|
||||
testSKU = entity.Sku(1076963)
|
||||
|
||||
testUID = entity.ID(1337)
|
||||
testCount = uint32(2)
|
||||
)
|
||||
|
||||
type LomsIntegrationSuite struct {
|
||||
suite.Suite
|
||||
|
||||
grpcSrv *grpc.Server
|
||||
grpcConn *grpc.ClientConn
|
||||
lomsClient pb.LOMSClient
|
||||
}
|
||||
|
||||
func TestLomsIntegrationSuite(t *testing.T) {
|
||||
suite.RunSuite(t, new(LomsIntegrationSuite))
|
||||
}
|
||||
|
||||
func (s *LomsIntegrationSuite) BeforeAll(t provider.T) {
|
||||
t.WithNewStep("init cart-service", func(sCtx provider.StepCtx) {
|
||||
orderRepo := ordersRepository.NewInMemoryRepository(100)
|
||||
stockRepo, err := stocksRepository.NewInMemoryRepository(100)
|
||||
sCtx.Require().NoError(err)
|
||||
|
||||
svc := lomsService.NewLomsService(orderRepo, stockRepo)
|
||||
lomsServer := server.NewServer(svc)
|
||||
|
||||
lis, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
sCtx.Require().NoError(err)
|
||||
|
||||
s.grpcSrv = grpc.NewServer()
|
||||
pb.RegisterLOMSServer(s.grpcSrv, lomsServer)
|
||||
|
||||
go func() { _ = s.grpcSrv.Serve(lis) }()
|
||||
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
conn, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
|
||||
sCtx.Require().NoError(err)
|
||||
|
||||
s.grpcConn = conn
|
||||
s.lomsClient = pb.NewLOMSClient(conn)
|
||||
})
|
||||
}
|
||||
|
||||
func (s *LomsIntegrationSuite) AfterAll(t provider.T) {
|
||||
s.grpcSrv.Stop()
|
||||
_ = s.grpcConn.Close()
|
||||
}
|
||||
|
||||
func (s *LomsIntegrationSuite) TestOrderProcessPositive(t provider.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
var orderID int64
|
||||
|
||||
t.WithNewStep("create order", func(sCtx provider.StepCtx) {
|
||||
req := &pb.OrderCreateRequest{
|
||||
UserId: int64(testUID),
|
||||
Items: []*pb.OrderItem{{
|
||||
Sku: int64(testSKU),
|
||||
Count: testCount,
|
||||
}},
|
||||
}
|
||||
|
||||
resp, err := s.lomsClient.OrderCreate(ctx, req)
|
||||
sCtx.Require().NoError(err)
|
||||
sCtx.Require().Greater(resp.OrderId, int64(0))
|
||||
orderID = resp.OrderId
|
||||
})
|
||||
|
||||
t.WithNewStep("verify order info (NEW)", func(sCtx provider.StepCtx) {
|
||||
resp, err := s.lomsClient.OrderInfo(ctx, &pb.OrderInfoRequest{OrderId: orderID})
|
||||
sCtx.Require().NoError(err)
|
||||
|
||||
sCtx.Require().Equal("awaiting payment", resp.Status)
|
||||
sCtx.Require().Equal(int64(testUID), resp.UserId)
|
||||
sCtx.Require().Len(resp.Items, 1)
|
||||
sCtx.Require().Equal(int64(testSKU), resp.Items[0].Sku)
|
||||
sCtx.Require().Equal(testCount, resp.Items[0].Count)
|
||||
})
|
||||
|
||||
t.WithNewStep("pay order", func(sCtx provider.StepCtx) {
|
||||
_, err := s.lomsClient.OrderPay(ctx, &pb.OrderPayRequest{OrderId: orderID})
|
||||
sCtx.Require().NoError(err)
|
||||
})
|
||||
|
||||
t.WithNewStep("verify order info (PAYED)", func(sCtx provider.StepCtx) {
|
||||
resp, err := s.lomsClient.OrderInfo(ctx, &pb.OrderInfoRequest{OrderId: orderID})
|
||||
sCtx.Require().NoError(err)
|
||||
sCtx.Require().Equal("payed", resp.Status)
|
||||
})
|
||||
}
|
||||
|
||||
func (s *LomsIntegrationSuite) TestStocksInfoPositive(t provider.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
t.WithNewStep("call StocksInfo", func(sCtx provider.StepCtx) {
|
||||
resp, err := s.lomsClient.StocksInfo(ctx, &pb.StocksInfoRequest{Sku: int64(testSKU)})
|
||||
sCtx.Require().NoError(err)
|
||||
sCtx.Require().Greater(resp.Count, uint32(0))
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user