mirror of https://gitee.com/answerdev/answer.git
refactor(repo): refactor some repo test
This commit is contained in:
parent
964195fd85
commit
fcb48b86ee
|
@ -93,7 +93,6 @@ func (cc *ConnectorController) ConnectorLogin(connector plugin.Connector) (fn fu
|
||||||
if len(redirectURL) > 0 {
|
if len(redirectURL) > 0 {
|
||||||
ctx.Redirect(http.StatusFound, redirectURL)
|
ctx.Redirect(http.StatusFound, redirectURL)
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -189,7 +189,6 @@ func (tc *TemplateController) QuestionInfoeRdirect(ctx *gin.Context, siteInfo *s
|
||||||
titleIsAnswerID = true
|
titleIsAnswerID = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
siteInfo = tc.SiteInfo(ctx)
|
|
||||||
url = fmt.Sprintf("%s/questions/%s", siteInfo.General.SiteUrl, id)
|
url = fmt.Sprintf("%s/questions/%s", siteInfo.General.SiteUrl, id)
|
||||||
if siteInfo.SiteSeo.PermaLink == constant.PermaLinkQuestionID || siteInfo.SiteSeo.PermaLink == constant.PermaLinkQuestionIDByShortID {
|
if siteInfo.SiteSeo.PermaLink == constant.PermaLinkQuestionID || siteInfo.SiteSeo.PermaLink == constant.PermaLinkQuestionIDByShortID {
|
||||||
if len(ctx.Request.URL.Query()) > 0 {
|
if len(ctx.Request.URL.Query()) > 0 {
|
||||||
|
|
|
@ -1,61 +0,0 @@
|
||||||
package repo_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/answerdev/answer/internal/schema"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Test_configRepo_Get(t *testing.T) {
|
|
||||||
configRepo := config_common.NewConfigRepo(testDataSource)
|
|
||||||
_, err := configRepo.Get("email.config")
|
|
||||||
assert.NoError(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Test_configRepo_GetArrayString(t *testing.T) {
|
|
||||||
configRepo := config_common.NewConfigRepo(testDataSource)
|
|
||||||
got, err := configRepo.GetArrayString("daily_rank_limit.exclude")
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, 1, len(got))
|
|
||||||
assert.Equal(t, "answer.accepted", got[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
func Test_configRepo_GetConfigById(t *testing.T) {
|
|
||||||
configRepo := config_common.NewConfigRepo(testDataSource)
|
|
||||||
|
|
||||||
closeInfo := &schema.GetReportTypeResp{}
|
|
||||||
err := configRepo.GetJsonConfigByIDAndSetToObject(74, closeInfo)
|
|
||||||
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, "needs close", closeInfo.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Test_configRepo_GetConfigType(t *testing.T) {
|
|
||||||
configRepo := config_common.NewConfigRepo(testDataSource)
|
|
||||||
configType, err := configRepo.GetConfigType("answer.accepted")
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, 1, configType)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Test_configRepo_GetInt(t *testing.T) {
|
|
||||||
configRepo := config_common.NewConfigRepo(testDataSource)
|
|
||||||
got, err := configRepo.GetInt("answer.accepted")
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, 15, got)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Test_configRepo_GetString(t *testing.T) {
|
|
||||||
configRepo := config_common.NewConfigRepo(testDataSource)
|
|
||||||
_, err := configRepo.GetString("email.config")
|
|
||||||
assert.NoError(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Test_configRepo_SetConfig(t *testing.T) {
|
|
||||||
configRepo := config_common.NewConfigRepo(testDataSource)
|
|
||||||
got, err := configRepo.GetString("email.config")
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
err = configRepo.SetConfig("email.config", got)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
}
|
|
|
@ -2,6 +2,8 @@ package repo_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/answerdev/answer/internal/repo/config"
|
||||||
|
serviceconfig "github.com/answerdev/answer/internal/service/config"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/answerdev/answer/internal/repo/reason"
|
"github.com/answerdev/answer/internal/repo/reason"
|
||||||
|
@ -9,8 +11,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_reasonRepo_ListReasons(t *testing.T) {
|
func Test_reasonRepo_ListReasons(t *testing.T) {
|
||||||
configRepo := config_common.NewConfigRepo(testDataSource)
|
configRepo := config.NewConfigRepo(testDataSource)
|
||||||
reasonRepo := reason.NewReasonRepo(configRepo)
|
reasonRepo := reason.NewReasonRepo(serviceconfig.NewConfigService(configRepo))
|
||||||
reasonItems, err := reasonRepo.ListReasons(context.TODO(), "question", "close")
|
reasonItems, err := reasonRepo.ListReasons(context.TODO(), "question", "close")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, 4, len(reasonItems))
|
assert.Equal(t, 4, len(reasonItems))
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package repo_test
|
package repo_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
@ -55,6 +56,10 @@ func TestMain(t *testing.M) {
|
||||||
// Use sqlite3 to test.
|
// Use sqlite3 to test.
|
||||||
dbSetting = dbSettingMapping[string(schemas.SQLITE)]
|
dbSetting = dbSettingMapping[string(schemas.SQLITE)]
|
||||||
}
|
}
|
||||||
|
if dbSetting.Driver == string(schemas.SQLITE) {
|
||||||
|
os.RemoveAll(dbSetting.Connection)
|
||||||
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if tearDown != nil {
|
if tearDown != nil {
|
||||||
tearDown()
|
tearDown()
|
||||||
|
@ -160,8 +165,15 @@ func initDatabase(dbSetting TestDBSetting) (dbEngine *xorm.Engine, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("connection to database failed: %s", err)
|
return nil, fmt.Errorf("connection to database failed: %s", err)
|
||||||
}
|
}
|
||||||
err = migrations.InitDB(dataConf)
|
if err := migrations.NewMentor(context.TODO(), dbEngine, &migrations.InitNeedUserInputData{
|
||||||
if err != nil {
|
Language: "en_US",
|
||||||
|
SiteName: "ANSWER",
|
||||||
|
SiteURL: "http://127.0.0.1:8080/",
|
||||||
|
ContactEmail: "answer@answer.com",
|
||||||
|
AdminName: "admin",
|
||||||
|
AdminPassword: "admin",
|
||||||
|
AdminEmail: "answer@answer.com",
|
||||||
|
}).InitDB(); err != nil {
|
||||||
return nil, fmt.Errorf("migrations init database failed: %s", err)
|
return nil, fmt.Errorf("migrations init database failed: %s", err)
|
||||||
}
|
}
|
||||||
return dbEngine, nil
|
return dbEngine, nil
|
||||||
|
|
|
@ -2,6 +2,8 @@ package repo_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/answerdev/answer/internal/repo/unique"
|
||||||
|
"log"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -14,29 +16,29 @@ var (
|
||||||
tagRelOnce sync.Once
|
tagRelOnce sync.Once
|
||||||
testTagRelList = []*entity.TagRel{
|
testTagRelList = []*entity.TagRel{
|
||||||
{
|
{
|
||||||
ObjectID: "1",
|
ObjectID: "10010000000000001",
|
||||||
TagID: "1",
|
TagID: "10030000000000001",
|
||||||
Status: entity.TagRelStatusAvailable,
|
Status: entity.TagRelStatusAvailable,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ObjectID: "2",
|
ObjectID: "10010000000000002",
|
||||||
TagID: "2",
|
TagID: "10030000000000002",
|
||||||
Status: entity.TagRelStatusAvailable,
|
Status: entity.TagRelStatusAvailable,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func addTagRelList() {
|
func addTagRelList() {
|
||||||
tagRelRepo := tag.NewTagRelRepo(testDataSource)
|
tagRelRepo := tag.NewTagRelRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))
|
||||||
err := tagRelRepo.AddTagRelList(context.TODO(), testTagRelList)
|
err := tagRelRepo.AddTagRelList(context.TODO(), testTagRelList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Fatalf("%+v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_tagListRepo_BatchGetObjectTagRelList(t *testing.T) {
|
func Test_tagListRepo_BatchGetObjectTagRelList(t *testing.T) {
|
||||||
tagRelOnce.Do(addTagRelList)
|
tagRelOnce.Do(addTagRelList)
|
||||||
tagRelRepo := tag.NewTagRelRepo(testDataSource)
|
tagRelRepo := tag.NewTagRelRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))
|
||||||
relList, err :=
|
relList, err :=
|
||||||
tagRelRepo.BatchGetObjectTagRelList(context.TODO(), []string{testTagRelList[0].ObjectID, testTagRelList[1].ObjectID})
|
tagRelRepo.BatchGetObjectTagRelList(context.TODO(), []string{testTagRelList[0].ObjectID, testTagRelList[1].ObjectID})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -45,15 +47,15 @@ func Test_tagListRepo_BatchGetObjectTagRelList(t *testing.T) {
|
||||||
|
|
||||||
func Test_tagListRepo_CountTagRelByTagID(t *testing.T) {
|
func Test_tagListRepo_CountTagRelByTagID(t *testing.T) {
|
||||||
tagRelOnce.Do(addTagRelList)
|
tagRelOnce.Do(addTagRelList)
|
||||||
tagRelRepo := tag.NewTagRelRepo(testDataSource)
|
tagRelRepo := tag.NewTagRelRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))
|
||||||
count, err := tagRelRepo.CountTagRelByTagID(context.TODO(), "1")
|
count, err := tagRelRepo.CountTagRelByTagID(context.TODO(), "10030000000000001")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, int64(1), count)
|
assert.Equal(t, int64(1), count)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_tagListRepo_GetObjectTagRelList(t *testing.T) {
|
func Test_tagListRepo_GetObjectTagRelList(t *testing.T) {
|
||||||
tagRelOnce.Do(addTagRelList)
|
tagRelOnce.Do(addTagRelList)
|
||||||
tagRelRepo := tag.NewTagRelRepo(testDataSource)
|
tagRelRepo := tag.NewTagRelRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))
|
||||||
|
|
||||||
relList, err :=
|
relList, err :=
|
||||||
tagRelRepo.GetObjectTagRelList(context.TODO(), testTagRelList[0].ObjectID)
|
tagRelRepo.GetObjectTagRelList(context.TODO(), testTagRelList[0].ObjectID)
|
||||||
|
@ -63,7 +65,7 @@ func Test_tagListRepo_GetObjectTagRelList(t *testing.T) {
|
||||||
|
|
||||||
func Test_tagListRepo_GetObjectTagRelWithoutStatus(t *testing.T) {
|
func Test_tagListRepo_GetObjectTagRelWithoutStatus(t *testing.T) {
|
||||||
tagRelOnce.Do(addTagRelList)
|
tagRelOnce.Do(addTagRelList)
|
||||||
tagRelRepo := tag.NewTagRelRepo(testDataSource)
|
tagRelRepo := tag.NewTagRelRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))
|
||||||
|
|
||||||
relList, err :=
|
relList, err :=
|
||||||
tagRelRepo.BatchGetObjectTagRelList(context.TODO(), []string{testTagRelList[0].ObjectID, testTagRelList[1].ObjectID})
|
tagRelRepo.BatchGetObjectTagRelList(context.TODO(), []string{testTagRelList[0].ObjectID, testTagRelList[1].ObjectID})
|
||||||
|
@ -74,7 +76,7 @@ func Test_tagListRepo_GetObjectTagRelWithoutStatus(t *testing.T) {
|
||||||
err = tagRelRepo.RemoveTagRelListByIDs(context.TODO(), ids)
|
err = tagRelRepo.RemoveTagRelListByIDs(context.TODO(), ids)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
count, err := tagRelRepo.CountTagRelByTagID(context.TODO(), "1")
|
count, err := tagRelRepo.CountTagRelByTagID(context.TODO(), "10030000000000001")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, int64(0), count)
|
assert.Equal(t, int64(0), count)
|
||||||
|
|
||||||
|
@ -85,7 +87,7 @@ func Test_tagListRepo_GetObjectTagRelWithoutStatus(t *testing.T) {
|
||||||
err = tagRelRepo.EnableTagRelByIDs(context.TODO(), ids)
|
err = tagRelRepo.EnableTagRelByIDs(context.TODO(), ids)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
count, err = tagRelRepo.CountTagRelByTagID(context.TODO(), "1")
|
count, err = tagRelRepo.CountTagRelByTagID(context.TODO(), "10030000000000001")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, int64(1), count)
|
assert.Equal(t, int64(1), count)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package repo_test
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -46,7 +47,7 @@ func addTagList() {
|
||||||
tagCommonRepo := tag_common.NewTagCommonRepo(testDataSource, uniqueIDRepo)
|
tagCommonRepo := tag_common.NewTagCommonRepo(testDataSource, uniqueIDRepo)
|
||||||
err := tagCommonRepo.AddTagList(context.TODO(), testTagList)
|
err := tagCommonRepo.AddTagList(context.TODO(), testTagList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Fatalf("%+v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_userRepo_AddUser(t *testing.T) {
|
func Test_userRepo_AddUser(t *testing.T) {
|
||||||
userRepo := user.NewUserRepo(testDataSource, config_common.NewConfigRepo(testDataSource))
|
userRepo := user.NewUserRepo(testDataSource)
|
||||||
userInfo := &entity.User{
|
userInfo := &entity.User{
|
||||||
Username: "answer",
|
Username: "answer",
|
||||||
Pass: "answer",
|
Pass: "answer",
|
||||||
|
@ -25,7 +25,7 @@ func Test_userRepo_AddUser(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_userRepo_BatchGetByID(t *testing.T) {
|
func Test_userRepo_BatchGetByID(t *testing.T) {
|
||||||
userRepo := user.NewUserRepo(testDataSource, config_common.NewConfigRepo(testDataSource))
|
userRepo := user.NewUserRepo(testDataSource)
|
||||||
got, err := userRepo.BatchGetByID(context.TODO(), []string{"1"})
|
got, err := userRepo.BatchGetByID(context.TODO(), []string{"1"})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, 1, len(got))
|
assert.Equal(t, 1, len(got))
|
||||||
|
@ -33,7 +33,7 @@ func Test_userRepo_BatchGetByID(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_userRepo_GetByEmail(t *testing.T) {
|
func Test_userRepo_GetByEmail(t *testing.T) {
|
||||||
userRepo := user.NewUserRepo(testDataSource, config_common.NewConfigRepo(testDataSource))
|
userRepo := user.NewUserRepo(testDataSource)
|
||||||
got, exist, err := userRepo.GetByEmail(context.TODO(), "admin@admin.com")
|
got, exist, err := userRepo.GetByEmail(context.TODO(), "admin@admin.com")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, exist)
|
assert.True(t, exist)
|
||||||
|
@ -41,7 +41,7 @@ func Test_userRepo_GetByEmail(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_userRepo_GetByUserID(t *testing.T) {
|
func Test_userRepo_GetByUserID(t *testing.T) {
|
||||||
userRepo := user.NewUserRepo(testDataSource, config_common.NewConfigRepo(testDataSource))
|
userRepo := user.NewUserRepo(testDataSource)
|
||||||
got, exist, err := userRepo.GetByUserID(context.TODO(), "1")
|
got, exist, err := userRepo.GetByUserID(context.TODO(), "1")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, exist)
|
assert.True(t, exist)
|
||||||
|
@ -49,7 +49,7 @@ func Test_userRepo_GetByUserID(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_userRepo_GetByUsername(t *testing.T) {
|
func Test_userRepo_GetByUsername(t *testing.T) {
|
||||||
userRepo := user.NewUserRepo(testDataSource, config_common.NewConfigRepo(testDataSource))
|
userRepo := user.NewUserRepo(testDataSource)
|
||||||
got, exist, err := userRepo.GetByUsername(context.TODO(), "admin")
|
got, exist, err := userRepo.GetByUsername(context.TODO(), "admin")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, exist)
|
assert.True(t, exist)
|
||||||
|
@ -57,7 +57,7 @@ func Test_userRepo_GetByUsername(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_userRepo_IncreaseAnswerCount(t *testing.T) {
|
func Test_userRepo_IncreaseAnswerCount(t *testing.T) {
|
||||||
userRepo := user.NewUserRepo(testDataSource, config_common.NewConfigRepo(testDataSource))
|
userRepo := user.NewUserRepo(testDataSource)
|
||||||
err := userRepo.IncreaseAnswerCount(context.TODO(), "1", 1)
|
err := userRepo.IncreaseAnswerCount(context.TODO(), "1", 1)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ func Test_userRepo_IncreaseAnswerCount(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_userRepo_IncreaseQuestionCount(t *testing.T) {
|
func Test_userRepo_IncreaseQuestionCount(t *testing.T) {
|
||||||
userRepo := user.NewUserRepo(testDataSource, config_common.NewConfigRepo(testDataSource))
|
userRepo := user.NewUserRepo(testDataSource)
|
||||||
err := userRepo.IncreaseQuestionCount(context.TODO(), "1", 1)
|
err := userRepo.IncreaseQuestionCount(context.TODO(), "1", 1)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
@ -79,19 +79,19 @@ func Test_userRepo_IncreaseQuestionCount(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_userRepo_UpdateEmail(t *testing.T) {
|
func Test_userRepo_UpdateEmail(t *testing.T) {
|
||||||
userRepo := user.NewUserRepo(testDataSource, config_common.NewConfigRepo(testDataSource))
|
userRepo := user.NewUserRepo(testDataSource)
|
||||||
err := userRepo.UpdateEmail(context.TODO(), "1", "admin@admin.com")
|
err := userRepo.UpdateEmail(context.TODO(), "1", "admin@admin.com")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_userRepo_UpdateEmailStatus(t *testing.T) {
|
func Test_userRepo_UpdateEmailStatus(t *testing.T) {
|
||||||
userRepo := user.NewUserRepo(testDataSource, config_common.NewConfigRepo(testDataSource))
|
userRepo := user.NewUserRepo(testDataSource)
|
||||||
err := userRepo.UpdateEmailStatus(context.TODO(), "1", entity.EmailStatusToBeVerified)
|
err := userRepo.UpdateEmailStatus(context.TODO(), "1", entity.EmailStatusToBeVerified)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_userRepo_UpdateInfo(t *testing.T) {
|
func Test_userRepo_UpdateInfo(t *testing.T) {
|
||||||
userRepo := user.NewUserRepo(testDataSource, config_common.NewConfigRepo(testDataSource))
|
userRepo := user.NewUserRepo(testDataSource)
|
||||||
err := userRepo.UpdateInfo(context.TODO(), &entity.User{ID: "1", Bio: "test"})
|
err := userRepo.UpdateInfo(context.TODO(), &entity.User{ID: "1", Bio: "test"})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
@ -102,19 +102,19 @@ func Test_userRepo_UpdateInfo(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_userRepo_UpdateLastLoginDate(t *testing.T) {
|
func Test_userRepo_UpdateLastLoginDate(t *testing.T) {
|
||||||
userRepo := user.NewUserRepo(testDataSource, config_common.NewConfigRepo(testDataSource))
|
userRepo := user.NewUserRepo(testDataSource)
|
||||||
err := userRepo.UpdateLastLoginDate(context.TODO(), "1")
|
err := userRepo.UpdateLastLoginDate(context.TODO(), "1")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_userRepo_UpdateNoticeStatus(t *testing.T) {
|
func Test_userRepo_UpdateNoticeStatus(t *testing.T) {
|
||||||
userRepo := user.NewUserRepo(testDataSource, config_common.NewConfigRepo(testDataSource))
|
userRepo := user.NewUserRepo(testDataSource)
|
||||||
err := userRepo.UpdateNoticeStatus(context.TODO(), "1", 1)
|
err := userRepo.UpdateNoticeStatus(context.TODO(), "1", 1)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_userRepo_UpdatePass(t *testing.T) {
|
func Test_userRepo_UpdatePass(t *testing.T) {
|
||||||
userRepo := user.NewUserRepo(testDataSource, config_common.NewConfigRepo(testDataSource))
|
userRepo := user.NewUserRepo(testDataSource)
|
||||||
err := userRepo.UpdatePass(context.TODO(), "1", "admin")
|
err := userRepo.UpdatePass(context.TODO(), "1", "admin")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package tag
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/answerdev/answer/internal/base/data"
|
"github.com/answerdev/answer/internal/base/data"
|
||||||
"github.com/answerdev/answer/internal/base/handler"
|
"github.com/answerdev/answer/internal/base/handler"
|
||||||
"github.com/answerdev/answer/internal/base/reason"
|
"github.com/answerdev/answer/internal/base/reason"
|
||||||
|
|
|
@ -156,7 +156,9 @@ func (us *UserCenterLoginService) registerNewUser(ctx context.Context, provider
|
||||||
MetaInfo: string(metaInfo),
|
MetaInfo: string(metaInfo),
|
||||||
}
|
}
|
||||||
err = us.userExternalLoginRepo.AddUserExternalLogin(ctx, newExternalUserInfo)
|
err = us.userExternalLoginRepo.AddUserExternalLogin(ctx, newExternalUserInfo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return userInfo, nil
|
return userInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,6 +90,9 @@ func (vs *VoteService) VoteUp(ctx context.Context, req *schema.VoteReq) (resp *s
|
||||||
}
|
}
|
||||||
err = vs.voteRepo.Vote(ctx, voteUpOperationInfo)
|
err = vs.voteRepo.Vote(ctx, voteUpOperationInfo)
|
||||||
}
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
resp = &schema.VoteResp{}
|
resp = &schema.VoteResp{}
|
||||||
resp.UpVotes, resp.DownVotes, err = vs.voteRepo.GetAndSaveVoteResult(ctx, req.ObjectID, objectInfo.ObjectType)
|
resp.UpVotes, resp.DownVotes, err = vs.voteRepo.GetAndSaveVoteResult(ctx, req.ObjectID, objectInfo.ObjectType)
|
||||||
|
|
|
@ -22,8 +22,5 @@ func IsSupportedImageFile(file io.Reader, ext string) bool {
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if err != nil {
|
return err == nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package gravatar
|
package gravatar
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/answerdev/answer/internal/base/constant"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -23,7 +24,7 @@ func TestGetAvatarURL(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
assert.Equal(t, tt.want, GetAvatarURL(tt.args.email))
|
assert.Equal(t, tt.want, GetAvatarURL(constant.DefaultGravatarBaseURL, tt.args.email))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue