feat: update profit sharing
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"apskel-pos-be/internal/constants"
|
||||
"apskel-pos-be/internal/entities"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// teamCategoryRepositoryStub serves the two lookups the team rules make. The embedded
|
||||
// interface is left nil, so any other call panics and shows up in the test.
|
||||
type teamCategoryRepositoryStub struct {
|
||||
CategoryRepository
|
||||
categories []*entities.Category
|
||||
}
|
||||
|
||||
func (s *teamCategoryRepositoryStub) ListParentCategories(ctx context.Context, organizationID uuid.UUID, outletID *uuid.UUID) ([]*entities.Category, error) {
|
||||
return s.categories, nil
|
||||
}
|
||||
|
||||
func (s *teamCategoryRepositoryStub) GetByID(ctx context.Context, id uuid.UUID) (*entities.Category, error) {
|
||||
for _, category := range s.categories {
|
||||
if category.ID == id {
|
||||
return category, nil
|
||||
}
|
||||
}
|
||||
return nil, errors.New("record not found")
|
||||
}
|
||||
|
||||
func TestListTeamsSkipsParentCategoriesThatAreNotTeams(t *testing.T) {
|
||||
organizationID := uuid.New()
|
||||
food := &entities.Category{ID: uuid.New(), OrganizationID: organizationID, Name: "Food", IsTeam: true}
|
||||
merch := &entities.Category{ID: uuid.New(), OrganizationID: organizationID, Name: "Merchandise", IsTeam: false}
|
||||
repo := &teamCategoryRepositoryStub{categories: []*entities.Category{food, merch}}
|
||||
|
||||
result, err := listTeams(context.Background(), repo, organizationID, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, result.Teams, 2)
|
||||
require.Equal(t, "Food", result.Teams[0].Name)
|
||||
require.Equal(t, &food.ID, result.Teams[0].CategoryID)
|
||||
require.Equal(t, constants.PurchaseTeamCentralName, result.Teams[1].Name)
|
||||
}
|
||||
|
||||
func TestResolveTeamSelectionRejectsParentCategoryThatIsNotATeam(t *testing.T) {
|
||||
organizationID := uuid.New()
|
||||
food := &entities.Category{ID: uuid.New(), OrganizationID: organizationID, Name: "Food", IsTeam: true}
|
||||
merch := &entities.Category{ID: uuid.New(), OrganizationID: organizationID, Name: "Merchandise", IsTeam: false}
|
||||
repo := &teamCategoryRepositoryStub{categories: []*entities.Category{food, merch}}
|
||||
scope := constants.PurchaseTeamScopeCategory
|
||||
|
||||
resolvedScope, resolvedID, err := resolveTeamSelection(context.Background(), repo, organizationID, nil, &scope, &food.ID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, constants.PurchaseTeamScopeCategory, *resolvedScope)
|
||||
require.Equal(t, food.ID, *resolvedID)
|
||||
|
||||
_, _, err = resolveTeamSelection(context.Background(), repo, organizationID, nil, &scope, &merch.ID)
|
||||
require.EqualError(t, err, "category Merchandise is not a team")
|
||||
}
|
||||
Reference in New Issue
Block a user