storj/satellite/marketingweb/server_test.go

124 lines
3.0 KiB
Go
Raw Normal View History

satellite/marketing: Create New Offer (#2186) * update UI to reflect final mockups * implement create handler and render offers table data to UI * fix line-height unit and remove important from selectors * update file names and ids for clarity * shorten 'label' in ids * localize global vars, fix endpoint names, remove unnecessary receiver, fix comments * fix unnecessary initialization of pointer * correct file-naming conventions * register timeConverter in an init func for safety and remove unnecessary important from css * consolidate create endpoints and add comments * register timeConverter in init func * add copyright to files * introduce require pkg * add proper http server unit test * update linting and create offers concurrently in unit test * fix getOffers comment * add copy-right to unit-test * fix data-races * fix linting * remove converter in NewServer * requested changes in progress * add require for checking status code * renamed template file * fix 400 handler * fix missing copyright and remove extra line * fix build * run goroutine for testing parallel * evaluate reqType with switch stmt and promp for credit amount in cents * fix lint issue * add default case * remove unnecessary var * fix range scope error * remove empty lines and use long form for struct field * fix merge conflicts * fix template reference * fix modal id * not delete package * add currency formatting and requested changes * markup formatting * lean out currency logic and move wait outside loop * pass ToDollars func to home template * fix lint
2019-06-28 15:34:10 +01:00
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package marketingweb_test
import (
"io"
"io/ioutil"
satellite/marketing: Create New Offer (#2186) * update UI to reflect final mockups * implement create handler and render offers table data to UI * fix line-height unit and remove important from selectors * update file names and ids for clarity * shorten 'label' in ids * localize global vars, fix endpoint names, remove unnecessary receiver, fix comments * fix unnecessary initialization of pointer * correct file-naming conventions * register timeConverter in an init func for safety and remove unnecessary important from css * consolidate create endpoints and add comments * register timeConverter in init func * add copyright to files * introduce require pkg * add proper http server unit test * update linting and create offers concurrently in unit test * fix getOffers comment * add copy-right to unit-test * fix data-races * fix linting * remove converter in NewServer * requested changes in progress * add require for checking status code * renamed template file * fix 400 handler * fix missing copyright and remove extra line * fix build * run goroutine for testing parallel * evaluate reqType with switch stmt and promp for credit amount in cents * fix lint issue * add default case * remove unnecessary var * fix range scope error * remove empty lines and use long form for struct field * fix merge conflicts * fix template reference * fix modal id * not delete package * add currency formatting and requested changes * markup formatting * lean out currency logic and move wait outside loop * pass ToDollars func to home template * fix lint
2019-06-28 15:34:10 +01:00
"net/http"
"net/url"
"strconv"
satellite/marketing: Create New Offer (#2186) * update UI to reflect final mockups * implement create handler and render offers table data to UI * fix line-height unit and remove important from selectors * update file names and ids for clarity * shorten 'label' in ids * localize global vars, fix endpoint names, remove unnecessary receiver, fix comments * fix unnecessary initialization of pointer * correct file-naming conventions * register timeConverter in an init func for safety and remove unnecessary important from css * consolidate create endpoints and add comments * register timeConverter in init func * add copyright to files * introduce require pkg * add proper http server unit test * update linting and create offers concurrently in unit test * fix getOffers comment * add copy-right to unit-test * fix data-races * fix linting * remove converter in NewServer * requested changes in progress * add require for checking status code * renamed template file * fix 400 handler * fix missing copyright and remove extra line * fix build * run goroutine for testing parallel * evaluate reqType with switch stmt and promp for credit amount in cents * fix lint issue * add default case * remove unnecessary var * fix range scope error * remove empty lines and use long form for struct field * fix merge conflicts * fix template reference * fix modal id * not delete package * add currency formatting and requested changes * markup formatting * lean out currency logic and move wait outside loop * pass ToDollars func to home template * fix lint
2019-06-28 15:34:10 +01:00
"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) {
satellite/marketing: Create New Offer (#2186) * update UI to reflect final mockups * implement create handler and render offers table data to UI * fix line-height unit and remove important from selectors * update file names and ids for clarity * shorten 'label' in ids * localize global vars, fix endpoint names, remove unnecessary receiver, fix comments * fix unnecessary initialization of pointer * correct file-naming conventions * register timeConverter in an init func for safety and remove unnecessary important from css * consolidate create endpoints and add comments * register timeConverter in init func * add copyright to files * introduce require pkg * add proper http server unit test * update linting and create offers concurrently in unit test * fix getOffers comment * add copy-right to unit-test * fix data-races * fix linting * remove converter in NewServer * requested changes in progress * add require for checking status code * renamed template file * fix 400 handler * fix missing copyright and remove extra line * fix build * run goroutine for testing parallel * evaluate reqType with switch stmt and promp for credit amount in cents * fix lint issue * add default case * remove unnecessary var * fix range scope error * remove empty lines and use long form for struct field * fix merge conflicts * fix template reference * fix modal id * not delete package * add currency formatting and requested changes * markup formatting * lean out currency logic and move wait outside loop * pass ToDollars func to home template * fix lint
2019-06-28 15:34:10 +01:00
testplanet.Run(t, testplanet.Config{
SatelliteCount: 1,
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
requests := []CreateRequest{
{
Path: "/create/referral",
satellite/marketing: Create New Offer (#2186) * update UI to reflect final mockups * implement create handler and render offers table data to UI * fix line-height unit and remove important from selectors * update file names and ids for clarity * shorten 'label' in ids * localize global vars, fix endpoint names, remove unnecessary receiver, fix comments * fix unnecessary initialization of pointer * correct file-naming conventions * register timeConverter in an init func for safety and remove unnecessary important from css * consolidate create endpoints and add comments * register timeConverter in init func * add copyright to files * introduce require pkg * add proper http server unit test * update linting and create offers concurrently in unit test * fix getOffers comment * add copy-right to unit-test * fix data-races * fix linting * remove converter in NewServer * requested changes in progress * add require for checking status code * renamed template file * fix 400 handler * fix missing copyright and remove extra line * fix build * run goroutine for testing parallel * evaluate reqType with switch stmt and promp for credit amount in cents * fix lint issue * add default case * remove unnecessary var * fix range scope error * remove empty lines and use long form for struct field * fix merge conflicts * fix template reference * fix modal id * not delete package * add currency formatting and requested changes * markup formatting * lean out currency logic and move wait outside loop * pass ToDollars func to home template * fix lint
2019-06-28 15:34:10 +01:00
Values: url.Values{
"Name": {"Referral Credit"},
"Description": {"desc"},
"ExpiresAt": {"2119-06-27"},
"InviteeCredit": {"50"},
satellite/marketing: Create New Offer (#2186) * update UI to reflect final mockups * implement create handler and render offers table data to UI * fix line-height unit and remove important from selectors * update file names and ids for clarity * shorten 'label' in ids * localize global vars, fix endpoint names, remove unnecessary receiver, fix comments * fix unnecessary initialization of pointer * correct file-naming conventions * register timeConverter in an init func for safety and remove unnecessary important from css * consolidate create endpoints and add comments * register timeConverter in init func * add copyright to files * introduce require pkg * add proper http server unit test * update linting and create offers concurrently in unit test * fix getOffers comment * add copy-right to unit-test * fix data-races * fix linting * remove converter in NewServer * requested changes in progress * add require for checking status code * renamed template file * fix 400 handler * fix missing copyright and remove extra line * fix build * run goroutine for testing parallel * evaluate reqType with switch stmt and promp for credit amount in cents * fix lint issue * add default case * remove unnecessary var * fix range scope error * remove empty lines and use long form for struct field * fix merge conflicts * fix template reference * fix modal id * not delete package * add currency formatting and requested changes * markup formatting * lean out currency logic and move wait outside loop * pass ToDollars func to home template * fix lint
2019-06-28 15:34:10 +01:00
"InviteeCreditDurationDays": {"50"},
"AwardCredit": {"50"},
satellite/marketing: Create New Offer (#2186) * update UI to reflect final mockups * implement create handler and render offers table data to UI * fix line-height unit and remove important from selectors * update file names and ids for clarity * shorten 'label' in ids * localize global vars, fix endpoint names, remove unnecessary receiver, fix comments * fix unnecessary initialization of pointer * correct file-naming conventions * register timeConverter in an init func for safety and remove unnecessary important from css * consolidate create endpoints and add comments * register timeConverter in init func * add copyright to files * introduce require pkg * add proper http server unit test * update linting and create offers concurrently in unit test * fix getOffers comment * add copy-right to unit-test * fix data-races * fix linting * remove converter in NewServer * requested changes in progress * add require for checking status code * renamed template file * fix 400 handler * fix missing copyright and remove extra line * fix build * run goroutine for testing parallel * evaluate reqType with switch stmt and promp for credit amount in cents * fix lint issue * add default case * remove unnecessary var * fix range scope error * remove empty lines and use long form for struct field * fix merge conflicts * fix template reference * fix modal id * not delete package * add currency formatting and requested changes * markup formatting * lean out currency logic and move wait outside loop * pass ToDollars func to home template * fix lint
2019-06-28 15:34:10 +01:00
"AwardCreditDurationDays": {"50"},
"RedeemableCap": {"150"},
},
}, {
Path: "/create/free-credit",
satellite/marketing: Create New Offer (#2186) * update UI to reflect final mockups * implement create handler and render offers table data to UI * fix line-height unit and remove important from selectors * update file names and ids for clarity * shorten 'label' in ids * localize global vars, fix endpoint names, remove unnecessary receiver, fix comments * fix unnecessary initialization of pointer * correct file-naming conventions * register timeConverter in an init func for safety and remove unnecessary important from css * consolidate create endpoints and add comments * register timeConverter in init func * add copyright to files * introduce require pkg * add proper http server unit test * update linting and create offers concurrently in unit test * fix getOffers comment * add copy-right to unit-test * fix data-races * fix linting * remove converter in NewServer * requested changes in progress * add require for checking status code * renamed template file * fix 400 handler * fix missing copyright and remove extra line * fix build * run goroutine for testing parallel * evaluate reqType with switch stmt and promp for credit amount in cents * fix lint issue * add default case * remove unnecessary var * fix range scope error * remove empty lines and use long form for struct field * fix merge conflicts * fix template reference * fix modal id * not delete package * add currency formatting and requested changes * markup formatting * lean out currency logic and move wait outside loop * pass ToDollars func to home template * fix lint
2019-06-28 15:34:10 +01:00
Values: url.Values{
"Name": {"Free Credit"},
"Description": {"desc"},
"ExpiresAt": {"2119-06-27"},
"InviteeCredit": {"50"},
"InviteeCreditDurationDays": {"50"},
"RedeemableCap": {"150"},
},
}, {
Path: "/create/partner",
Values: url.Values{
"Name": {"FileZilla"},
satellite/marketing: Create New Offer (#2186) * update UI to reflect final mockups * implement create handler and render offers table data to UI * fix line-height unit and remove important from selectors * update file names and ids for clarity * shorten 'label' in ids * localize global vars, fix endpoint names, remove unnecessary receiver, fix comments * fix unnecessary initialization of pointer * correct file-naming conventions * register timeConverter in an init func for safety and remove unnecessary important from css * consolidate create endpoints and add comments * register timeConverter in init func * add copyright to files * introduce require pkg * add proper http server unit test * update linting and create offers concurrently in unit test * fix getOffers comment * add copy-right to unit-test * fix data-races * fix linting * remove converter in NewServer * requested changes in progress * add require for checking status code * renamed template file * fix 400 handler * fix missing copyright and remove extra line * fix build * run goroutine for testing parallel * evaluate reqType with switch stmt and promp for credit amount in cents * fix lint issue * add default case * remove unnecessary var * fix range scope error * remove empty lines and use long form for struct field * fix merge conflicts * fix template reference * fix modal id * not delete package * add currency formatting and requested changes * markup formatting * lean out currency logic and move wait outside loop * pass ToDollars func to home template * fix lint
2019-06-28 15:34:10 +01:00
"Description": {"desc"},
"ExpiresAt": {"2119-06-27"},
"InviteeCredit": {"50"},
satellite/marketing: Create New Offer (#2186) * update UI to reflect final mockups * implement create handler and render offers table data to UI * fix line-height unit and remove important from selectors * update file names and ids for clarity * shorten 'label' in ids * localize global vars, fix endpoint names, remove unnecessary receiver, fix comments * fix unnecessary initialization of pointer * correct file-naming conventions * register timeConverter in an init func for safety and remove unnecessary important from css * consolidate create endpoints and add comments * register timeConverter in init func * add copyright to files * introduce require pkg * add proper http server unit test * update linting and create offers concurrently in unit test * fix getOffers comment * add copy-right to unit-test * fix data-races * fix linting * remove converter in NewServer * requested changes in progress * add require for checking status code * renamed template file * fix 400 handler * fix missing copyright and remove extra line * fix build * run goroutine for testing parallel * evaluate reqType with switch stmt and promp for credit amount in cents * fix lint issue * add default case * remove unnecessary var * fix range scope error * remove empty lines and use long form for struct field * fix merge conflicts * fix template reference * fix modal id * not delete package * add currency formatting and requested changes * markup formatting * lean out currency logic and move wait outside loop * pass ToDollars func to home template * fix lint
2019-06-28 15:34:10 +01:00
"InviteeCreditDurationDays": {"50"},
"RedeemableCap": {"150"},
},
},
}
addr := planet.Satellites[0].Marketing.Listener.Addr()
var group errgroup.Group
for index, offer := range requests {
satellite/marketing: Create New Offer (#2186) * update UI to reflect final mockups * implement create handler and render offers table data to UI * fix line-height unit and remove important from selectors * update file names and ids for clarity * shorten 'label' in ids * localize global vars, fix endpoint names, remove unnecessary receiver, fix comments * fix unnecessary initialization of pointer * correct file-naming conventions * register timeConverter in an init func for safety and remove unnecessary important from css * consolidate create endpoints and add comments * register timeConverter in init func * add copyright to files * introduce require pkg * add proper http server unit test * update linting and create offers concurrently in unit test * fix getOffers comment * add copy-right to unit-test * fix data-races * fix linting * remove converter in NewServer * requested changes in progress * add require for checking status code * renamed template file * fix 400 handler * fix missing copyright and remove extra line * fix build * run goroutine for testing parallel * evaluate reqType with switch stmt and promp for credit amount in cents * fix lint issue * add default case * remove unnecessary var * fix range scope error * remove empty lines and use long form for struct field * fix merge conflicts * fix template reference * fix modal id * not delete package * add currency formatting and requested changes * markup formatting * lean out currency logic and move wait outside loop * pass ToDollars func to home template * fix lint
2019-06-28 15:34:10 +01:00
o := offer
id := strconv.Itoa(index + 1)
satellite/marketing: Create New Offer (#2186) * update UI to reflect final mockups * implement create handler and render offers table data to UI * fix line-height unit and remove important from selectors * update file names and ids for clarity * shorten 'label' in ids * localize global vars, fix endpoint names, remove unnecessary receiver, fix comments * fix unnecessary initialization of pointer * correct file-naming conventions * register timeConverter in an init func for safety and remove unnecessary important from css * consolidate create endpoints and add comments * register timeConverter in init func * add copyright to files * introduce require pkg * add proper http server unit test * update linting and create offers concurrently in unit test * fix getOffers comment * add copy-right to unit-test * fix data-races * fix linting * remove converter in NewServer * requested changes in progress * add require for checking status code * renamed template file * fix 400 handler * fix missing copyright and remove extra line * fix build * run goroutine for testing parallel * evaluate reqType with switch stmt and promp for credit amount in cents * fix lint issue * add default case * remove unnecessary var * fix range scope error * remove empty lines and use long form for struct field * fix merge conflicts * fix template reference * fix modal id * not delete package * add currency formatting and requested changes * markup formatting * lean out currency logic and move wait outside loop * pass ToDollars func to home template * fix lint
2019-06-28 15:34:10 +01:00
group.Go(func() error {
baseURL := "http://" + addr.String()
req, err := http.PostForm(baseURL+o.Path, o.Values)
satellite/marketing: Create New Offer (#2186) * update UI to reflect final mockups * implement create handler and render offers table data to UI * fix line-height unit and remove important from selectors * update file names and ids for clarity * shorten 'label' in ids * localize global vars, fix endpoint names, remove unnecessary receiver, fix comments * fix unnecessary initialization of pointer * correct file-naming conventions * register timeConverter in an init func for safety and remove unnecessary important from css * consolidate create endpoints and add comments * register timeConverter in init func * add copyright to files * introduce require pkg * add proper http server unit test * update linting and create offers concurrently in unit test * fix getOffers comment * add copy-right to unit-test * fix data-races * fix linting * remove converter in NewServer * requested changes in progress * add require for checking status code * renamed template file * fix 400 handler * fix missing copyright and remove extra line * fix build * run goroutine for testing parallel * evaluate reqType with switch stmt and promp for credit amount in cents * fix lint issue * add default case * remove unnecessary var * fix range scope error * remove empty lines and use long form for struct field * fix merge conflicts * fix template reference * fix modal id * not delete package * add currency formatting and requested changes * markup formatting * lean out currency logic and move wait outside loop * pass ToDollars func to home template * fix lint
2019-06-28 15:34:10 +01:00
if err != nil {
return err
}
require.Equal(t, http.StatusOK, req.StatusCode)
//reading out the rest of the connection
_, err = io.Copy(ioutil.Discard, req.Body)
if err != nil {
return err
}
if err := req.Body.Close(); err != nil {
return err
}
satellite/marketing: Create New Offer (#2186) * update UI to reflect final mockups * implement create handler and render offers table data to UI * fix line-height unit and remove important from selectors * update file names and ids for clarity * shorten 'label' in ids * localize global vars, fix endpoint names, remove unnecessary receiver, fix comments * fix unnecessary initialization of pointer * correct file-naming conventions * register timeConverter in an init func for safety and remove unnecessary important from css * consolidate create endpoints and add comments * register timeConverter in init func * add copyright to files * introduce require pkg * add proper http server unit test * update linting and create offers concurrently in unit test * fix getOffers comment * add copy-right to unit-test * fix data-races * fix linting * remove converter in NewServer * requested changes in progress * add require for checking status code * renamed template file * fix 400 handler * fix missing copyright and remove extra line * fix build * run goroutine for testing parallel * evaluate reqType with switch stmt and promp for credit amount in cents * fix lint issue * add default case * remove unnecessary var * fix range scope error * remove empty lines and use long form for struct field * fix merge conflicts * fix template reference * fix modal id * not delete package * add currency formatting and requested changes * markup formatting * lean out currency logic and move wait outside loop * pass ToDollars func to home template * fix lint
2019-06-28 15:34:10 +01:00
req, err = http.Get(baseURL)
satellite/marketing: Create New Offer (#2186) * update UI to reflect final mockups * implement create handler and render offers table data to UI * fix line-height unit and remove important from selectors * update file names and ids for clarity * shorten 'label' in ids * localize global vars, fix endpoint names, remove unnecessary receiver, fix comments * fix unnecessary initialization of pointer * correct file-naming conventions * register timeConverter in an init func for safety and remove unnecessary important from css * consolidate create endpoints and add comments * register timeConverter in init func * add copyright to files * introduce require pkg * add proper http server unit test * update linting and create offers concurrently in unit test * fix getOffers comment * add copy-right to unit-test * fix data-races * fix linting * remove converter in NewServer * requested changes in progress * add require for checking status code * renamed template file * fix 400 handler * fix missing copyright and remove extra line * fix build * run goroutine for testing parallel * evaluate reqType with switch stmt and promp for credit amount in cents * fix lint issue * add default case * remove unnecessary var * fix range scope error * remove empty lines and use long form for struct field * fix merge conflicts * fix template reference * fix modal id * not delete package * add currency formatting and requested changes * markup formatting * lean out currency logic and move wait outside loop * pass ToDollars func to home template * fix lint
2019-06-28 15:34:10 +01:00
if err != nil {
return err
}
require.Equal(t, http.StatusOK, req.StatusCode)
_, err = io.Copy(ioutil.Discard, req.Body)
if err != nil {
return err
}
if err := req.Body.Close(); err != nil {
return err
}
satellite/marketing: Create New Offer (#2186) * update UI to reflect final mockups * implement create handler and render offers table data to UI * fix line-height unit and remove important from selectors * update file names and ids for clarity * shorten 'label' in ids * localize global vars, fix endpoint names, remove unnecessary receiver, fix comments * fix unnecessary initialization of pointer * correct file-naming conventions * register timeConverter in an init func for safety and remove unnecessary important from css * consolidate create endpoints and add comments * register timeConverter in init func * add copyright to files * introduce require pkg * add proper http server unit test * update linting and create offers concurrently in unit test * fix getOffers comment * add copy-right to unit-test * fix data-races * fix linting * remove converter in NewServer * requested changes in progress * add require for checking status code * renamed template file * fix 400 handler * fix missing copyright and remove extra line * fix build * run goroutine for testing parallel * evaluate reqType with switch stmt and promp for credit amount in cents * fix lint issue * add default case * remove unnecessary var * fix range scope error * remove empty lines and use long form for struct field * fix merge conflicts * fix template reference * fix modal id * not delete package * add currency formatting and requested changes * markup formatting * lean out currency logic and move wait outside loop * pass ToDollars func to home template * fix lint
2019-06-28 15:34:10 +01:00
req, err = http.Post(baseURL+"/stop/"+id, "application/x-www-form-urlencoded", nil)
if err != nil {
return err
}
require.Equal(t, http.StatusOK, req.StatusCode)
_, err = io.Copy(ioutil.Discard, req.Body)
if err != nil {
return err
}
if err := req.Body.Close(); err != nil {
return err
}
satellite/marketing: Create New Offer (#2186) * update UI to reflect final mockups * implement create handler and render offers table data to UI * fix line-height unit and remove important from selectors * update file names and ids for clarity * shorten 'label' in ids * localize global vars, fix endpoint names, remove unnecessary receiver, fix comments * fix unnecessary initialization of pointer * correct file-naming conventions * register timeConverter in an init func for safety and remove unnecessary important from css * consolidate create endpoints and add comments * register timeConverter in init func * add copyright to files * introduce require pkg * add proper http server unit test * update linting and create offers concurrently in unit test * fix getOffers comment * add copy-right to unit-test * fix data-races * fix linting * remove converter in NewServer * requested changes in progress * add require for checking status code * renamed template file * fix 400 handler * fix missing copyright and remove extra line * fix build * run goroutine for testing parallel * evaluate reqType with switch stmt and promp for credit amount in cents * fix lint issue * add default case * remove unnecessary var * fix range scope error * remove empty lines and use long form for struct field * fix merge conflicts * fix template reference * fix modal id * not delete package * add currency formatting and requested changes * markup formatting * lean out currency logic and move wait outside loop * pass ToDollars func to home template * fix lint
2019-06-28 15:34:10 +01:00
return nil
})
}
err := group.Wait()
require.NoError(t, err)
})
}