Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
domino14 committed Feb 6, 2025
1 parent df5573c commit dc04275
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
24 changes: 20 additions & 4 deletions pkg/mod/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import (

"github.com/matryer/is"
"github.com/woogles-io/liwords/pkg/apiserver"
"github.com/woogles-io/liwords/pkg/auth/rbac"
"github.com/woogles-io/liwords/pkg/entity"
"github.com/woogles-io/liwords/pkg/stores/common"
"github.com/woogles-io/liwords/pkg/stores/models"
"github.com/woogles-io/liwords/pkg/stores/user"
pb "github.com/woogles-io/liwords/rpc/api/proto/mod_service"
)
Expand All @@ -25,9 +28,18 @@ func TestAuthenticateMod(t *testing.T) {

recreateDB()
us := userStore()
ms := &ModService{userStore: us}

_, err := authenticateMod(ctx, ms, &pb.ModActionsList{
pool, err := common.OpenTestingDB(pkg)
is.NoErr(err)
q := models.New(pool)
ms := &ModService{userStore: us, queries: q}
err = q.AssignRole(ctx, models.AssignRoleParams{
Username: common.ToPGTypeText("Moderator"),
RoleName: string(rbac.Moderator),
})
is.NoErr(err)

_, err = authenticateMod(ctx, ms, &pb.ModActionsList{
Actions: []*pb.ModAction{},
})
is.NoErr(err)
Expand All @@ -47,9 +59,13 @@ func TestAuthenticateModNoAuth(t *testing.T) {

recreateDB()
us := userStore()
ms := &ModService{userStore: us}

_, err := authenticateMod(ctx, ms, &pb.ModActionsList{
pool, err := common.OpenTestingDB(pkg)
is.NoErr(err)
q := models.New(pool)
ms := &ModService{userStore: us, queries: q}

_, err = authenticateMod(ctx, ms, &pb.ModActionsList{
Actions: []*pb.ModAction{},
})
is.Equal(err, apiserver.Unauthenticated(errNotAuthorized.Error()))
Expand Down
4 changes: 4 additions & 0 deletions pkg/stores/common/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,3 +435,7 @@ func checkRowsAffected(rowsAffected int, cfg *CommonDBConfig) error {
}
return nil
}

func ToPGTypeText(str string) pgtype.Text {
return pgtype.Text{Valid: true, String: str}
}

0 comments on commit dc04275

Please sign in to comment.