forked from sogko/go-wordpress
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpages_revisions_test.go
More file actions
128 lines (108 loc) · 3.27 KB
/
pages_revisions_test.go
File metadata and controls
128 lines (108 loc) · 3.27 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package wordpress_test
import (
"net/http"
"testing"
"github.com/eideroliveira/wordpress"
)
func getLatestRevisionForPage(t *testing.T, page *wordpress.Page) *wordpress.Revision {
revisions, resp, _, _ := page.Revisions().List(nil)
if resp.StatusCode != http.StatusOK {
t.Errorf("Expected 200 OK, got %v", resp.Status)
}
if len(revisions) < 1 {
t.Fatalf("Should not return empty revisions")
}
// get latest revision
revisionID := revisions[0].ID
revision, resp, _, _ := page.Revisions().Get(revisionID, nil)
if resp.StatusCode != http.StatusOK {
t.Fatalf("Expected 200 OK, got %v", resp.Status)
}
return revision
}
func TestPagesRevisions_InvalidCall(t *testing.T) {
// User is not allowed to call create wordpress.Page object manually to retrieve PageMetaCollection
// A proper API call would inject the right PageMetaCollection, Client and other goodies into a page,
// allowing user to call page.Revisions()
invalidPage := wordpress.Page{}
invalidRevisions := invalidPage.Revisions()
if invalidRevisions != nil {
t.Errorf("Expected revisions to be nil, %v", invalidRevisions)
}
}
func TestPagesRevisionsList(t *testing.T) {
wp := initTestClient()
page := getAnyOnePage(t, wp)
revisions, resp, body, err := page.Revisions().List(nil)
if err != nil {
t.Errorf("Should not return error: %v", err.Error())
}
if body == nil {
t.Errorf("Should not return nil body")
}
if resp.StatusCode != http.StatusOK {
t.Errorf("Expected 200 OK, got %v", resp.Status)
}
if revisions == nil {
t.Errorf("Should not return nil revisions")
}
}
func TestPagesRevisionsList_Lazy(t *testing.T) {
wp := initTestClient()
page := getAnyOnePage(t, wp)
pageID := page.ID
// Use Pages().Entity(pageID) to retrieve revisions in one API call
lazyRevisions, resp, body, err := wp.Pages().Entity(pageID).Revisions().List(nil)
if err != nil {
t.Errorf("Should not return error: %v", err.Error())
}
if body == nil {
t.Errorf("Should not return nil body")
}
if resp.StatusCode != http.StatusOK {
t.Errorf("Expected 200 OK, got %v", resp.Status)
}
if lazyRevisions == nil {
t.Errorf("Should not return nil revisions")
}
}
func TestPagesRevisionsGet(t *testing.T) {
wp := initTestClient()
page := getAnyOnePage(t, wp)
r := getLatestRevisionForPage(t, page)
revisionID := r.ID
revision, resp, body, err := page.Revisions().Get(revisionID, nil)
if err != nil {
t.Errorf("Should not return error: %v", err.Error())
}
if body == nil {
t.Errorf("Should not return nil body")
}
if resp.StatusCode != http.StatusOK {
t.Errorf("Expected 200 OK, got %v", resp.Status)
}
if revision == nil {
t.Errorf("Should not return nil revisions")
}
}
func TestPagesRevisionsGet_Lazy(t *testing.T) {
wp := initTestClient()
page := getAnyOnePage(t, wp)
r := getLatestRevisionForPage(t, page)
pageID := page.ID
revisionID := r.ID
// Use Pages().Entity(pageID) to retrieve revisions in one API call
lazyRevision, resp, body, err := wp.Pages().Entity(pageID).Revisions().Get(revisionID, nil)
if err != nil {
t.Errorf("Should not return error: %v", err.Error())
}
if body == nil {
t.Errorf("Should not return nil body")
}
if resp.StatusCode != http.StatusOK {
t.Errorf("Expected 200 OK, got %v", resp.Status)
}
if lazyRevision == nil {
t.Errorf("Should not return nil revisions")
}
}