-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpost_test.go
93 lines (86 loc) · 1.98 KB
/
post_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
package writeas
import (
"fmt"
"testing"
)
func TestPostRoundTrip(t *testing.T) {
var id, token string
dwac := NewClient()
t.Run("Create post", func(t *testing.T) {
p, err := dwac.CreatePost(&PostParams{
Title: "Title!",
Content: "This is a post.",
Font: "sans",
})
if err != nil {
t.Errorf("Post create failed: %v", err)
return
}
t.Logf("Post created: %+v", p)
id, token = p.ID, p.Token
})
t.Run("Get post", func(t *testing.T) {
res, err := dwac.GetPost(id)
if err != nil {
t.Errorf("Unexpected fetch results: %+v, err: %v\n", res, err)
} else {
t.Logf("Post: %+v", res)
if res.Content != "This is a post." {
t.Errorf("Unexpected fetch results: %+v\n", res)
}
}
})
t.Run("Update post", func(t *testing.T) {
p, err := dwac.UpdatePost(id, token, &PostParams{
Content: "Now it's been updated!",
})
if err != nil {
t.Errorf("Post update failed: %v", err)
return
}
t.Logf("Post updated: %+v", p)
})
t.Run("Delete post", func(t *testing.T) {
err := dwac.DeletePost(id, token)
if err != nil {
t.Errorf("Post delete failed: %v", err)
return
}
t.Logf("Post deleted!")
})
}
func TestPinUnPin(t *testing.T) {
dwac := NewDevClient()
_, err := dwac.LogIn("demo", "demo")
if err != nil {
t.Fatalf("Unable to log in: %v", err)
}
defer dwac.LogOut()
t.Run("Pin post", func(t *testing.T) {
err := dwac.PinPost("tester", &PinnedPostParams{ID: "olx6uk7064heqltf"})
if err != nil {
t.Fatalf("Pin failed: %v", err)
}
})
t.Run("Unpin post", func(t *testing.T) {
err := dwac.UnpinPost("tester", &PinnedPostParams{ID: "olx6uk7064heqltf"})
if err != nil {
t.Fatalf("Unpin failed: %v", err)
}
})
}
func ExampleClient_CreatePost() {
dwac := NewDevClient()
// Publish a post
p, err := dwac.CreatePost(&PostParams{
Title: "Title!",
Content: "This is a post.",
Font: "sans",
})
if err != nil {
fmt.Printf("Unable to create: %v", err)
return
}
fmt.Printf("%s", p.Content)
// Output: This is a post.
}