-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.go
75 lines (61 loc) · 1.78 KB
/
client_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package twigots_test
import (
"context"
"io"
"os"
"path/filepath"
"testing"
"github.com/ahobsonsayers/twigots"
"github.com/joho/godotenv"
"github.com/stretchr/testify/require"
)
// TODO: Use httptest client
func TestGetLatestTicketListings(t *testing.T) {
t.Skip(t, "Does not work on CI atm. Fix this.")
projectDirectory := projectDirectory(t)
_ = godotenv.Load(filepath.Join(projectDirectory, ".env"))
twicketsAPIKey := os.Getenv("TWICKETS_API_KEY")
require.NotEmpty(t, twicketsAPIKey, "TWICKETS_API_KEY is not set")
twicketsClient := twigots.NewClient(nil)
listings, err := twicketsClient.FetchTicketListings(
context.Background(),
twigots.FetchTicketListingsInput{
APIKey: twicketsAPIKey,
Country: twigots.CountryUnitedKingdom,
Regions: []twigots.Region{
twigots.RegionLondon,
twigots.RegionNorthWest,
},
MaxNumber: 10,
},
)
require.NoError(t, err)
require.Len(t, listings, 10)
}
func projectDirectory(t *testing.T) string {
workingDirectory, err := os.Getwd()
if err != nil {
require.NoError(t, err, "failed to get path of current working directory")
}
directory := workingDirectory
for directory != "/" {
_, err := os.Stat(filepath.Join(directory, "go.mod"))
if err == nil {
break
}
directory = filepath.Dir(directory)
}
require.NotEqual(t, "failed find project directory", directory, "/")
return directory
}
func testTicketListings(t *testing.T) twigots.TicketListings {
projectDirectory := projectDirectory(t)
feedJsonFilePath := filepath.Join(projectDirectory, "testdata", "feed.json")
feedJsonFile, err := os.Open(feedJsonFilePath)
require.NoError(t, err)
feedJson, err := io.ReadAll(feedJsonFile)
require.NoError(t, err)
tickets, err := twigots.UnmarshalTwicketsFeedJson(feedJson)
require.NoError(t, err)
return tickets
}