Skip to content

Commit 9504b9b

Browse files
committed
feat: BotUser => PlatformUser
1 parent 51b41a3 commit 9504b9b

File tree

6 files changed

+138
-32
lines changed

6 files changed

+138
-32
lines changed

botsfwmodels/bot_records_maker.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type BotRecordsMaker interface {
1010
MakeAppUserDto(botID string) (AppUserData, error)
1111

1212
// MakeBotUserDto makes bot user DTO for a given request sender
13-
MakeBotUserDto(botID string) (BotUserData, error)
13+
MakeBotUserDto(botID string) (PlatformUserData, error)
1414

1515
// MakeBotChatDto makes bot chat DTO for a given request
1616
MakeBotChatDto(botID string) (BotChatData, error)
@@ -19,7 +19,7 @@ type BotRecordsMaker interface {
1919
func NewBotRecordsMaker(
2020
platform string,
2121
makeAppUserDto func(botID string) (appUser AppUserData, err error),
22-
makeBotUserDto func(botID string) (botUser BotUserData, err error),
22+
makeBotUserDto func(botID string) (botUser PlatformUserData, err error),
2323
makeBotChatDto func(botID string) (botChat BotChatData, err error),
2424
) BotRecordsMaker {
2525
if makeAppUserDto == nil {
@@ -42,7 +42,7 @@ func NewBotRecordsMaker(
4242
type botRecordsMaker struct {
4343
platform string
4444
makeAppUserDto func(botID string) (AppUserData, error)
45-
makeBotUserDto func(botID string) (BotUserData, error)
45+
makeBotUserDto func(botID string) (PlatformUserData, error)
4646
makeBotChatDto func(botID string) (botChat BotChatData, err error)
4747
}
4848

@@ -54,7 +54,7 @@ func (b botRecordsMaker) MakeAppUserDto(botID string) (AppUserData, error) {
5454
return b.makeAppUserDto(botID)
5555
}
5656

57-
func (b botRecordsMaker) MakeBotUserDto(botID string) (BotUserData, error) {
57+
func (b botRecordsMaker) MakeBotUserDto(botID string) (PlatformUserData, error) {
5858
return b.makeBotUserDto(botID)
5959
}
6060

botsfwmodels/bot_records_maker_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ func TestNewBotRecordsMaker(t *testing.T) {
88
type args struct {
99
platform string
1010
makeAppUserDto func(botID string) (appUser AppUserData, err error)
11-
makeBotUserDto func(botID string) (botUser BotUserData, err error)
11+
makeBotUserDto func(botID string) (botUser PlatformUserData, err error)
1212
makeBotChatDto func(botID string) (botChat BotChatData, err error)
1313
}
1414

1515
makeAppUserDto := func(botID string) (appUser AppUserData, err error) {
1616
return nil, nil
1717
}
1818

19-
makeBotUserDto := func(botID string) (botUser BotUserData, err error) {
19+
makeBotUserDto := func(botID string) (botUser PlatformUserData, err error) {
2020
return nil, nil
2121
}
2222

botsfwmodels/bot_user_data.go

Lines changed: 0 additions & 23 deletions
This file was deleted.

botsfwmodels/chat_key_test.go

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package botsfwmodels
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
)
7+
8+
func TestChatKey_String(t *testing.T) {
9+
type fields struct {
10+
BotID string
11+
ChatID string
12+
}
13+
tests := []struct {
14+
name string
15+
fields fields
16+
want string
17+
}{
18+
{
19+
name: "empty",
20+
want: ":",
21+
},
22+
{
23+
name: "botID",
24+
fields: fields{
25+
BotID: "bot1",
26+
ChatID: "chat1",
27+
},
28+
want: "bot1:chat1",
29+
},
30+
}
31+
for _, tt := range tests {
32+
t.Run(tt.name, func(t *testing.T) {
33+
k := ChatKey{
34+
BotID: tt.fields.BotID,
35+
ChatID: tt.fields.ChatID,
36+
}
37+
if got := k.String(); got != tt.want {
38+
t.Errorf("String() = %v, want %v", got, tt.want)
39+
}
40+
})
41+
}
42+
}
43+
44+
func TestChatKey_Validate(t *testing.T) {
45+
type fields struct {
46+
BotID string
47+
ChatID string
48+
}
49+
tests := []struct {
50+
name string
51+
fields fields
52+
wantErr bool
53+
}{
54+
{
55+
name: "valid",
56+
fields: fields{
57+
BotID: "bot1",
58+
ChatID: "chat1",
59+
},
60+
wantErr: false,
61+
},
62+
}
63+
for _, tt := range tests {
64+
t.Run(tt.name, func(t *testing.T) {
65+
k := ChatKey{
66+
BotID: tt.fields.BotID,
67+
ChatID: tt.fields.ChatID,
68+
}
69+
if err := k.Validate(); (err != nil) != tt.wantErr {
70+
t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr)
71+
}
72+
})
73+
}
74+
}
75+
76+
func TestNewChatKey(t *testing.T) {
77+
type args struct {
78+
botID string
79+
chatID string
80+
}
81+
tests := []struct {
82+
name string
83+
args args
84+
want ChatKey
85+
}{
86+
{
87+
name: "valid",
88+
args: args{
89+
botID: "bot1",
90+
chatID: "chat1",
91+
},
92+
want: ChatKey{
93+
BotID: "bot1",
94+
ChatID: "chat1",
95+
},
96+
},
97+
}
98+
for _, tt := range tests {
99+
t.Run(tt.name, func(t *testing.T) {
100+
if got := NewChatKey(tt.args.botID, tt.args.chatID); !reflect.DeepEqual(got, tt.want) {
101+
t.Errorf("NewChatKey() = %v, want %v", got, tt.want)
102+
}
103+
})
104+
}
105+
}

botsfwmodels/platform_user_data.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package botsfwmodels
2+
3+
var _ PlatformUserData = (*PlatformUserBaseDbo)(nil)
4+
5+
// PlatformUserBaseDbo hold common properties for bot user entities
6+
type PlatformUserBaseDbo struct {
7+
BotBaseData
8+
9+
BotIDs []string `json:"botIDs,omitempty" dalgo:"botIDs,omitempty,noindex" firestore:"botIDs,omitempty"`
10+
11+
// FirstName is the first name of a user
12+
FirstName string `json:"firstName,omitempty" dalgo:"firstName,omitempty,noindex" firestore:"firstName,omitempty"`
13+
14+
// LastName is the last name of a user
15+
LastName string `json:"lastName,omitempty" dalgo:"lastName,omitempty,noindex" firestore:"lastName,omitempty"`
16+
17+
// UserName is login ID of a user
18+
UserName string `json:"userName,omitempty" dalgo:"userName,omitempty,noindex" firestore:"userName,omitempty"`
19+
}
20+
21+
// BaseData returns base data of a user that should be included in all structs that implement PlatformUserData
22+
func (v *PlatformUserBaseDbo) BaseData() *PlatformUserBaseDbo {
23+
return v
24+
}

botsfwmodels/bot_user_interface.go renamed to botsfwmodels/platform_user_interface.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import (
44
"time"
55
)
66

7-
// BotUserData interface provides information about bot user
7+
// PlatformUserData interface provides information about bot user
88
// This should be implemented by bot user record struct.
9-
type BotUserData interface {
9+
type PlatformUserData interface {
1010
// BaseData returns base data that should be implemented by all bot user structs
11-
BaseData() *BotUserBaseData
11+
BaseData() *PlatformUserBaseDbo
1212

1313
// GetAppUserID returns app user ID if available
1414
GetAppUserID() string

0 commit comments

Comments
 (0)