-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlistings_test.go
105 lines (85 loc) · 2.34 KB
/
listings_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package dev
import (
"os"
"strconv"
"testing"
)
func TestGetPublishedListings(t *testing.T) {
c, err := NewTestClient()
if err != nil {
t.Errorf("Failed to create TestClient: %s", err.Error())
}
listings, err := c.GetPublishedListings(
ListingQueryParams{
PerPage: 5,
Category: "collabs",
},
)
if err != nil {
t.Errorf("Error fetching articles: %s", err.Error())
}
if listings[0].TypeOf != "listing" {
t.Errorf("Expected field 'type_of' to be 'listing', got '%s'", listings[0].TypeOf)
}
if listings[0].Category != "collabs" {
t.Errorf("Expected field 'category' to be 'cfp', got '%s'", listings[0].Category)
}
}
// NOTE: this test is failing
func TestCreateListing(t *testing.T) {
t.Skip()
c, err := NewTestClient()
if err != nil {
t.Errorf("Failed to create TestClient: %s", err.Error())
}
payload := ListingBodySchema{}
payload.Listing.Title = "ACME Conference"
payload.Listing.BodyMarkdown = "Awesome conference, come join us!"
payload.Listing.Category = ListingCategoryCfp
payload.Listing.Tags = []string{"events"}
listing, err := c.CreateListing(payload, nil)
if err != nil {
t.Errorf("Error creating listing: %s", err.Error())
}
if listing.TypeOf != "listing" {
t.Errorf("Expected 'type_of' field to be 'listing', got '%s'", listing.TypeOf)
}
}
func TestGetPublishedListingsByCategory(t *testing.T) {
c, err := NewTestClient()
if err != nil {
t.Errorf("Failed to create TestClient: %s", err.Error())
}
listings, err := c.GetPublishedListingsByCategory(
"cfp",
ListingQueryParams{
PerPage: 5,
},
)
if err != nil {
t.Errorf("Error fetching articles: %s", err.Error())
}
for _, v := range listings {
if v.Category != "cfp" {
t.Errorf("Expected catrgory to be 'cfp', instead got '%s'", v.Category)
}
}
}
func TestGetListingByID(t *testing.T) {
c, err := NewTestClient()
if err != nil {
t.Errorf("Failed to create TestClient: %s", err.Error())
}
listingID := os.Getenv("TEST_LISTING_ID")
listing, err := c.GetListingByID(listingID)
if err != nil {
t.Errorf("Error fetching articles: %s", err.Error())
}
listingIDInt, err := strconv.Atoi(listingID)
if err != nil {
t.Errorf("Error converting listingID to int: %s", err.Error())
}
if listing.ID != int64(listingIDInt) {
t.Errorf("Expected result to be a listing with id: '%s', instead got '%d'", listingID, listing.ID)
}
}