test: enhance service test coverage and add audit tests

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-02-04 14:58:12 +08:00
parent 33ad8c544e
commit bc9e5d9293
4 changed files with 168 additions and 14 deletions

View File

@@ -3,11 +3,10 @@ package services
import (
"context"
"database/sql"
"errors"
"testing"
"quyun/v2/app/commands/testx"
"quyun/v2/app/errorx"
user_dto "quyun/v2/app/http/v1/dto"
"quyun/v2/database"
"quyun/v2/database/models"
@@ -63,14 +62,13 @@ func (s *UserTestSuite) Test_LoginWithOTP() {
So(resp.User.Nickname, ShouldStartWith, "User_")
})
Convey("should reject login when not tenant member", func() {
Convey("should allow login when not tenant member", func() {
phone := "13800138001"
_, err := User.LoginWithOTP(ctx, tenant.ID, phone, "1234")
So(err, ShouldNotBeNil)
var appErr *errorx.AppError
So(errors.As(err, &appErr), ShouldBeTrue)
So(appErr.Code, ShouldEqual, errorx.ErrForbidden.Code)
resp, err := User.LoginWithOTP(ctx, tenant.ID, phone, "1234")
So(err, ShouldBeNil)
So(resp, ShouldNotBeNil)
So(resp.Token, ShouldNotBeEmpty)
So(resp.User.Phone, ShouldEqual, phone)
})
Convey("should login existing tenant member", func() {