/
presentation.go
407 lines (355 loc) · 15.8 KB
/
presentation.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
package test
import (
"bytes"
"fmt"
"github.com/goadesign/goa"
"github.com/goadesign/goa/goatest"
"github.com/gopheracademy/congo/app"
"golang.org/x/net/context"
"net/http"
"net/http/httptest"
"testing"
)
// ListPresentationOKAdmin test setup
func ListPresentationOKAdmin(t *testing.T, ctrl app.PresentationController, tenantID string, eventID string, speakerID string) *app.PresentationAdminCollection {
return ListPresentationOKAdminCtx(t, context.Background(), ctrl, tenantID, eventID, speakerID)
}
// ListPresentationOKAdminCtx test setup
func ListPresentationOKAdminCtx(t *testing.T, ctx context.Context, ctrl app.PresentationController, tenantID string, eventID string, speakerID string) *app.PresentationAdminCollection {
var logBuf bytes.Buffer
var resp interface{}
respSetter := func(r interface{}) { resp = r }
service := goatest.Service(&logBuf, respSetter)
rw := httptest.NewRecorder()
req, err := http.NewRequest("GET", fmt.Sprintf("/api/tenants/%v/events/%v/speakers/%v/presentations", tenantID, eventID, speakerID), nil)
if err != nil {
panic("invalid test " + err.Error()) // bug
}
goaCtx := goa.NewContext(goa.WithAction(ctx, "PresentationTest"), rw, req, nil)
listCtx, err := app.NewListPresentationContext(goaCtx, service)
if err != nil {
panic("invalid test data " + err.Error()) // bug
}
err = ctrl.List(listCtx)
if err != nil {
t.Fatalf("controller returned %s, logs:\n%s", err, logBuf.String())
}
a, ok := resp.(*app.PresentationAdminCollection)
if !ok {
t.Errorf("invalid response media: got %+v, expected instance of app.PresentationAdminCollection", resp)
}
if rw.Code != 200 {
t.Errorf("invalid response status code: got %+v, expected 200", rw.Code)
}
return a
}
// ListPresentationOK test setup
func ListPresentationOK(t *testing.T, ctrl app.PresentationController, tenantID string, eventID string, speakerID string) *app.PresentationCollection {
return ListPresentationOKCtx(t, context.Background(), ctrl, tenantID, eventID, speakerID)
}
// ListPresentationOKCtx test setup
func ListPresentationOKCtx(t *testing.T, ctx context.Context, ctrl app.PresentationController, tenantID string, eventID string, speakerID string) *app.PresentationCollection {
var logBuf bytes.Buffer
var resp interface{}
respSetter := func(r interface{}) { resp = r }
service := goatest.Service(&logBuf, respSetter)
rw := httptest.NewRecorder()
req, err := http.NewRequest("GET", fmt.Sprintf("/api/tenants/%v/events/%v/speakers/%v/presentations", tenantID, eventID, speakerID), nil)
if err != nil {
panic("invalid test " + err.Error()) // bug
}
goaCtx := goa.NewContext(goa.WithAction(ctx, "PresentationTest"), rw, req, nil)
listCtx, err := app.NewListPresentationContext(goaCtx, service)
if err != nil {
panic("invalid test data " + err.Error()) // bug
}
err = ctrl.List(listCtx)
if err != nil {
t.Fatalf("controller returned %s, logs:\n%s", err, logBuf.String())
}
a, ok := resp.(*app.PresentationCollection)
if !ok {
t.Errorf("invalid response media: got %+v, expected instance of app.PresentationCollection", resp)
}
if rw.Code != 200 {
t.Errorf("invalid response status code: got %+v, expected 200", rw.Code)
}
return a
}
// ListPresentationNotFound test setup
func ListPresentationNotFound(t *testing.T, ctrl app.PresentationController, tenantID string, eventID string, speakerID string) {
ListPresentationNotFoundCtx(t, context.Background(), ctrl, tenantID, eventID, speakerID)
}
// ListPresentationNotFoundCtx test setup
func ListPresentationNotFoundCtx(t *testing.T, ctx context.Context, ctrl app.PresentationController, tenantID string, eventID string, speakerID string) {
var logBuf bytes.Buffer
var resp interface{}
respSetter := func(r interface{}) { resp = r }
service := goatest.Service(&logBuf, respSetter)
rw := httptest.NewRecorder()
req, err := http.NewRequest("GET", fmt.Sprintf("/api/tenants/%v/events/%v/speakers/%v/presentations", tenantID, eventID, speakerID), nil)
if err != nil {
panic("invalid test " + err.Error()) // bug
}
goaCtx := goa.NewContext(goa.WithAction(ctx, "PresentationTest"), rw, req, nil)
listCtx, err := app.NewListPresentationContext(goaCtx, service)
if err != nil {
panic("invalid test data " + err.Error()) // bug
}
err = ctrl.List(listCtx)
if err != nil {
t.Fatalf("controller returned %s, logs:\n%s", err, logBuf.String())
}
if rw.Code != 404 {
t.Errorf("invalid response status code: got %+v, expected 404", rw.Code)
}
}
// ShowPresentationOK test setup
func ShowPresentationOK(t *testing.T, ctrl app.PresentationController, tenantID string, eventID string, speakerID string, presentationID int) *app.Presentation {
return ShowPresentationOKCtx(t, context.Background(), ctrl, tenantID, eventID, speakerID, presentationID)
}
// ShowPresentationOKCtx test setup
func ShowPresentationOKCtx(t *testing.T, ctx context.Context, ctrl app.PresentationController, tenantID string, eventID string, speakerID string, presentationID int) *app.Presentation {
var logBuf bytes.Buffer
var resp interface{}
respSetter := func(r interface{}) { resp = r }
service := goatest.Service(&logBuf, respSetter)
rw := httptest.NewRecorder()
req, err := http.NewRequest("GET", fmt.Sprintf("/api/tenants/%v/events/%v/speakers/%v/presentations/%v", tenantID, eventID, speakerID, presentationID), nil)
if err != nil {
panic("invalid test " + err.Error()) // bug
}
goaCtx := goa.NewContext(goa.WithAction(ctx, "PresentationTest"), rw, req, nil)
showCtx, err := app.NewShowPresentationContext(goaCtx, service)
if err != nil {
panic("invalid test data " + err.Error()) // bug
}
err = ctrl.Show(showCtx)
if err != nil {
t.Fatalf("controller returned %s, logs:\n%s", err, logBuf.String())
}
a, ok := resp.(*app.Presentation)
if !ok {
t.Errorf("invalid response media: got %+v, expected instance of app.Presentation", resp)
}
if rw.Code != 200 {
t.Errorf("invalid response status code: got %+v, expected 200", rw.Code)
}
return a
}
// ShowPresentationOKAdmin test setup
func ShowPresentationOKAdmin(t *testing.T, ctrl app.PresentationController, tenantID string, eventID string, speakerID string, presentationID int) *app.PresentationAdmin {
return ShowPresentationOKAdminCtx(t, context.Background(), ctrl, tenantID, eventID, speakerID, presentationID)
}
// ShowPresentationOKAdminCtx test setup
func ShowPresentationOKAdminCtx(t *testing.T, ctx context.Context, ctrl app.PresentationController, tenantID string, eventID string, speakerID string, presentationID int) *app.PresentationAdmin {
var logBuf bytes.Buffer
var resp interface{}
respSetter := func(r interface{}) { resp = r }
service := goatest.Service(&logBuf, respSetter)
rw := httptest.NewRecorder()
req, err := http.NewRequest("GET", fmt.Sprintf("/api/tenants/%v/events/%v/speakers/%v/presentations/%v", tenantID, eventID, speakerID, presentationID), nil)
if err != nil {
panic("invalid test " + err.Error()) // bug
}
goaCtx := goa.NewContext(goa.WithAction(ctx, "PresentationTest"), rw, req, nil)
showCtx, err := app.NewShowPresentationContext(goaCtx, service)
if err != nil {
panic("invalid test data " + err.Error()) // bug
}
err = ctrl.Show(showCtx)
if err != nil {
t.Fatalf("controller returned %s, logs:\n%s", err, logBuf.String())
}
a, ok := resp.(*app.PresentationAdmin)
if !ok {
t.Errorf("invalid response media: got %+v, expected instance of app.PresentationAdmin", resp)
}
if rw.Code != 200 {
t.Errorf("invalid response status code: got %+v, expected 200", rw.Code)
}
return a
}
// ShowPresentationNotFound test setup
func ShowPresentationNotFound(t *testing.T, ctrl app.PresentationController, tenantID string, eventID string, speakerID string, presentationID int) {
ShowPresentationNotFoundCtx(t, context.Background(), ctrl, tenantID, eventID, speakerID, presentationID)
}
// ShowPresentationNotFoundCtx test setup
func ShowPresentationNotFoundCtx(t *testing.T, ctx context.Context, ctrl app.PresentationController, tenantID string, eventID string, speakerID string, presentationID int) {
var logBuf bytes.Buffer
var resp interface{}
respSetter := func(r interface{}) { resp = r }
service := goatest.Service(&logBuf, respSetter)
rw := httptest.NewRecorder()
req, err := http.NewRequest("GET", fmt.Sprintf("/api/tenants/%v/events/%v/speakers/%v/presentations/%v", tenantID, eventID, speakerID, presentationID), nil)
if err != nil {
panic("invalid test " + err.Error()) // bug
}
goaCtx := goa.NewContext(goa.WithAction(ctx, "PresentationTest"), rw, req, nil)
showCtx, err := app.NewShowPresentationContext(goaCtx, service)
if err != nil {
panic("invalid test data " + err.Error()) // bug
}
err = ctrl.Show(showCtx)
if err != nil {
t.Fatalf("controller returned %s, logs:\n%s", err, logBuf.String())
}
if rw.Code != 404 {
t.Errorf("invalid response status code: got %+v, expected 404", rw.Code)
}
}
// CreatePresentationCreated test setup
func CreatePresentationCreated(t *testing.T, ctrl app.PresentationController, tenantID string, eventID string, speakerID string, payload *app.CreatePresentationPayload) {
CreatePresentationCreatedCtx(t, context.Background(), ctrl, tenantID, eventID, speakerID, payload)
}
// CreatePresentationCreatedCtx test setup
func CreatePresentationCreatedCtx(t *testing.T, ctx context.Context, ctrl app.PresentationController, tenantID string, eventID string, speakerID string, payload *app.CreatePresentationPayload) {
err := payload.Validate()
if err != nil {
panic(err)
}
var logBuf bytes.Buffer
var resp interface{}
respSetter := func(r interface{}) { resp = r }
service := goatest.Service(&logBuf, respSetter)
rw := httptest.NewRecorder()
req, err := http.NewRequest("POST", fmt.Sprintf("/api/tenants/%v/events/%v/speakers/%v/presentations", tenantID, eventID, speakerID), nil)
if err != nil {
panic("invalid test " + err.Error()) // bug
}
goaCtx := goa.NewContext(goa.WithAction(ctx, "PresentationTest"), rw, req, nil)
createCtx, err := app.NewCreatePresentationContext(goaCtx, service)
createCtx.Payload = payload
if err != nil {
panic("invalid test data " + err.Error()) // bug
}
err = ctrl.Create(createCtx)
if err != nil {
t.Fatalf("controller returned %s, logs:\n%s", err, logBuf.String())
}
if rw.Code != 201 {
t.Errorf("invalid response status code: got %+v, expected 201", rw.Code)
}
}
// UpdatePresentationNoContent test setup
func UpdatePresentationNoContent(t *testing.T, ctrl app.PresentationController, tenantID string, eventID string, speakerID string, presentationID int, payload *app.UpdatePresentationPayload) {
UpdatePresentationNoContentCtx(t, context.Background(), ctrl, tenantID, eventID, speakerID, presentationID, payload)
}
// UpdatePresentationNoContentCtx test setup
func UpdatePresentationNoContentCtx(t *testing.T, ctx context.Context, ctrl app.PresentationController, tenantID string, eventID string, speakerID string, presentationID int, payload *app.UpdatePresentationPayload) {
err := payload.Validate()
if err != nil {
panic(err)
}
var logBuf bytes.Buffer
var resp interface{}
respSetter := func(r interface{}) { resp = r }
service := goatest.Service(&logBuf, respSetter)
rw := httptest.NewRecorder()
req, err := http.NewRequest("PATCH", fmt.Sprintf("/api/tenants/%v/events/%v/speakers/%v/presentations/%v", tenantID, eventID, speakerID, presentationID), nil)
if err != nil {
panic("invalid test " + err.Error()) // bug
}
goaCtx := goa.NewContext(goa.WithAction(ctx, "PresentationTest"), rw, req, nil)
updateCtx, err := app.NewUpdatePresentationContext(goaCtx, service)
updateCtx.Payload = payload
if err != nil {
panic("invalid test data " + err.Error()) // bug
}
err = ctrl.Update(updateCtx)
if err != nil {
t.Fatalf("controller returned %s, logs:\n%s", err, logBuf.String())
}
if rw.Code != 204 {
t.Errorf("invalid response status code: got %+v, expected 204", rw.Code)
}
}
// UpdatePresentationNotFound test setup
func UpdatePresentationNotFound(t *testing.T, ctrl app.PresentationController, tenantID string, eventID string, speakerID string, presentationID int, payload *app.UpdatePresentationPayload) {
UpdatePresentationNotFoundCtx(t, context.Background(), ctrl, tenantID, eventID, speakerID, presentationID, payload)
}
// UpdatePresentationNotFoundCtx test setup
func UpdatePresentationNotFoundCtx(t *testing.T, ctx context.Context, ctrl app.PresentationController, tenantID string, eventID string, speakerID string, presentationID int, payload *app.UpdatePresentationPayload) {
err := payload.Validate()
if err != nil {
panic(err)
}
var logBuf bytes.Buffer
var resp interface{}
respSetter := func(r interface{}) { resp = r }
service := goatest.Service(&logBuf, respSetter)
rw := httptest.NewRecorder()
req, err := http.NewRequest("PATCH", fmt.Sprintf("/api/tenants/%v/events/%v/speakers/%v/presentations/%v", tenantID, eventID, speakerID, presentationID), nil)
if err != nil {
panic("invalid test " + err.Error()) // bug
}
goaCtx := goa.NewContext(goa.WithAction(ctx, "PresentationTest"), rw, req, nil)
updateCtx, err := app.NewUpdatePresentationContext(goaCtx, service)
updateCtx.Payload = payload
if err != nil {
panic("invalid test data " + err.Error()) // bug
}
err = ctrl.Update(updateCtx)
if err != nil {
t.Fatalf("controller returned %s, logs:\n%s", err, logBuf.String())
}
if rw.Code != 404 {
t.Errorf("invalid response status code: got %+v, expected 404", rw.Code)
}
}
// DeletePresentationNoContent test setup
func DeletePresentationNoContent(t *testing.T, ctrl app.PresentationController, tenantID string, eventID string, speakerID string, presentationID int) {
DeletePresentationNoContentCtx(t, context.Background(), ctrl, tenantID, eventID, speakerID, presentationID)
}
// DeletePresentationNoContentCtx test setup
func DeletePresentationNoContentCtx(t *testing.T, ctx context.Context, ctrl app.PresentationController, tenantID string, eventID string, speakerID string, presentationID int) {
var logBuf bytes.Buffer
var resp interface{}
respSetter := func(r interface{}) { resp = r }
service := goatest.Service(&logBuf, respSetter)
rw := httptest.NewRecorder()
req, err := http.NewRequest("DELETE", fmt.Sprintf("/api/tenants/%v/events/%v/speakers/%v/presentations/%v", tenantID, eventID, speakerID, presentationID), nil)
if err != nil {
panic("invalid test " + err.Error()) // bug
}
goaCtx := goa.NewContext(goa.WithAction(ctx, "PresentationTest"), rw, req, nil)
deleteCtx, err := app.NewDeletePresentationContext(goaCtx, service)
if err != nil {
panic("invalid test data " + err.Error()) // bug
}
err = ctrl.Delete(deleteCtx)
if err != nil {
t.Fatalf("controller returned %s, logs:\n%s", err, logBuf.String())
}
if rw.Code != 204 {
t.Errorf("invalid response status code: got %+v, expected 204", rw.Code)
}
}
// DeletePresentationNotFound test setup
func DeletePresentationNotFound(t *testing.T, ctrl app.PresentationController, tenantID string, eventID string, speakerID string, presentationID int) {
DeletePresentationNotFoundCtx(t, context.Background(), ctrl, tenantID, eventID, speakerID, presentationID)
}
// DeletePresentationNotFoundCtx test setup
func DeletePresentationNotFoundCtx(t *testing.T, ctx context.Context, ctrl app.PresentationController, tenantID string, eventID string, speakerID string, presentationID int) {
var logBuf bytes.Buffer
var resp interface{}
respSetter := func(r interface{}) { resp = r }
service := goatest.Service(&logBuf, respSetter)
rw := httptest.NewRecorder()
req, err := http.NewRequest("DELETE", fmt.Sprintf("/api/tenants/%v/events/%v/speakers/%v/presentations/%v", tenantID, eventID, speakerID, presentationID), nil)
if err != nil {
panic("invalid test " + err.Error()) // bug
}
goaCtx := goa.NewContext(goa.WithAction(ctx, "PresentationTest"), rw, req, nil)
deleteCtx, err := app.NewDeletePresentationContext(goaCtx, service)
if err != nil {
panic("invalid test data " + err.Error()) // bug
}
err = ctrl.Delete(deleteCtx)
if err != nil {
t.Fatalf("controller returned %s, logs:\n%s", err, logBuf.String())
}
if rw.Code != 404 {
t.Errorf("invalid response status code: got %+v, expected 404", rw.Code)
}
}