Files
smart-search-back/internal/grpc/tests/request_handler_test.go
vallyenfail e2968722ed
Some checks failed
Deploy Smart Search Backend / deploy (push) Failing after 1m54s
add service
2026-01-17 20:41:37 +03:00

139 lines
3.3 KiB
Go

package tests
import (
"context"
authpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/auth"
requestpb "git.techease.ru/Smart-search/smart-search-back/pkg/pb/request"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (s *IntegrationSuite) TestRequestHandler_CreateTZWithNonExistentUser() {
req := &requestpb.CreateTZRequest{
UserId: 999999,
RequestTxt: "Нужны поставщики металлоконструкций",
}
resp, err := s.requestClient.CreateTZ(context.Background(), req)
s.Error(err)
s.Nil(resp)
st, ok := status.FromError(err)
s.True(ok)
s.Contains([]codes.Code{codes.NotFound, codes.Internal, codes.Unknown}, st.Code())
}
func (s *IntegrationSuite) TestRequestHandler_GetMailingListByIDWithNonExistent() {
req := &requestpb.GetMailingListByIDRequest{
RequestId: "999999",
UserId: 1,
}
resp, err := s.requestClient.GetMailingListByID(context.Background(), req)
s.Error(err)
s.Nil(resp)
st, ok := status.FromError(err)
s.True(ok)
s.Contains([]codes.Code{codes.NotFound, codes.Internal, codes.Unknown}, st.Code())
}
func (s *IntegrationSuite) TestRequestHandler_GetMailingListWithNonExistentUser() {
req := &requestpb.GetMailingListRequest{
UserId: 999999,
}
resp, err := s.requestClient.GetMailingList(context.Background(), req)
if err != nil {
st, ok := status.FromError(err)
s.True(ok)
s.Contains([]codes.Code{codes.NotFound, codes.Internal}, st.Code())
return
}
s.NotNil(resp)
s.Equal(0, len(resp.Items))
}
func (s *IntegrationSuite) TestRequestHandler_ApproveTZWithInvalidRequest() {
req := &requestpb.ApproveTZRequest{
RequestId: "999999",
FinalTz: "Approved TZ",
UserId: 1,
}
resp, err := s.requestClient.ApproveTZ(context.Background(), req)
s.Error(err)
s.Nil(resp)
st, ok := status.FromError(err)
s.True(ok)
s.Contains([]codes.Code{codes.NotFound, codes.Internal, codes.Unknown, codes.InvalidArgument}, st.Code())
}
func (s *IntegrationSuite) TestRequestHandler_CreateTZWithValidUser() {
ctx := context.Background()
loginReq := &authpb.LoginRequest{
Email: "test@example.com",
Password: "testpassword",
Ip: "127.0.0.1",
UserAgent: "integration-test",
}
loginResp, err := s.authClient.Login(ctx, loginReq)
s.NoError(err)
validateReq := &authpb.ValidateRequest{
AccessToken: loginResp.AccessToken,
}
validateResp, err := s.authClient.Validate(ctx, validateReq)
s.NoError(err)
req := &requestpb.CreateTZRequest{
UserId: validateResp.UserId,
RequestTxt: "Нужны поставщики металлоконструкций",
}
resp, err := s.requestClient.CreateTZ(ctx, req)
s.NoError(err)
s.NotNil(resp)
s.NotEmpty(resp.RequestId)
s.NotEmpty(resp.TzText)
}
func (s *IntegrationSuite) TestRequestHandler_GetMailingListWithValidUser() {
ctx := context.Background()
loginReq := &authpb.LoginRequest{
Email: "test@example.com",
Password: "testpassword",
Ip: "127.0.0.1",
UserAgent: "integration-test",
}
loginResp, err := s.authClient.Login(ctx, loginReq)
s.NoError(err)
validateReq := &authpb.ValidateRequest{
AccessToken: loginResp.AccessToken,
}
validateResp, err := s.authClient.Validate(ctx, validateReq)
s.NoError(err)
req := &requestpb.GetMailingListRequest{
UserId: validateResp.UserId,
}
resp, err := s.requestClient.GetMailingList(ctx, req)
s.NoError(err)
s.NotNil(resp)
}