You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
2.3 KiB
Go
122 lines
2.3 KiB
Go
package players
|
|
|
|
import (
|
|
"context"
|
|
"joybuywork/internal/repository/cache"
|
|
"joybuywork/internal/repository/dao"
|
|
"joybuywork/internal/repository/model"
|
|
"joybuywork/internal/repository/withdefault"
|
|
"testing"
|
|
|
|
_ "joybuywork/test"
|
|
|
|
"github.com/rs/xid"
|
|
)
|
|
|
|
var (
|
|
testGashaponCampaignID int64 = 4602
|
|
testGashaponUserID int64 = 276303329544409088
|
|
)
|
|
|
|
func createTestGashaponUser(ctx context.Context) (*model.FissionUser, error) {
|
|
user := withdefault.FissionUser(&model.FissionUser{
|
|
CampaignID: testGashaponCampaignID,
|
|
SubUserID: xid.New().String(),
|
|
LangMark: "zh",
|
|
})
|
|
|
|
m := dao.Q.FissionUser.SubTable(testGashaponCampaignID)
|
|
err := m.WithContext(ctx).Create(user)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return user, nil
|
|
}
|
|
|
|
func testNewGashaponUser(ctx context.Context, t *testing.T, newUser bool) *Gashapon {
|
|
var user *model.FissionUser
|
|
var err error
|
|
if newUser {
|
|
user, err = createTestGashaponUser(ctx)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
} else {
|
|
user, err = cache.NewFissionUser(ctx, testGashaponCampaignID).FindById(testGashaponUserID)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
user.LangMark = "zh"
|
|
}
|
|
|
|
kg, err := NewGashapon(ctx, user)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
return kg
|
|
}
|
|
|
|
func TestNewGashapon(t *testing.T) {
|
|
ctx := context.Background()
|
|
kg := testNewGashaponUser(ctx, t, true)
|
|
t.Log(kg.GetPlayer())
|
|
}
|
|
|
|
func TestGashaponSign(t *testing.T) {
|
|
ctx := context.Background()
|
|
kg := testNewGashaponUser(ctx, t, true)
|
|
|
|
err := kg.Sign()
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
t.Log(kg.GetPlayer())
|
|
}
|
|
|
|
func TestGashaponSetInit(t *testing.T) {
|
|
ctx := context.Background()
|
|
kg := testNewGashaponUser(ctx, t, true)
|
|
|
|
err := kg.SetInit()
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
t.Log(kg.GetPlayer())
|
|
}
|
|
|
|
func TestGashaponLottery(t *testing.T) {
|
|
ctx := context.Background()
|
|
kg := testNewGashaponUser(ctx, t, true)
|
|
|
|
reward, info, record, err := kg.Lottery()
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
t.Log(reward, info, record)
|
|
}
|
|
|
|
func TestGashaponPointsUse(t *testing.T) {
|
|
ctx := context.Background()
|
|
kg := testNewGashaponUser(ctx, t, true)
|
|
|
|
status, err := kg.PointsUse()
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
t.Log(status)
|
|
}
|
|
|
|
func TestGashaponGetConf(t *testing.T) {
|
|
ctx := context.Background()
|
|
kg := testNewGashaponUser(ctx, t, true)
|
|
|
|
conf := kg.GetConf()
|
|
t.Log(conf)
|
|
}
|