Skip to content

Commit

Permalink
fix(tests): Update tests with new types
Browse files Browse the repository at this point in the history
  • Loading branch information
Xoan Mallon Moure committed Dec 22, 2020
1 parent 4aaf889 commit d5bff5d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkg/notifications/notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"
)

const numberToUseForCheck = 74730
const numberToUseForCheck = "74730"

// setupEnv checks if there is an `.env' file where a series of variables
// used to perform the integration tests are defined
Expand All @@ -31,7 +31,7 @@ func TestMain(m *testing.M) {
}

func TestSendPushOverNotification(t *testing.T) {
finalPrize := 2000
finalPrize := 2000.00
number := numberToUseForCheck
origin := "test-origin"

Expand Down
14 changes: 10 additions & 4 deletions pkg/results/results_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
)

const numberToUseForCheck = 74730
const numberToUseForCheck = "74730"
const correctLotteryDrawResultsAPIURL = "http://api.elpais.com/ws/LoteriaNavidadPremiados"
const inCorrectLotteryDrawResultsAPIURLForJSONUnmarshall = "http://api.elpais.com/ws/LoteriaNavidadPremiadoss"

Expand Down Expand Up @@ -123,7 +123,10 @@ func resultEqualWithoutTimestamp(expected Result, obtained Result) bool {
}

func TestCheckNumberCorrect(t *testing.T) {
expectedResult := NewResult(numberToUseForCheck, 0, 51515151, 1, 0)
expectedResult, err := NewResult(numberToUseForCheck, 0, 51515151, 1, 0)
if err != nil {
log.Fatal(err)
}
result, err := CheckNumber(correctLotteryDrawResultsAPIURL, numberToUseForCheck, 20, "origin_test")

if err != nil {
Expand All @@ -136,8 +139,11 @@ func TestCheckNumberCorrect(t *testing.T) {
}

func TestCheckNumberIncorrect(t *testing.T) {
expectedResult := NewResult(0, 0, 0, 0, 1)
result, err := CheckNumber(correctLotteryDrawResultsAPIURL, 7455730, 20, "origin_test")
expectedResult, err := NewResult("0", 0, 0, 0, 1)
if err != nil {
log.Fatal(err)
}
result, err := CheckNumber(correctLotteryDrawResultsAPIURL, "7455730", 20, "origin_test")

if err != nil {
log.Fatal(err)
Expand Down
10 changes: 8 additions & 2 deletions pkg/results/types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package results

import "strconv"

// Number struct which information about
// each lottery number to check
type Number struct {
Expand Down Expand Up @@ -32,8 +34,12 @@ type Result struct {
}

// NewResult allows to create a Result type struct providing all the information for it
func NewResult(numero int, premio int, timestamp int, status int, error int) *Result {
return &Result{numero, premio, timestamp, status, error}
func NewResult(numero string, premio int, timestamp int, status int, error int) (*Result, error) {
numero_int, err := strconv.Atoi(numero)
if err != nil {
return nil, err
}
return &Result{numero_int, premio, timestamp, status, error}, nil
}

// LotteryDrawStatus which contain information about
Expand Down

0 comments on commit d5bff5d

Please sign in to comment.