@@ -217,7 +217,7 @@ func TestOrderCreate(t *testing.T) {
217
217
Claims : map [string ]string {
218
218
"email" : test .Data .testUser .Email ,
219
219
},
220
- Percentage : 15 ,
220
+ Percentage : 15 ,
221
221
ProductTypes : []string {"Book" },
222
222
},
223
223
},
@@ -249,6 +249,68 @@ func TestOrderCreate(t *testing.T) {
249
249
assert .Equal (t , uint64 (15 ), discountItem .Percentage )
250
250
assert .Equal (t , uint64 (0 ), discountItem .Fixed )
251
251
})
252
+
253
+ t .Run ("MultipleItemsWithDownloads" , func (t * testing.T ) {
254
+ test := NewRouteTest (t )
255
+
256
+ site := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
257
+ switch r .URL .Path {
258
+ case "/i/believe/i/can/fly" :
259
+ fmt .Fprint (w , productMetaFrame (
260
+ `{
261
+ "sku": "123-i-can-fly-456",
262
+ "downloads": [{"title": "First Download", "url": "/assets/first-download"}],
263
+ "prices": [{"currency": "USD", "amount": "3.00"}]
264
+ }` ,
265
+ ))
266
+ return
267
+ case "/its/not/about/the/money" :
268
+ fmt .Fprintf (w , productMetaFrame (
269
+ `{
270
+ "sku": "not-about-the-money",
271
+ "downloads": [{"title": "Second Download", "url": "/assets/second-download"}],
272
+ "prices": [{"currency": "USD", "amount": "5.00"}]
273
+ }` ,
274
+ ))
275
+ return
276
+ }
277
+ w .WriteHeader (http .StatusNotFound )
278
+ }))
279
+ defer site .Close ()
280
+ test .Config .SiteURL = site .URL
281
+
282
+ body := strings .NewReader (`{
283
+ "email": "info@example.com",
284
+ "shipping_address": {
285
+ "name": "Test User",
286
+ "address1": "Branengebranen",
287
+ "city": "Berlin", "country": "Germany", "zip": "94107"
288
+ },
289
+ "line_items": [
290
+ {"path": "/i/believe/i/can/fly", "quantity": 1},
291
+ {"path": "/its/not/about/the/money", "quantity": 1}
292
+ ]
293
+ }` )
294
+ token := test .Data .testUserToken
295
+ recorder := test .TestEndpoint (http .MethodPost , "/orders" , body , token )
296
+
297
+ order := & models.Order {}
298
+ extractPayload (t , http .StatusCreated , recorder , order )
299
+ assert .Len (t , order .Downloads , 2 )
300
+ for _ , dl := range order .Downloads {
301
+ fmt .Printf ("dl: %+v\n " , dl )
302
+ switch dl .Sku {
303
+ case "123-i-can-fly-456" :
304
+ assert .Equal (t , "First Download" , dl .Title )
305
+ assert .Equal (t , "/assets/first-download" , dl .URL )
306
+ case "not-about-the-money" :
307
+ assert .Equal (t , "Second Download" , dl .Title )
308
+ assert .Equal (t , "/assets/second-download" , dl .URL )
309
+ default :
310
+ t .Errorf ("Unknown download item: %+v" , dl )
311
+ }
312
+ }
313
+ })
252
314
}
253
315
254
316
func TestOrderCreateNewUser (t * testing.T ) {
0 commit comments