unit test bet outcome
This commit is contained in:
parent
c637ddb321
commit
95eaed18ad
|
|
@ -4177,7 +4177,7 @@ const docTemplate = `{
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Virtual Games"
|
||||
"Veli Games"
|
||||
],
|
||||
"summary": "Veli Games webhook handler",
|
||||
"parameters": [
|
||||
|
|
|
|||
|
|
@ -4169,7 +4169,7 @@
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Virtual Games"
|
||||
"Veli Games"
|
||||
],
|
||||
"summary": "Veli Games webhook handler",
|
||||
"parameters": [
|
||||
|
|
|
|||
|
|
@ -4258,7 +4258,7 @@ paths:
|
|||
type: object
|
||||
summary: Veli Games webhook handler
|
||||
tags:
|
||||
- Virtual Games
|
||||
- Veli Games
|
||||
securityDefinitions:
|
||||
Bearer:
|
||||
in: header
|
||||
|
|
|
|||
|
|
@ -498,9 +498,9 @@ func evaluateTotalOverUnder(outcome domain.BetOutcome, score struct{ Home, Away
|
|||
return domain.OUTCOME_STATUS_ERROR, fmt.Errorf("invalid odd header: %s", outcome.OddHeader)
|
||||
}
|
||||
|
||||
// Result and Total betting is a type of bet where the bettor predicts
|
||||
// the outcome of a match and whether the total number of points scored will be over or under a specified number.
|
||||
func evaluateResultAndTotal(outcome domain.BetOutcome, score struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
// Result and Total betting is a type of bet where the bettor predicts
|
||||
// the outcome of a match and whether the total number of points scored will be over or under a specified number.
|
||||
func evaluateResultAndTotal(outcome domain.BetOutcome, score struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
|
||||
// The handicap will be in the format "U {float}" or "O {float}"
|
||||
// U and O denoting over and under for this case
|
||||
|
|
@ -548,11 +548,11 @@ func evaluateResultAndTotal(outcome domain.BetOutcome, score struct{ Home, Away
|
|||
default:
|
||||
return domain.OUTCOME_STATUS_ERROR, fmt.Errorf("failed to parse over and under: %s", outcome.OddName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Team Total betting is a type of bet where the bettor predicts the total number of points scored by a specific team in a match
|
||||
// is over or under a specified number.
|
||||
func evaluateTeamTotal(outcome domain.BetOutcome, score struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
// Team Total betting is a type of bet where the bettor predicts the total number of points scored by a specific team in a match
|
||||
// is over or under a specified number.
|
||||
func evaluateTeamTotal(outcome domain.BetOutcome, score struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
|
||||
// The handicap will be in the format "U {float}" or "O {float}"
|
||||
// U and O denoting over and under for this case
|
||||
|
|
@ -594,11 +594,11 @@ func evaluateTeamTotal(outcome domain.BetOutcome, score struct{ Home, Away int }
|
|||
default:
|
||||
return domain.OUTCOME_STATUS_ERROR, fmt.Errorf("failed to parse over and under: %s", outcome.OddName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Result and Both Teams To Score X Points is a type of bet where the bettor predicts whether both teams will score a certain number of points
|
||||
// and also the result fo the match
|
||||
func evaluateResultAndBTTSX(outcome domain.BetOutcome, score struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
// Result and Both Teams To Score X Points is a type of bet where the bettor predicts whether both teams will score a certain number of points
|
||||
// and also the result fo the match
|
||||
func evaluateResultAndBTTSX(outcome domain.BetOutcome, score struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
|
||||
// The name parameter will hold value "name": "{team_name} and {Yes | No}"
|
||||
// The best way to do this is to evaluate backwards since there might be
|
||||
|
|
@ -646,10 +646,10 @@ func evaluateResultAndBTTSX(outcome domain.BetOutcome, score struct{ Home, Away
|
|||
|
||||
return domain.OUTCOME_STATUS_LOSS, nil
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Both Teams To Score X Points is a type of bet where the bettor predicts whether both teams will score a certain number of points.
|
||||
func evaluateBTTSX(outcome domain.BetOutcome, score struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
// Both Teams To Score X Points is a type of bet where the bettor predicts whether both teams will score a certain number of points.
|
||||
func evaluateBTTSX(outcome domain.BetOutcome, score struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
threshold, err := strconv.ParseInt(outcome.OddName, 10, 64)
|
||||
if err != nil {
|
||||
return domain.OUTCOME_STATUS_ERROR, fmt.Errorf("invalid threshold: %s", outcome.OddName)
|
||||
|
|
@ -670,10 +670,10 @@ func evaluateBTTSX(outcome domain.BetOutcome, score struct{ Home, Away int }) (d
|
|||
}
|
||||
|
||||
return domain.OUTCOME_STATUS_LOSS, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Money Line 3 Way betting is a type of bet where the bettor predicts the outcome of a match with three possible outcomes: home win, away win, or draw.
|
||||
func evaluateMoneyLine3Way(outcome domain.BetOutcome, score struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
// Money Line 3 Way betting is a type of bet where the bettor predicts the outcome of a match with three possible outcomes: home win, away win, or draw.
|
||||
func evaluateMoneyLine3Way(outcome domain.BetOutcome, score struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
switch outcome.OddName {
|
||||
case "1": // Home win
|
||||
if score.Home > score.Away {
|
||||
|
|
@ -693,10 +693,10 @@ func evaluateMoneyLine3Way(outcome domain.BetOutcome, score struct{ Home, Away i
|
|||
default:
|
||||
return domain.OUTCOME_STATUS_ERROR, fmt.Errorf("invalid odd name: %s", outcome.OddName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Double Result betting is a type of bet where the bettor predicts the outcome of a match at both half-time and full-time.
|
||||
func evaluateDoubleResult(outcome domain.BetOutcome, firstHalfScore struct{ Home, Away int }, secondHalfScore struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
// Double Result betting is a type of bet where the bettor predicts the outcome of a match at both half-time and full-time.
|
||||
func evaluateDoubleResult(outcome domain.BetOutcome, firstHalfScore struct{ Home, Away int }, secondHalfScore struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
halfWins := strings.Split(outcome.OddName, "-")
|
||||
if len(halfWins) != 2 {
|
||||
return domain.OUTCOME_STATUS_ERROR, fmt.Errorf("invalid odd name: %s", outcome.OddName)
|
||||
|
|
@ -730,10 +730,10 @@ func evaluateDoubleResult(outcome domain.BetOutcome, firstHalfScore struct{ Home
|
|||
}
|
||||
|
||||
return domain.OUTCOME_STATUS_WIN, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Highest Scoring Half betting is a type of bet where the bettor predicts which half of the match will have the highest total score.
|
||||
func evaluateHighestScoringHalf(outcome domain.BetOutcome, firstScore struct{ Home, Away int }, secondScore struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
// Highest Scoring Half betting is a type of bet where the bettor predicts which half of the match will have the highest total score.
|
||||
func evaluateHighestScoringHalf(outcome domain.BetOutcome, firstScore struct{ Home, Away int }, secondScore struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
firstHalfTotal := firstScore.Home + firstScore.Away
|
||||
secondHalfTotal := secondScore.Home + secondScore.Away
|
||||
switch outcome.OddName {
|
||||
|
|
@ -753,10 +753,10 @@ func evaluateHighestScoringHalf(outcome domain.BetOutcome, firstScore struct{ Ho
|
|||
return domain.OUTCOME_STATUS_ERROR, fmt.Errorf("invalid oddname: %s", outcome.OddName)
|
||||
}
|
||||
return domain.OUTCOME_STATUS_LOSS, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Highest Scoring Quarter betting is a type of bet where the bettor predicts which quarter of the match will have the highest score.
|
||||
func evaluateHighestScoringQuarter(outcome domain.BetOutcome, firstScore struct{ Home, Away int }, secondScore struct{ Home, Away int }, thirdScore struct{ Home, Away int }, fourthScore struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
// Highest Scoring Quarter betting is a type of bet where the bettor predicts which quarter of the match will have the highest score.
|
||||
func evaluateHighestScoringQuarter(outcome domain.BetOutcome, firstScore struct{ Home, Away int }, secondScore struct{ Home, Away int }, thirdScore struct{ Home, Away int }, fourthScore struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
firstQuarterTotal := firstScore.Home + firstScore.Away
|
||||
secondQuarterTotal := secondScore.Home + secondScore.Away
|
||||
thirdQuarterTotal := thirdScore.Home + thirdScore.Away
|
||||
|
|
@ -787,10 +787,10 @@ func evaluateHighestScoringQuarter(outcome domain.BetOutcome, firstScore struct{
|
|||
return domain.OUTCOME_STATUS_ERROR, fmt.Errorf("invalid oddname: %s", outcome.OddName)
|
||||
}
|
||||
return domain.OUTCOME_STATUS_LOSS, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Team With Highest Scoring Quarter betting is a type of bet where the bettor predicts which team will have the highest score in a specific quarter.
|
||||
func evaluateTeamWithHighestScoringQuarter(outcome domain.BetOutcome, firstScore struct{ Home, Away int }, secondScore struct{ Home, Away int }, thirdScore struct{ Home, Away int }, fourthScore struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
// Team With Highest Scoring Quarter betting is a type of bet where the bettor predicts which team will have the highest score in a specific quarter.
|
||||
func evaluateTeamWithHighestScoringQuarter(outcome domain.BetOutcome, firstScore struct{ Home, Away int }, secondScore struct{ Home, Away int }, thirdScore struct{ Home, Away int }, fourthScore struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
homeTeamHighestQuarter := max(firstScore.Home, secondScore.Home, thirdScore.Home, fourthScore.Home)
|
||||
awayTeamHighestQuarter := max(firstScore.Away, secondScore.Away, thirdScore.Away, fourthScore.Away)
|
||||
|
||||
|
|
@ -811,11 +811,11 @@ func evaluateTeamWithHighestScoringQuarter(outcome domain.BetOutcome, firstScore
|
|||
return domain.OUTCOME_STATUS_ERROR, fmt.Errorf("invalid oddname: %s", outcome.OddName)
|
||||
}
|
||||
return domain.OUTCOME_STATUS_LOSS, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Handicap and Total betting is a combination of spread betting and total points betting
|
||||
// where the bettor predicts the outcome of a match with a point spread and the total number of points scored is over or under a specified number.
|
||||
func evaluateHandicapAndTotal(outcome domain.BetOutcome, score struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
// Handicap and Total betting is a combination of spread betting and total points betting
|
||||
// where the bettor predicts the outcome of a match with a point spread and the total number of points scored is over or under a specified number.
|
||||
func evaluateHandicapAndTotal(outcome domain.BetOutcome, score struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
|
||||
nameSplit := strings.Split(outcome.OddName, " ")
|
||||
// Evaluate from bottom to get the threshold and find out if its over or under
|
||||
|
|
@ -864,10 +864,10 @@ func evaluateHandicapAndTotal(outcome domain.BetOutcome, score struct{ Home, Awa
|
|||
return domain.OUTCOME_STATUS_ERROR, fmt.Errorf("failed parsing team name: %s", outcome.OddName)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Winning Margin betting is a type of bet where the bettor predicts the margin of victory in a match.
|
||||
func evaluateWinningMargin(outcome domain.BetOutcome, score struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
// Winning Margin betting is a type of bet where the bettor predicts the margin of victory in a match.
|
||||
func evaluateWinningMargin(outcome domain.BetOutcome, score struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
|
||||
marginSplit := strings.Split(outcome.OddName, "")
|
||||
if len(marginSplit) < 1 {
|
||||
|
|
@ -901,10 +901,10 @@ func evaluateWinningMargin(outcome domain.BetOutcome, score struct{ Home, Away i
|
|||
}
|
||||
|
||||
return domain.OUTCOME_STATUS_ERROR, fmt.Errorf("invalid oddheader: %s", outcome.OddHeader)
|
||||
}
|
||||
}
|
||||
|
||||
// Highest Scoring Period betting is a type of bet where the bettor predicts which period of the match will have the highest total score.
|
||||
func evaluateHighestScoringPeriod(outcome domain.BetOutcome, firstScore struct{ Home, Away int }, secondScore struct{ Home, Away int }, thirdScore struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
// Highest Scoring Period betting is a type of bet where the bettor predicts which period of the match will have the highest total score.
|
||||
func evaluateHighestScoringPeriod(outcome domain.BetOutcome, firstScore struct{ Home, Away int }, secondScore struct{ Home, Away int }, thirdScore struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
firstPeriodTotal := firstScore.Home + firstScore.Away
|
||||
secondPeriodTotal := secondScore.Home + secondScore.Away
|
||||
thirdPeriodTotal := thirdScore.Home + thirdScore.Away
|
||||
|
|
@ -930,10 +930,10 @@ func evaluateHighestScoringPeriod(outcome domain.BetOutcome, firstScore struct{
|
|||
return domain.OUTCOME_STATUS_ERROR, fmt.Errorf("invalid oddname: %s", outcome.OddName)
|
||||
}
|
||||
return domain.OUTCOME_STATUS_LOSS, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Tied After Regulation is a type of bet where the bettor predicts whether the match will end in a tie after regulation time.
|
||||
func evaluateTiedAfterRegulation(outcome domain.BetOutcome, scores []struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
// Tied After Regulation is a type of bet where the bettor predicts whether the match will end in a tie after regulation time.
|
||||
func evaluateTiedAfterRegulation(outcome domain.BetOutcome, scores []struct{ Home, Away int }) (domain.OutcomeStatus, error) {
|
||||
totalScore := struct{ Home, Away int }{0, 0}
|
||||
for _, score := range scores {
|
||||
totalScore.Home += score.Home
|
||||
|
|
@ -953,10 +953,10 @@ func evaluateTiedAfterRegulation(outcome domain.BetOutcome, scores []struct{ Hom
|
|||
}
|
||||
|
||||
return domain.OUTCOME_STATUS_ERROR, fmt.Errorf("invalid oddname: %s", outcome.OddName)
|
||||
}
|
||||
}
|
||||
|
||||
// evaluateRugbyOutcome evaluates the outcome of a Rugby bet
|
||||
func evaluateRugbyOutcome(outcome domain.BetOutcome, result *domain.RugbyResultResponse) (domain.OutcomeStatus, error) {
|
||||
// evaluateRugbyOutcome evaluates the outcome of a Rugby bet
|
||||
func evaluateRugbyOutcome(outcome domain.BetOutcome, result *domain.RugbyResultResponse) (domain.OutcomeStatus, error) {
|
||||
finalScore := parseSS(result.SS)
|
||||
|
||||
switch outcome.MarketName {
|
||||
|
|
@ -969,10 +969,10 @@ func evaluateRugbyOutcome(outcome domain.BetOutcome, result *domain.RugbyResultR
|
|||
default:
|
||||
return domain.OUTCOME_STATUS_PENDING, fmt.Errorf("unsupported rugby market: %s", outcome.MarketName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// evaluateBaseballOutcome evaluates the outcome of a Baseball bet
|
||||
func evaluateBaseballOutcome(outcome domain.BetOutcome, result *domain.BaseballResultResponse) (domain.OutcomeStatus, error) {
|
||||
// evaluateBaseballOutcome evaluates the outcome of a Baseball bet
|
||||
func evaluateBaseballOutcome(outcome domain.BetOutcome, result *domain.BaseballResultResponse) (domain.OutcomeStatus, error) {
|
||||
finalScore := parseSS(result.SS)
|
||||
|
||||
switch outcome.MarketName {
|
||||
|
|
@ -985,4 +985,4 @@ func evaluateBaseballOutcome(outcome domain.BetOutcome, result *domain.BaseballR
|
|||
default:
|
||||
return domain.OUTCOME_STATUS_PENDING, fmt.Errorf("unsupported baseball market: %s", outcome.MarketName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
49
internal/services/result/service_test.go
Normal file
49
internal/services/result/service_test.go
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
package result
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
|
||||
)
|
||||
|
||||
func TestEvaluateFootballOutcome(t *testing.T) {
|
||||
service := &Service{} // or your real logger
|
||||
|
||||
// Mock outcome
|
||||
outcome := domain.BetOutcome{
|
||||
ID: 1,
|
||||
BetID: 1,
|
||||
EventID: 1001,
|
||||
OddID: 2001,
|
||||
SportID: 1, // Assuming 1 = Football
|
||||
HomeTeamName: "Manchester",
|
||||
AwayTeamName: "Liverpool",
|
||||
MarketID: int64(domain.FOOTBALL_FULL_TIME_RESULT),
|
||||
MarketName: "Full Time Result",
|
||||
Odd: 1.75,
|
||||
OddName: "2", // Home win
|
||||
OddHeader: "1",
|
||||
OddHandicap: "",
|
||||
Status: domain.OUTCOME_STATUS_PENDING, // Initial status
|
||||
Expires: time.Now().Add(24 * time.Hour),
|
||||
}
|
||||
|
||||
// Parsed result (simulate Bet365 JSON)
|
||||
finalScore := struct{ Home, Away int }{Home: 2, Away: 1}
|
||||
firstHalfScore := struct{ Home, Away int }{Home: 1, Away: 1}
|
||||
secondHalfScore := struct{ Home, Away int }{Home: 1, Away: 0}
|
||||
corners := struct{ Home, Away int }{Home: 5, Away: 3}
|
||||
halfTimeCorners := struct{ Home, Away int }{Home: 2, Away: 2}
|
||||
events := []map[string]string{
|
||||
{"type": "goal", "team": "home", "minute": "23"},
|
||||
{"type": "goal", "team": "away", "minute": "34"},
|
||||
}
|
||||
|
||||
// Act
|
||||
status, _ := service.evaluateFootballOutcome(outcome, finalScore, firstHalfScore, secondHalfScore, corners, halfTimeCorners, events)
|
||||
|
||||
fmt.Printf("\n\nBet Outcome: %v\n\n", &status)
|
||||
|
||||
}
|
||||
|
|
@ -42,7 +42,7 @@ func (h *Handler) LaunchVeliGame(c *fiber.Ctx) error {
|
|||
// HandleVeliCallback godoc
|
||||
// @Summary Veli Games webhook handler
|
||||
// @Description Processes game round settlements from Veli
|
||||
// @Tags Virtual Games
|
||||
// @Tags Veli Games
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param payload body domain.VeliCallback true "Callback payload"
|
||||
|
|
|
|||
|
|
@ -194,11 +194,11 @@ func (a *App) initAppRoutes() {
|
|||
group.Post("/webhooks/alea-play", a.authMiddleware, h.HandleAleaCallback)
|
||||
|
||||
//Veli Virtual Game Routes
|
||||
group.Get("/veli-games/launch", a.authMiddleware, h.LaunchVeliGame)
|
||||
group.Post("/webhooks/veli-games", a.authMiddleware, h.HandleVeliCallback)
|
||||
group.Get("/veli-games/launch", h.LaunchVeliGame)
|
||||
group.Post("/webhooks/veli-games", h.HandleVeliCallback)
|
||||
|
||||
// Recommendation Routes
|
||||
group.Get("/virtual-games/recommendations/:userID", a.authMiddleware, h.GetRecommendations)
|
||||
group.Get("/virtual-games/recommendations/:userID", h.GetRecommendations)
|
||||
|
||||
// Transactions /transactions
|
||||
a.fiber.Post("/transaction", a.authMiddleware, h.CreateTransaction)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user