Files
smart-search-back/tests/request_handler_test.go
vallyenfail 9b4b8bd012
Some checks failed
Deploy Smart Search Backend / deploy (push) Failing after 13m51s
add service
2026-01-20 22:30:05 +03:00

269 lines
6.8 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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: "TestPassword123",
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: "TestPassword123",
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)
}
func (s *IntegrationSuite) TestRequestHandler_CreateTZWithFile() {
ctx := context.Background()
loginReq := &authpb.LoginRequest{
Email: "test@example.com",
Password: "TestPassword123",
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: "Нужны поставщики металлоконструкций",
FileData: []byte("Содержимое файла с дополнительными требованиями"),
FileName: "requirements.txt",
}
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_ApproveTZSuccess() {
ctx := context.Background()
loginReq := &authpb.LoginRequest{
Email: "test@example.com",
Password: "TestPassword123",
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)
userID := validateResp.UserId
createReq := &requestpb.CreateTZRequest{
UserId: userID,
RequestTxt: "Нужны поставщики кирпича для строительства",
}
createResp, err := s.requestClient.CreateTZ(ctx, createReq)
s.NoError(err)
s.NotEmpty(createResp.RequestId)
approveReq := &requestpb.ApproveTZRequest{
RequestId: createResp.RequestId,
FinalTz: "Утвержденное техническое задание на поставку кирпича",
UserId: userID,
}
approveResp, err := s.requestClient.ApproveTZ(ctx, approveReq)
s.NoError(err)
s.NotNil(approveResp)
s.NotEmpty(approveResp.RequestId)
s.NotNil(approveResp.Suppliers)
}
func (s *IntegrationSuite) TestRequestHandler_GetMailingListByIDSuccess() {
ctx := context.Background()
loginReq := &authpb.LoginRequest{
Email: "test@example.com",
Password: "TestPassword123",
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)
userID := validateResp.UserId
createReq := &requestpb.CreateTZRequest{
UserId: userID,
RequestTxt: "Нужны поставщики бетона",
}
createResp, err := s.requestClient.CreateTZ(ctx, createReq)
s.NoError(err)
s.NotEmpty(createResp.RequestId)
requestID := createResp.RequestId
approveReq := &requestpb.ApproveTZRequest{
RequestId: requestID,
FinalTz: "Утвержденное ТЗ на поставку бетона",
UserId: userID,
}
_, err = s.requestClient.ApproveTZ(ctx, approveReq)
s.NoError(err)
getByIDReq := &requestpb.GetMailingListByIDRequest{
RequestId: requestID,
UserId: userID,
}
getByIDResp, err := s.requestClient.GetMailingListByID(ctx, getByIDReq)
s.NoError(err)
s.NotNil(getByIDResp)
s.NotNil(getByIDResp.Detail)
s.Equal(requestID, getByIDResp.Detail.RequestId)
s.Greater(len(getByIDResp.Detail.Suppliers), 0)
}