|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "net/http" |
| 6 | + "os" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/calvinmclean/babyapi" |
| 10 | + babytest "github.com/calvinmclean/babyapi/test" |
| 11 | + "github.com/stretchr/testify/require" |
| 12 | +) |
| 13 | + |
| 14 | +func TestAPI(t *testing.T) { |
| 15 | + defer os.RemoveAll("storage.json") |
| 16 | + |
| 17 | + api := createAPI() |
| 18 | + |
| 19 | + babytest.RunTableTest(t, api.Events, []babytest.TestCase[*babyapi.AnyResource]{ |
| 20 | + { |
| 21 | + Name: "ErrorCreatingEventWithoutPassword", |
| 22 | + Test: babytest.RequestTest[*babyapi.AnyResource]{ |
| 23 | + Method: http.MethodPost, |
| 24 | + Body: `{"Name": "Party"}`, |
| 25 | + }, |
| 26 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 27 | + Status: http.StatusBadRequest, |
| 28 | + Body: `{"status":"Invalid request.","error":"missing required 'password' field"}`, |
| 29 | + Error: "error posting resource: unexpected response with text: Invalid request.", |
| 30 | + }, |
| 31 | + }, |
| 32 | + { |
| 33 | + Name: "CreateEvent", |
| 34 | + Test: babytest.RequestTest[*babyapi.AnyResource]{ |
| 35 | + Method: http.MethodPost, |
| 36 | + Body: `{"Name": "Party", "Password": "secret"}`, |
| 37 | + }, |
| 38 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 39 | + Status: http.StatusCreated, |
| 40 | + BodyRegexp: `{"id":"[0-9a-v]{20}","Name":"Party","Contact":"","Date":"","Location":"","Details":""}`, |
| 41 | + }, |
| 42 | + }, |
| 43 | + { |
| 44 | + Name: "GetEventForbidden", |
| 45 | + Test: babytest.RequestFuncTest[*babyapi.AnyResource](func(getResponse babytest.PreviousResponseGetter, address string) *http.Request { |
| 46 | + id := getResponse("CreateEvent").Data.GetID() |
| 47 | + address = fmt.Sprintf("%s/events/%s", address, id) |
| 48 | + |
| 49 | + r, err := http.NewRequest(http.MethodGet, address, http.NoBody) |
| 50 | + require.NoError(t, err) |
| 51 | + return r |
| 52 | + }), |
| 53 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 54 | + Status: http.StatusForbidden, |
| 55 | + Body: `{"status":"Forbidden"}`, |
| 56 | + }, |
| 57 | + }, |
| 58 | + { |
| 59 | + Name: "GetEvent", |
| 60 | + Test: babytest.RequestTest[*babyapi.AnyResource]{ |
| 61 | + Method: http.MethodGet, |
| 62 | + RawQuery: "password=secret", |
| 63 | + IDFunc: func(getResponse babytest.PreviousResponseGetter) string { |
| 64 | + return getResponse("CreateEvent").Data.GetID() |
| 65 | + }, |
| 66 | + }, |
| 67 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 68 | + Status: http.StatusOK, |
| 69 | + BodyRegexp: `{"id":"[0-9a-v]{20}","Name":"Party","Contact":"","Date":"","Location":"","Details":""}`, |
| 70 | + }, |
| 71 | + }, |
| 72 | + { |
| 73 | + Name: "GetAllEventsForbidden", |
| 74 | + Test: babytest.RequestTest[*babyapi.AnyResource]{ |
| 75 | + Method: babytest.MethodGetAll, |
| 76 | + RawQuery: "password=secret", |
| 77 | + IDFunc: func(getResponse babytest.PreviousResponseGetter) string { |
| 78 | + return getResponse("CreateEvent").Data.GetID() |
| 79 | + }, |
| 80 | + }, |
| 81 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 82 | + Status: http.StatusForbidden, |
| 83 | + Body: `{"status":"Forbidden"}`, |
| 84 | + Error: "error getting all resources: unexpected response with text: Forbidden", |
| 85 | + }, |
| 86 | + }, |
| 87 | + { |
| 88 | + Name: "GetAllEventsForbiddenUsingRequestFuncTest", |
| 89 | + Test: babytest.RequestFuncTest[*babyapi.AnyResource](func(getResponse babytest.PreviousResponseGetter, address string) *http.Request { |
| 90 | + r, err := http.NewRequest(http.MethodGet, address+"/events", http.NoBody) |
| 91 | + require.NoError(t, err) |
| 92 | + return r |
| 93 | + }), |
| 94 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 95 | + Status: http.StatusForbidden, |
| 96 | + Body: `{"status":"Forbidden"}`, |
| 97 | + }, |
| 98 | + }, |
| 99 | + { |
| 100 | + Name: "GetEventWithInvalidInvite", |
| 101 | + Test: babytest.RequestTest[*babyapi.AnyResource]{ |
| 102 | + Method: http.MethodGet, |
| 103 | + RawQuery: "invite=DoesNotExist", |
| 104 | + IDFunc: func(getResponse babytest.PreviousResponseGetter) string { |
| 105 | + return getResponse("CreateEvent").Data.GetID() |
| 106 | + }, |
| 107 | + }, |
| 108 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 109 | + Status: http.StatusForbidden, |
| 110 | + Body: `{"status":"Forbidden"}`, |
| 111 | + Error: "error getting resource: unexpected response with text: Forbidden", |
| 112 | + }, |
| 113 | + }, |
| 114 | + { |
| 115 | + Name: "PUTNotAllowed", |
| 116 | + Test: babytest.RequestTest[*babyapi.AnyResource]{ |
| 117 | + Method: http.MethodPut, |
| 118 | + RawQuery: "password=secret", |
| 119 | + IDFunc: func(getResponse babytest.PreviousResponseGetter) string { |
| 120 | + return getResponse("CreateEvent").Data.GetID() |
| 121 | + }, |
| 122 | + BodyFunc: func(getResponse babytest.PreviousResponseGetter) string { |
| 123 | + return fmt.Sprintf(`{"id": "%s", "name": "New Name"}`, getResponse("CreateEvent").Data.GetID()) |
| 124 | + }, |
| 125 | + }, |
| 126 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 127 | + Status: http.StatusBadRequest, |
| 128 | + Body: `{"status":"Invalid request.","error":"PUT not allowed"}`, |
| 129 | + Error: "error putting resource: unexpected response with text: Invalid request.", |
| 130 | + }, |
| 131 | + }, |
| 132 | + { |
| 133 | + Name: "CannotCreateInviteWithoutEventPassword", |
| 134 | + Test: babytest.RequestTest[*babyapi.AnyResource]{ |
| 135 | + Method: http.MethodPost, |
| 136 | + ParentIDsFunc: func(getResponse babytest.PreviousResponseGetter) []string { |
| 137 | + return []string{getResponse("CreateEvent").Data.GetID()} |
| 138 | + }, |
| 139 | + Body: `{"Name": "Name"}`, |
| 140 | + }, |
| 141 | + ClientName: "Invite", |
| 142 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 143 | + Status: http.StatusForbidden, |
| 144 | + Body: `{"status":"Forbidden"}`, |
| 145 | + Error: "error posting resource: unexpected response with text: Forbidden", |
| 146 | + }, |
| 147 | + }, |
| 148 | + { |
| 149 | + Name: "CreateInvite", |
| 150 | + Test: babytest.RequestTest[*babyapi.AnyResource]{ |
| 151 | + Method: http.MethodPost, |
| 152 | + RawQuery: "password=secret", |
| 153 | + ParentIDsFunc: func(getResponse babytest.PreviousResponseGetter) []string { |
| 154 | + return []string{getResponse("CreateEvent").Data.GetID()} |
| 155 | + }, |
| 156 | + Body: `{"Name": "Firstname Lastname"}`, |
| 157 | + }, |
| 158 | + ClientName: "Invite", |
| 159 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 160 | + Status: http.StatusCreated, |
| 161 | + BodyRegexp: `{"id":"[0-9a-v]{20}","Name":"Firstname Lastname","Contact":"","EventID":"[0-9a-v]{20}","RSVP":null}`, |
| 162 | + }, |
| 163 | + }, |
| 164 | + { |
| 165 | + Name: "GetInvite", |
| 166 | + Test: babytest.RequestTest[*babyapi.AnyResource]{ |
| 167 | + Method: http.MethodGet, |
| 168 | + ParentIDsFunc: func(getResponse babytest.PreviousResponseGetter) []string { |
| 169 | + return []string{getResponse("CreateEvent").Data.GetID()} |
| 170 | + }, |
| 171 | + IDFunc: func(getResponse babytest.PreviousResponseGetter) string { |
| 172 | + return getResponse("CreateInvite").Data.GetID() |
| 173 | + }, |
| 174 | + }, |
| 175 | + ClientName: "Invite", |
| 176 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 177 | + Status: http.StatusOK, |
| 178 | + BodyRegexp: `{"id":"[0-9a-v]{20}","Name":"Firstname Lastname","Contact":"","EventID":"[0-9a-v]{20}","RSVP":null}`, |
| 179 | + }, |
| 180 | + }, |
| 181 | + { |
| 182 | + Name: "ListInvites", |
| 183 | + Test: babytest.RequestTest[*babyapi.AnyResource]{ |
| 184 | + Method: babytest.MethodGetAll, |
| 185 | + RawQuery: "password=secret", |
| 186 | + ParentIDsFunc: func(getResponse babytest.PreviousResponseGetter) []string { |
| 187 | + return []string{getResponse("CreateEvent").Data.GetID()} |
| 188 | + }, |
| 189 | + IDFunc: func(getResponse babytest.PreviousResponseGetter) string { |
| 190 | + return getResponse("CreateInvite").Data.GetID() |
| 191 | + }, |
| 192 | + }, |
| 193 | + ClientName: "Invite", |
| 194 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 195 | + Status: http.StatusOK, |
| 196 | + BodyRegexp: `{"items":\[{"id":"[0-9a-v]{20}","Name":"Firstname Lastname","Contact":"","EventID":"[0-9a-v]{20}","RSVP":null}]`, |
| 197 | + }, |
| 198 | + }, |
| 199 | + { |
| 200 | + Name: "ListInviteUsingRequestFuncTest", |
| 201 | + Test: babytest.RequestFuncTest[*babyapi.AnyResource](func(getResponse babytest.PreviousResponseGetter, address string) *http.Request { |
| 202 | + id := getResponse("CreateEvent").Data.GetID() |
| 203 | + address = fmt.Sprintf("%s/events/%s/invites", address, id) |
| 204 | + |
| 205 | + r, err := http.NewRequest(babytest.MethodGetAll, address, http.NoBody) |
| 206 | + require.NoError(t, err) |
| 207 | + |
| 208 | + q := r.URL.Query() |
| 209 | + q.Add("password", "secret") |
| 210 | + r.URL.RawQuery = q.Encode() |
| 211 | + |
| 212 | + return r |
| 213 | + }), |
| 214 | + ClientName: "Invite", |
| 215 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 216 | + Status: http.StatusOK, |
| 217 | + BodyRegexp: `{"items":\[{"id":"[0-9a-v]{20}","Name":"Firstname Lastname","Contact":"","EventID":"[0-9a-v]{20}","RSVP":null}]`, |
| 218 | + }, |
| 219 | + }, |
| 220 | + { |
| 221 | + Name: "GetEventWithInviteIDAsPassword", |
| 222 | + Test: babytest.RequestTest[*babyapi.AnyResource]{ |
| 223 | + Method: http.MethodGet, |
| 224 | + RawQueryFunc: func(getResponse babytest.PreviousResponseGetter) string { |
| 225 | + return "invite=" + getResponse("CreateInvite").Data.GetID() |
| 226 | + }, |
| 227 | + ParentIDsFunc: func(getResponse babytest.PreviousResponseGetter) []string { |
| 228 | + return []string{getResponse("CreateEvent").Data.GetID()} |
| 229 | + }, |
| 230 | + IDFunc: func(getResponse babytest.PreviousResponseGetter) string { |
| 231 | + return getResponse("CreateInvite").Data.GetID() |
| 232 | + }, |
| 233 | + }, |
| 234 | + ClientName: "Invite", |
| 235 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 236 | + Status: http.StatusOK, |
| 237 | + BodyRegexp: `{"id":"[0-9a-v]{20}","Name":"Firstname Lastname","Contact":"","EventID":"[0-9a-v]{20}","RSVP":null}`, |
| 238 | + }, |
| 239 | + }, |
| 240 | + { |
| 241 | + Name: "DeleteInvite", |
| 242 | + Test: babytest.RequestTest[*babyapi.AnyResource]{ |
| 243 | + Method: http.MethodDelete, |
| 244 | + ParentIDsFunc: func(getResponse babytest.PreviousResponseGetter) []string { |
| 245 | + return []string{getResponse("CreateEvent").Data.GetID()} |
| 246 | + }, |
| 247 | + IDFunc: func(getResponse babytest.PreviousResponseGetter) string { |
| 248 | + return getResponse("CreateInvite").Data.GetID() |
| 249 | + }, |
| 250 | + }, |
| 251 | + ClientName: "Invite", |
| 252 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 253 | + Status: http.StatusOK, |
| 254 | + NoBody: true, |
| 255 | + }, |
| 256 | + }, |
| 257 | + { |
| 258 | + Name: "PatchErrorNotConfigured", |
| 259 | + Test: babytest.RequestTest[*babyapi.AnyResource]{ |
| 260 | + Method: http.MethodPatch, |
| 261 | + RawQuery: "password=secret", |
| 262 | + IDFunc: func(getResponse babytest.PreviousResponseGetter) string { |
| 263 | + return getResponse("CreateEvent").Data.GetID() |
| 264 | + }, |
| 265 | + Body: `{"Name": "NEW"}`, |
| 266 | + }, |
| 267 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 268 | + Status: http.StatusMethodNotAllowed, |
| 269 | + Error: "error patching resource: unexpected response with text: Method not allowed.", |
| 270 | + Body: `{"status":"Method not allowed."}`, |
| 271 | + }, |
| 272 | + }, |
| 273 | + }) |
| 274 | +} |
| 275 | + |
| 276 | +func TestIndividualTest(t *testing.T) { |
| 277 | + defer os.RemoveAll("storage.json") |
| 278 | + |
| 279 | + api := createAPI() |
| 280 | + |
| 281 | + client, stop := babytest.NewTestClient[*Event](t, api.Events) |
| 282 | + defer stop() |
| 283 | + |
| 284 | + babytest.TestCase[*Event]{ |
| 285 | + Name: "CreateEvent", |
| 286 | + Test: babytest.RequestTest[*Event]{ |
| 287 | + Method: http.MethodPost, |
| 288 | + Body: `{"Name": "Party", "Password": "secret"}`, |
| 289 | + }, |
| 290 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 291 | + Status: http.StatusCreated, |
| 292 | + BodyRegexp: `{"id":"[0-9a-v]{20}","Name":"Party","Contact":"","Date":"","Location":"","Details":""}`, |
| 293 | + }, |
| 294 | + Assert: func(r *babytest.Response[*Event]) { |
| 295 | + require.Equal(t, "Party", r.Data.Name) |
| 296 | + }, |
| 297 | + }.Run(t, client) |
| 298 | + |
| 299 | + resp := babytest.TestCase[*Event]{ |
| 300 | + Name: "CreateEvent", |
| 301 | + Test: babytest.RequestTest[*Event]{ |
| 302 | + Method: http.MethodPost, |
| 303 | + Body: `{"Name": "Party", "Password": "secret"}`, |
| 304 | + }, |
| 305 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 306 | + Status: http.StatusCreated, |
| 307 | + BodyRegexp: `{"id":"[0-9a-v]{20}","Name":"Party","Contact":"","Date":"","Location":"","Details":""}`, |
| 308 | + }, |
| 309 | + Assert: func(r *babytest.Response[*Event]) { |
| 310 | + require.Equal(t, "Party", r.Data.Name) |
| 311 | + }, |
| 312 | + }.RunWithResponse(t, client) |
| 313 | + require.NotNil(t, resp) |
| 314 | +} |
| 315 | + |
| 316 | +func TestCLI(t *testing.T) { |
| 317 | + defer os.RemoveAll("storage.json") |
| 318 | + |
| 319 | + api := createAPI() |
| 320 | + |
| 321 | + babytest.RunTableTest(t, api.Events, []babytest.TestCase[*babyapi.AnyResource]{ |
| 322 | + { |
| 323 | + Name: "ErrorCreatingEventWithoutPassword", |
| 324 | + Test: babytest.CommandLineTest[*babyapi.AnyResource]{ |
| 325 | + Command: api.Events.Command, |
| 326 | + Args: []string{"event", "post", "-d", `{"Name": "Party"}`}, |
| 327 | + }, |
| 328 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 329 | + Status: http.StatusBadRequest, |
| 330 | + Body: `{"status":"Invalid request.","error":"missing required 'password' field"}`, |
| 331 | + Error: "error running client from CLI: error running Post: error posting resource: unexpected response with text: Invalid request.", |
| 332 | + }, |
| 333 | + }, |
| 334 | + { |
| 335 | + Name: "CreateEvent", |
| 336 | + Test: babytest.CommandLineTest[*babyapi.AnyResource]{ |
| 337 | + Command: api.Events.Command, |
| 338 | + Args: []string{"event", "post", "-d", `{"Name": "Party", "Password": "secret"}`}, |
| 339 | + }, |
| 340 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 341 | + Status: http.StatusCreated, |
| 342 | + BodyRegexp: `{"id":"[0-9a-v]{20}","Name":"Party","Contact":"","Date":"","Location":"","Details":""}`, |
| 343 | + CLIOutRegexp: `{\s+"Contact": "",\s+"Date": "",\s+"Details": "",\s+"Location": "",\s+"Name": "Party",\s+"id": "[0-9a-v]{20}"\s+}\s*`, |
| 344 | + }, |
| 345 | + }, |
| 346 | + { |
| 347 | + Name: "GetEventForbidden", |
| 348 | + Test: babytest.CommandLineTest[*babyapi.AnyResource]{ |
| 349 | + Command: api.Events.Command, |
| 350 | + ArgsFunc: func(getResponse babytest.PreviousResponseGetter) []string { |
| 351 | + return []string{"event", "get", getResponse("CreateEvent").Data.GetID()} |
| 352 | + }, |
| 353 | + }, |
| 354 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 355 | + Status: http.StatusForbidden, |
| 356 | + Body: `{"status":"Forbidden"}`, |
| 357 | + Error: "error running client from CLI: error running Get: error getting resource: unexpected response with text: Forbidden", |
| 358 | + }, |
| 359 | + }, |
| 360 | + { |
| 361 | + Name: "GetEvent", |
| 362 | + Test: babytest.CommandLineTest[*babyapi.AnyResource]{ |
| 363 | + Command: api.Events.Command, |
| 364 | + ArgsFunc: func(getResponse babytest.PreviousResponseGetter) []string { |
| 365 | + return []string{"event", "get", getResponse("CreateEvent").Data.GetID(), "-q", "password=secret"} |
| 366 | + }, |
| 367 | + }, |
| 368 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 369 | + Status: http.StatusOK, |
| 370 | + BodyRegexp: `{"id":"[0-9a-v]{20}","Name":"Party","Contact":"","Date":"","Location":"","Details":""}`, |
| 371 | + }, |
| 372 | + }, |
| 373 | + { |
| 374 | + Name: "GetEventWithInvalidInvite", |
| 375 | + Test: babytest.CommandLineTest[*babyapi.AnyResource]{ |
| 376 | + Command: api.Events.Command, |
| 377 | + ArgsFunc: func(getResponse babytest.PreviousResponseGetter) []string { |
| 378 | + return []string{"event", "get", getResponse("CreateEvent").Data.GetID(), "-q", "invite=DoesNotExist"} |
| 379 | + }, |
| 380 | + }, |
| 381 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 382 | + Status: http.StatusForbidden, |
| 383 | + Body: `{"status":"Forbidden"}`, |
| 384 | + Error: "error running client from CLI: error running Get: error getting resource: unexpected response with text: Forbidden", |
| 385 | + }, |
| 386 | + }, |
| 387 | + { |
| 388 | + Name: "PUTNotAllowed", |
| 389 | + Test: babytest.CommandLineTest[*babyapi.AnyResource]{ |
| 390 | + Command: api.Events.Command, |
| 391 | + ArgsFunc: func(getResponse babytest.PreviousResponseGetter) []string { |
| 392 | + return []string{ |
| 393 | + "event", "put", |
| 394 | + getResponse("CreateEvent").Data.GetID(), |
| 395 | + "-d", fmt.Sprintf(`{"id": "%s", "name": "New Name"}`, getResponse("CreateEvent").Data.GetID()), |
| 396 | + "-q", "password=secret", |
| 397 | + } |
| 398 | + }, |
| 399 | + }, |
| 400 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 401 | + Status: http.StatusBadRequest, |
| 402 | + Body: `{"status":"Invalid request.","error":"PUT not allowed"}`, |
| 403 | + Error: "error running client from CLI: error running Put: error putting resource: unexpected response with text: Invalid request.", |
| 404 | + }, |
| 405 | + }, |
| 406 | + { |
| 407 | + Name: "CannotCreateInviteWithoutEventPassword", |
| 408 | + Test: babytest.CommandLineTest[*babyapi.AnyResource]{ |
| 409 | + Command: api.Events.Command, |
| 410 | + ArgsFunc: func(getResponse babytest.PreviousResponseGetter) []string { |
| 411 | + eventID := getResponse("CreateEvent").Data.GetID() |
| 412 | + return []string{"invite", "post", "--event-id", eventID, "-d", `{"Name": "Name"}`} |
| 413 | + }, |
| 414 | + }, |
| 415 | + ClientName: "Invite", |
| 416 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 417 | + Status: http.StatusForbidden, |
| 418 | + Body: `{"status":"Forbidden"}`, |
| 419 | + Error: "error running client from CLI: error running Post: error posting resource: unexpected response with text: Forbidden", |
| 420 | + }, |
| 421 | + }, |
| 422 | + { |
| 423 | + Name: "CreateInvite", |
| 424 | + Test: babytest.CommandLineTest[*babyapi.AnyResource]{ |
| 425 | + Command: api.Events.Command, |
| 426 | + ArgsFunc: func(getResponse babytest.PreviousResponseGetter) []string { |
| 427 | + eventID := getResponse("CreateEvent").Data.GetID() |
| 428 | + return []string{"invite", "post", "--event-id", eventID, "-d", `{"Name": "Firstname Lastname"}`, "-q", "password=secret"} |
| 429 | + }, |
| 430 | + }, |
| 431 | + ClientName: "Invite", |
| 432 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 433 | + Status: http.StatusCreated, |
| 434 | + BodyRegexp: `{"id":"[0-9a-v]{20}","Name":"Firstname Lastname","Contact":"","EventID":"[0-9a-v]{20}","RSVP":null}`, |
| 435 | + }, |
| 436 | + }, |
| 437 | + { |
| 438 | + Name: "GetInvite", |
| 439 | + Test: babytest.CommandLineTest[*babyapi.AnyResource]{ |
| 440 | + Command: api.Events.Command, |
| 441 | + ArgsFunc: func(getResponse babytest.PreviousResponseGetter) []string { |
| 442 | + eventID := getResponse("CreateEvent").Data.GetID() |
| 443 | + return []string{ |
| 444 | + "invite", "get", |
| 445 | + getResponse("CreateInvite").Data.GetID(), "--event-id", eventID, |
| 446 | + "-q", "password=secret", |
| 447 | + } |
| 448 | + }, |
| 449 | + }, |
| 450 | + ClientName: "Invite", |
| 451 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 452 | + Status: http.StatusOK, |
| 453 | + BodyRegexp: `{"id":"[0-9a-v]{20}","Name":"Firstname Lastname","Contact":"","EventID":"[0-9a-v]{20}","RSVP":null}`, |
| 454 | + }, |
| 455 | + }, |
| 456 | + { |
| 457 | + Name: "ListInvites", |
| 458 | + Test: babytest.CommandLineTest[*babyapi.AnyResource]{ |
| 459 | + Command: api.Events.Command, |
| 460 | + ArgsFunc: func(getResponse babytest.PreviousResponseGetter) []string { |
| 461 | + eventID := getResponse("CreateEvent").Data.GetID() |
| 462 | + return []string{ |
| 463 | + "invite", "list", "--event-id", eventID, "-q", "password=secret", |
| 464 | + } |
| 465 | + }, |
| 466 | + }, |
| 467 | + ClientName: "Invite", |
| 468 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 469 | + Status: http.StatusOK, |
| 470 | + BodyRegexp: `{"items":\[{"id":"[0-9a-v]{20}","Name":"Firstname Lastname","Contact":"","EventID":"[0-9a-v]{20}","RSVP":null}]`, |
| 471 | + }, |
| 472 | + }, |
| 473 | + { |
| 474 | + Name: "GetEventWithInviteIDAsPassword", |
| 475 | + Test: babytest.CommandLineTest[*babyapi.AnyResource]{ |
| 476 | + Command: api.Events.Command, |
| 477 | + ArgsFunc: func(getResponse babytest.PreviousResponseGetter) []string { |
| 478 | + eventID := getResponse("CreateEvent").Data.GetID() |
| 479 | + return []string{ |
| 480 | + "invite", "get", |
| 481 | + getResponse("CreateInvite").Data.GetID(), "--event-id", eventID, |
| 482 | + "-q", "invite=" + getResponse("CreateInvite").Data.GetID(), |
| 483 | + } |
| 484 | + }, |
| 485 | + }, |
| 486 | + ClientName: "Invite", |
| 487 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 488 | + Status: http.StatusOK, |
| 489 | + BodyRegexp: `{"id":"[0-9a-v]{20}","Name":"Firstname Lastname","Contact":"","EventID":"[0-9a-v]{20}","RSVP":null}`, |
| 490 | + }, |
| 491 | + }, |
| 492 | + { |
| 493 | + Name: "DeleteInvite", |
| 494 | + Test: babytest.CommandLineTest[*babyapi.AnyResource]{ |
| 495 | + Command: api.Events.Command, |
| 496 | + ArgsFunc: func(getResponse babytest.PreviousResponseGetter) []string { |
| 497 | + eventID := getResponse("CreateEvent").Data.GetID() |
| 498 | + return []string{ |
| 499 | + "invite", "delete", |
| 500 | + getResponse("CreateInvite").Data.GetID(), "--event-id", eventID, |
| 501 | + } |
| 502 | + }, |
| 503 | + }, |
| 504 | + ClientName: "Invite", |
| 505 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 506 | + Status: http.StatusOK, |
| 507 | + NoBody: true, |
| 508 | + }, |
| 509 | + }, |
| 510 | + { |
| 511 | + Name: "PatchErrorNotConfigured", |
| 512 | + Test: babytest.CommandLineTest[*babyapi.AnyResource]{ |
| 513 | + Command: api.Events.Command, |
| 514 | + ArgsFunc: func(getResponse babytest.PreviousResponseGetter) []string { |
| 515 | + eventID := getResponse("CreateEvent").Data.GetID() |
| 516 | + return []string{"event", "patch", eventID, "-d", `{"Name": "NEW"}`, "-q", "password=secret"} |
| 517 | + }, |
| 518 | + }, |
| 519 | + ExpectedResponse: babytest.ExpectedResponse{ |
| 520 | + Status: http.StatusMethodNotAllowed, |
| 521 | + Body: `{"status":"Method not allowed."}`, |
| 522 | + Error: "error running client from CLI: error running Patch: error patching resource: unexpected response with text: Method not allowed.", |
| 523 | + }, |
| 524 | + }, |
| 525 | + }) |
| 526 | +} |
0 commit comments