This repository has been archived by the owner on Jun 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
emvi_test.go
88 lines (69 loc) · 1.98 KB
/
emvi_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
package emvi
import (
"testing"
)
const (
// this is our API test organization
testClientId = "HEuxz77eec6xat5xD0Xj"
testClientSecret = "MNYy5v9TI7sUUUm6Abi2ortxT28bB26gxIMbfBd8hcTXYfKO7AThrcdr2YBBjAa1"
testClientOrga = "api-test"
)
var (
testConfig = &Config{"https://auth.emvi-integration.com", "https://api.emvi-integration.com"}
)
func TestNewClientRefreshToken(t *testing.T) {
client := getTestClient()
if err := client.refreshToken(); err != nil {
t.Fatalf("Token must be refreshed, but was: %v", err)
}
if client.TokenType != "Bearer" ||
client.AccessToken == "" ||
client.ExpiresIn == 0 {
t.Fatalf("Client data not as expected: %v", client)
}
}
func TestClient_FindArticles(t *testing.T) {
client := getTestClient()
articles, count, err := client.FindArticles("test", nil)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if len(articles) != 2 || count != 2 {
t.Fatalf("Result not as expected: %v %v", len(articles), count)
}
}
func TestClient_GetOrganization(t *testing.T) {
client := getTestClient()
result, err := client.GetOrganization()
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if result.Id == "" ||
result.Name == "" ||
result.NameNormalized == "" {
t.Fatalf("Result not as expected: %v", result)
}
}
func TestClient_GetArticle(t *testing.T) {
client := getTestClient()
article, content, authors, err := client.GetArticle("beJarvjaQM", "JxGdjWaOz9", 0)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if article.Id != "beJarvjaQM" || content == nil || len(authors) != 1 {
t.Fatalf("Result not as expected: %v %v %v", article, content, authors)
}
}
func TestClient_GetLanguages(t *testing.T) {
client := getTestClient()
result, err := client.GetLanguages()
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if len(result) != 2 {
t.Fatalf("Result not as expected: %v", result)
}
}
func getTestClient() *Client {
return NewClient(testClientId, testClientSecret, testClientOrga, testConfig)
}