2022-09-13 11:40:55 +01:00
|
|
|
// Copyright (C) 2022 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package consoleapi_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/storj/private/testplanet"
|
|
|
|
"storj.io/storj/satellite"
|
|
|
|
"storj.io/storj/satellite/console"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestABMethodsOnError(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 0, UplinkCount: 0,
|
|
|
|
Reconfigure: testplanet.Reconfigure{
|
|
|
|
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
|
|
|
|
config.Console.ABTesting.Enabled = true
|
|
|
|
config.Console.ABTesting.APIKey = "APIKey"
|
|
|
|
config.Console.ABTesting.EnvId = "EnvId"
|
|
|
|
config.Console.ABTesting.FlagshipURL = "FlagshipURL"
|
|
|
|
config.Console.ABTesting.HitTrackingURL = "HitTrackingURL"
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
sat := planet.Satellites[0]
|
|
|
|
service := sat.API.ABTesting.Service
|
|
|
|
|
|
|
|
newUser := console.CreateUser{
|
|
|
|
FullName: "AB-Tester",
|
|
|
|
ShortName: "",
|
|
|
|
Email: "ab@test.test",
|
|
|
|
}
|
|
|
|
|
|
|
|
user, err := sat.AddUser(ctx, newUser, 1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-09-01 20:17:39 +01:00
|
|
|
_, status, err := doRequestWithAuth(ctx, t, sat, user, http.MethodGet, "ab/values", nil)
|
2022-09-13 11:40:55 +01:00
|
|
|
require.NoError(t, err)
|
2023-09-01 20:17:39 +01:00
|
|
|
require.Equal(t, http.StatusInternalServerError, status)
|
2022-09-13 11:40:55 +01:00
|
|
|
|
|
|
|
values, err := service.GetABValues(ctx, *user)
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Nil(t, values)
|
|
|
|
|
2023-09-01 20:17:39 +01:00
|
|
|
_, status, err = doRequestWithAuth(ctx, t, sat, user, http.MethodPost, "ab/hit/upgrade-account", nil)
|
2022-09-13 11:40:55 +01:00
|
|
|
require.NoError(t, err)
|
2023-09-01 20:17:39 +01:00
|
|
|
require.Equal(t, http.StatusOK, status)
|
2022-09-13 11:40:55 +01:00
|
|
|
})
|
|
|
|
}
|