Projeto bot pontos
This commit is contained in:
26
backend/internal/httpapi/middleware_test.go
Normal file
26
backend/internal/httpapi/middleware_test.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"botpontos/internal/domain"
|
||||
)
|
||||
|
||||
func TestIsRestricted(t *testing.T) {
|
||||
id := int64(7)
|
||||
cases := []struct {
|
||||
name string
|
||||
account domain.WebAccount
|
||||
want bool
|
||||
}{
|
||||
{"leitura ligada a um usuário", domain.WebAccount{Role: domain.RoleViewer, UserID: &id}, true},
|
||||
{"leitura sem vínculo", domain.WebAccount{Role: domain.RoleViewer}, false},
|
||||
{"admin ligado a um usuário", domain.WebAccount{Role: domain.RoleAdmin, UserID: &id}, false},
|
||||
{"owner ligado a um usuário", domain.WebAccount{Role: domain.RoleOwner, UserID: &id}, false},
|
||||
}
|
||||
for _, c := range cases {
|
||||
if got := isRestricted(c.account); got != c.want {
|
||||
t.Errorf("%s: isRestricted = %v, esperado %v", c.name, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user