-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidea_test.go
195 lines (157 loc) · 3.55 KB
/
idea_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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package roadmap_test
import (
"fmt"
"testing"
roadmap "github.com/roadmap-space/roadmap-go"
)
func createIdea(roadmapID, title string) (*roadmap.Idea, error) {
idea := roadmap.Idea{}
idea.RoadmapID = roadmapID
idea.Title = title
return c.Ideas.Create(idea)
}
func Test_IdeaCreate(t *testing.T) {
i, err := createIdea(testRoadmapID, "unit test idea")
if err != nil {
t.Fatal(err)
} else if i == nil {
t.Errorf("create idea returned a nil pointer")
}
deleteItem(i.ID, i.Token)
}
func Test_IdeaList(t *testing.T) {
t.Parallel()
i, err := createIdea(testRoadmapID, "unit test list")
if err != nil {
t.Fatal(err)
}
defer deleteItem(i.ID, i.Token)
list, err := c.Ideas.List(testRoadmapID, nil)
if err != nil {
t.Fatal(err)
}
found := false
for _, idea := range list {
if idea.ID == i.ID {
found = true
break
}
}
if !found {
t.Errorf("List is not returning our newly created idea")
}
}
func Test_IdeaListArchived(t *testing.T) {
t.Parallel()
i, err := createIdea(testRoadmapID, "unit test list archived")
if err != nil {
t.Fatal(err)
}
defer deleteItem(i.ID, i.Token)
if ok, err := c.Ideas.Delete(i.ID, i.Token); err != nil {
t.Fatal(err)
} else if !ok {
t.Errorf("the delete idea return false")
}
list, err := c.Ideas.List(testRoadmapID, &roadmap.IdeaListParams{IsArchived: true})
if err != nil {
t.Fatal(err)
}
found := false
for _, idea := range list {
if idea.ID == i.ID {
found = true
break
}
}
if !found {
t.Errorf("Unable to find the archived idea in archived list")
}
}
func Test_IdeaGet(t *testing.T) {
t.Parallel()
i, err := createIdea(testRoadmapID, "unit test get idea")
if err != nil {
t.Fatal(err)
}
defer deleteItem(i.ID, i.Token)
idea, err := c.Ideas.Get(i.ID, i.Token)
if err != nil {
t.Fatal(err)
} else if idea == nil {
t.Errorf("unable to get the idea")
}
}
func Test_IdeaToWidget(t *testing.T) {
t.Parallel()
i, err := createIdea(testRoadmapID, "unit test to widget")
if err != nil {
t.Fatal(err)
}
defer deleteItem(i.ID, i.Token)
if ok, err := c.Ideas.ToWidget(i.ID, testRoadmapID, i.Token); err != nil {
t.Fatal(err)
} else if !ok {
t.Error("unable to set the idea to be on widget")
}
//TODO: this kind of gave some issue during live stream
// not obvious that this field was needed to be true
i.Published = true
if _, err := c.Ideas.Update(*i); err != nil {
t.Fatal(err)
}
widget, err := c.Roadmaps.GetWidgetIdeas(testRoadmapID)
if err != nil {
t.Fatal(err)
}
found := false
for _, w := range widget {
fmt.Println(w.ID, i.ID)
if w.ID == i.ID {
found = true
break
}
}
if !found {
t.Error("new idea not found on widget")
}
}
func Test_IdeaUpdate(t *testing.T) {
t.Parallel()
i, err := createIdea(testRoadmapID, "test unit update")
if err != nil {
t.Fatal(err)
}
defer deleteItem(i.ID, i.Token)
i.Description = "## this is markdown"
if u, err := c.Ideas.Update(*i); err != nil {
t.Fatal(err)
} else if u == nil {
t.Errorf("unable to update the idea")
}
}
func Test_IdeaConvert(t *testing.T) {
t.Parallel()
idea, err := createIdea(testRoadmapID, "new idea to convert")
if err != nil {
t.Fatal(err)
}
if _, err := c.Ideas.Convert(testRoadmapID, idea.ID, idea.Token); err != nil {
t.Fatal(err)
}
p := &roadmap.StoryListParams{RoadmapID: testRoadmapID}
check, err := c.Stories.List(p)
if err != nil {
t.Fatal(err)
}
found := false
for _, s := range check {
if s.ID == idea.ID {
found = true
break
}
}
if found == false {
t.Error("the idea converted to story were not found in the roadmap stories")
}
}