~evanj/cms

ref: 8a453a73244ce94c291204147a7ee2cbf61f7ab2 cms/internal/m/user/mock.go -rw-r--r-- 1.4 KiB
8a453a73Evan M Jones Fix(testing): Refactor'd tests per RBAC feat breakage. All tests 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package user

import (
	"git.sr.ht/~evanj/cms/internal/m/org"
	"git.sr.ht/~evanj/cms/internal/m/role"
	"git.sr.ht/~evanj/cms/internal/m/tier"
	"github.com/google/uuid"
)

type _user struct {
	id, name, tok, email string
	org                  _org
	pass                 string
	role                 role.Role
}

type _org struct {
	id string
}

func NewMock(id, name string) _user {
	return _user{id, name, uuid.New().String(), "", _org{id}, "", role.Admin}
}

func NewMockWithEmail(id, name, email string) _user {
	return _user{id, name, uuid.New().String(), email, _org{id}, "", role.Admin}
}

func NewMockWithRole(id, name string, r role.Role) _user {
	return _user{id, name, uuid.New().String(), "", _org{id}, "", r}
}

func (u _user) ID() string             { return u.id }
func (u _user) Name() string           { return u.name }
func (u _user) Token() string          { return u.tok }
func (u _user) HasEmail() bool         { return u.email != "" }
func (u _user) Email() string          { return u.email }
func (u _user) Org() org.Org           { return u.org }
func (u _user) SetPass(p string) _user { u.pass = p; return u }
func (u _user) Pass() string           { return u.pass }
func (u _user) Role() role.Role        { return u.role }

func (o _org) ID() string                { return o.id }
func (o _org) HasPaymentCustomer() bool  { return false }
func (o _org) PaymentCustomerID() string { return "" }
func (o _org) Tier() tier.Tier           { return tier.Free }