storj/satellite/marketingweb/server_test.go
Faris Huskovic 0d294103e9
satellite/rewards: nicer offers handling (#2390)
* organize offers

* revert changes to go.mod and go.sum

* change OfferStatus enums back to original

* revert modified auto-gen files

* don't render empty row if offers is empty

* change return val of ListAll to Offers

* fix build

* add method to check for empty offer when rendering template

* fix typo

* fix lint and typos

* lean out IsEmpty

* dont use named return vals

* better clarify offer statuses

* change back order of setting offer.Status

* lint

* satellite/marketingweb: allow disabling rewards (#2392)

* implement handler for stop offer endpoint

* use proper text and fix data-target for free-credit stop modal
2019-07-10 13:12:40 -04:00

87 lines
2.0 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package marketingweb_test
import (
"net/http"
"net/url"
"strconv"
"testing"
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"
"storj.io/storj/internal/testcontext"
"storj.io/storj/internal/testplanet"
)
type CreateRequest struct {
Path string
Values url.Values
}
func TestCreateAndStopOffers(t *testing.T) {
testplanet.Run(t, testplanet.Config{
SatelliteCount: 1,
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
requests := []CreateRequest{
{
Path: "/create/referral-offer",
Values: url.Values{
"Name": {"Referral Credit"},
"Description": {"desc"},
"ExpiresAt": {"2119-06-27"},
"InviteeCredit": {"50"},
"InviteeCreditDurationDays": {"50"},
"AwardCredit": {"50"},
"AwardCreditDurationDays": {"50"},
"RedeemableCap": {"150"},
},
}, {
Path: "/create/free-credit-offer",
Values: url.Values{
"Name": {"Free Credit Credit"},
"Description": {"desc"},
"ExpiresAt": {"2119-06-27"},
"InviteeCredit": {"50"},
"InviteeCreditDurationDays": {"50"},
"RedeemableCap": {"150"},
},
},
}
addr := planet.Satellites[0].Marketing.Listener.Addr()
var group errgroup.Group
for index, offer := range requests {
o := offer
id := strconv.Itoa(index + 1)
group.Go(func() error {
baseURL := "http://" + addr.String()
_, err := http.PostForm(baseURL+o.Path, o.Values)
if err != nil {
return err
}
_, err = http.Get(baseURL)
if err != nil {
return err
}
_, err = http.Post(baseURL+"/stop/"+id, "application/x-www-form-urlencoded", nil)
if err != nil {
return err
}
return nil
})
}
err := group.Wait()
require.NoError(t, err)
})
}