2019-06-06 17:07:14 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package console_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"storj.io/storj/internal/testcontext"
|
2019-06-26 11:38:51 +01:00
|
|
|
"storj.io/storj/internal/testrand"
|
2019-06-06 17:07:14 +01:00
|
|
|
"storj.io/storj/satellite"
|
|
|
|
"storj.io/storj/satellite/console"
|
|
|
|
"storj.io/storj/satellite/satellitedb/satellitedbtest"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUserPaymentInfos(t *testing.T) {
|
|
|
|
satellitedbtest.Run(t, func(t *testing.T, db satellite.DB) {
|
|
|
|
ctx := testcontext.New(t)
|
|
|
|
consoleDB := db.Console()
|
|
|
|
|
2019-06-26 11:38:51 +01:00
|
|
|
customerID := testrand.Bytes(8)
|
|
|
|
passHash := testrand.Bytes(8)
|
2019-06-06 17:07:14 +01:00
|
|
|
|
|
|
|
// create user
|
|
|
|
user, err := consoleDB.Users().Insert(ctx, &console.User{
|
|
|
|
FullName: "John Doe",
|
2019-06-18 01:28:40 +01:00
|
|
|
Email: "john@mail.test",
|
2019-06-26 11:38:51 +01:00
|
|
|
PasswordHash: passHash,
|
2019-06-06 17:07:14 +01:00
|
|
|
Status: console.Active,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
t.Run("create user payment info", func(t *testing.T) {
|
|
|
|
info, err := consoleDB.UserPayments().Create(ctx, console.UserPayment{
|
|
|
|
UserID: user.ID,
|
2019-06-26 11:38:51 +01:00
|
|
|
CustomerID: customerID,
|
2019-06-06 17:07:14 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, user.ID, info.UserID)
|
2019-06-26 11:38:51 +01:00
|
|
|
assert.Equal(t, customerID, info.CustomerID)
|
2019-06-06 17:07:14 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("get user payment info", func(t *testing.T) {
|
|
|
|
info, err := consoleDB.UserPayments().Get(ctx, user.ID)
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, user.ID, info.UserID)
|
2019-06-26 11:38:51 +01:00
|
|
|
assert.Equal(t, customerID, info.CustomerID)
|
2019-06-06 17:07:14 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|