fix v13
This commit is contained in:
@@ -31,6 +31,7 @@ func TestQuestions(t *testing.T) {
|
||||
{"GetByUserID", testQuestionsGetByUserID},
|
||||
{"GetByAskUserID", testQuestionsGetByAskUserID},
|
||||
{"AnswerByID", testQuestionsAnswerByID},
|
||||
{"AnswerByIDPrivate", testQuestionsAnswerByIDPrivate},
|
||||
{"DeleteByID", testQuestionsDeleteByID},
|
||||
{"UpdateCensor", testQuestionsUpdateCensor},
|
||||
{"Count", testQuestionsCount},
|
||||
@@ -322,6 +323,33 @@ func testQuestionsAnswerByID(t *testing.T, ctx context.Context, db *questions) {
|
||||
})
|
||||
}
|
||||
|
||||
// testQuestionsAnswerByIDPrivate 覆盖 L2「收窄公开」的写入语义:
|
||||
// 回答与 is_private 必须在同一次写入里生效,不能出现「公开 + 已作答」的中间态。
|
||||
func testQuestionsAnswerByIDPrivate(t *testing.T, ctx context.Context, db *questions) {
|
||||
t.Run("normal", func(t *testing.T) {
|
||||
_, err := db.Create(ctx, CreateQuestionOptions{
|
||||
FromIP: "114.5.1.4",
|
||||
UserID: 1,
|
||||
Content: "Content - 1",
|
||||
AskerUserID: 1,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
err = db.AnswerByIDPrivate(ctx, 1, "Answer - 1")
|
||||
require.Nil(t, err)
|
||||
|
||||
got, err := db.GetByID(ctx, 1)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, "Answer - 1", got.Answer)
|
||||
require.True(t, got.IsPrivate)
|
||||
})
|
||||
|
||||
t.Run("not found", func(t *testing.T) {
|
||||
err := db.AnswerByIDPrivate(ctx, 404, "Answer - 1")
|
||||
require.Equal(t, ErrQuestionNotExist, err)
|
||||
})
|
||||
}
|
||||
|
||||
func testQuestionsDeleteByID(t *testing.T, ctx context.Context, db *questions) {
|
||||
t.Run("normal", func(t *testing.T) {
|
||||
_, err := db.Create(ctx, CreateQuestionOptions{
|
||||
|
||||
Reference in New Issue
Block a user