2019-11-25 21:36:36 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package referrals_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/pb"
|
2020-02-26 13:59:46 +00:00
|
|
|
"storj.io/common/pb/pbgrpc"
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/rpc/rpcstatus"
|
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/common/testrand"
|
2019-11-25 21:36:36 +00:00
|
|
|
"storj.io/storj/private/testplanet"
|
|
|
|
"storj.io/storj/satellite/referrals"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestServiceSuccess(t *testing.T) {
|
|
|
|
tokenCount := 2
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1,
|
|
|
|
Reconfigure: testplanet.Reconfigure{
|
2020-02-26 13:59:46 +00:00
|
|
|
ReferralManagerServer: func(logger *zap.Logger) pbgrpc.ReferralManagerServer {
|
2019-12-10 16:32:54 +00:00
|
|
|
endpoint := &endpointHappyPath{}
|
2019-11-25 21:36:36 +00:00
|
|
|
endpoint.SetTokenCount(tokenCount)
|
|
|
|
return endpoint
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
|
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
|
2020-04-02 15:18:08 +01:00
|
|
|
userID := testrand.UUID()
|
2019-11-25 21:36:36 +00:00
|
|
|
tokens, err := satellite.API.Referrals.Service.GetTokens(ctx, &userID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, tokens, tokenCount)
|
|
|
|
|
|
|
|
user := referrals.CreateUser{
|
|
|
|
FullName: "test",
|
|
|
|
ShortName: "test",
|
|
|
|
Email: "test@mail.test",
|
|
|
|
Password: "123a123",
|
2020-04-02 15:18:08 +01:00
|
|
|
ReferralToken: testrand.UUID().String(),
|
2019-11-25 21:36:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
createdUser, err := satellite.API.Referrals.Service.CreateUser(ctx, user)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, user.Email, createdUser.Email)
|
|
|
|
require.Equal(t, user.FullName, createdUser.FullName)
|
|
|
|
require.Equal(t, user.ShortName, createdUser.ShortName)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServiceRedeemFailure(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1,
|
|
|
|
Reconfigure: testplanet.Reconfigure{
|
2020-02-26 13:59:46 +00:00
|
|
|
ReferralManagerServer: func(logger *zap.Logger) pbgrpc.ReferralManagerServer {
|
2019-12-10 16:32:54 +00:00
|
|
|
endpoint := &endpointFailedPath{}
|
2019-11-25 21:36:36 +00:00
|
|
|
endpoint.SetTokenCount(2)
|
|
|
|
return endpoint
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
|
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
|
|
|
|
user := referrals.CreateUser{
|
|
|
|
FullName: "test",
|
|
|
|
ShortName: "test",
|
|
|
|
Email: "test@mail.test",
|
|
|
|
Password: "123a123",
|
2020-04-02 15:18:08 +01:00
|
|
|
ReferralToken: testrand.UUID().String(),
|
2019-11-25 21:36:36 +00:00
|
|
|
}
|
|
|
|
_, err := satellite.API.Referrals.Service.CreateUser(ctx, user)
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type endpointHappyPath struct {
|
|
|
|
testplanet.DefaultReferralManagerServer
|
|
|
|
}
|
|
|
|
|
|
|
|
type endpointFailedPath struct {
|
|
|
|
testplanet.DefaultReferralManagerServer
|
|
|
|
}
|
|
|
|
|
|
|
|
func (endpoint *endpointFailedPath) RedeemToken(ctx context.Context, req *pb.RedeemTokenRequest) (*pb.RedeemTokenResponse, error) {
|
|
|
|
return nil, rpcstatus.Error(rpcstatus.NotFound, "")
|
|
|
|
}
|