Skip to content

Commit 3bb84f3

Browse files
committed
Setup a temporary mock chat for testing
1 parent 0b8ec7b commit 3bb84f3

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

pkg/code/data/chat/v2/id.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ func GetChatIdFromBytes(buffer []byte) (ChatId, error) {
2929
return typed, nil
3030
}
3131

32+
// GetChatIdFromBytes gets a chat ID from the string representation
33+
func GetChatIdFromString(value string) (ChatId, error) {
34+
decoded, err := hex.DecodeString(value)
35+
if err != nil {
36+
return ChatId{}, errors.Wrap(err, "value is not a hexadecimal string")
37+
}
38+
39+
return GetChatIdFromBytes(decoded)
40+
}
41+
3242
// GetChatIdFromProto gets a chat ID from the protobuf variant
3343
func GetChatIdFromProto(proto *chatpb.ChatId) (ChatId, error) {
3444
if err := proto.Validate(); err != nil {
@@ -84,6 +94,16 @@ func GetMemberIdFromBytes(buffer []byte) (MemberId, error) {
8494
return typed, nil
8595
}
8696

97+
// GetMemberIdFromString gets a chat member ID from the string representation
98+
func GetMemberIdFromString(value string) (MemberId, error) {
99+
decoded, err := uuid.Parse(value)
100+
if err != nil {
101+
return MemberId{}, errors.Wrap(err, "value is not a uuid string")
102+
}
103+
104+
return GetMemberIdFromBytes(decoded[:])
105+
}
106+
87107
// GetMemberIdFromProto gets a member ID from the protobuf variant
88108
func GetMemberIdFromProto(proto *chatpb.ChatMemberId) (MemberId, error) {
89109
if err := proto.Validate(); err != nil {
@@ -171,6 +191,16 @@ func GetMessageIdFromBytes(buffer []byte) (MessageId, error) {
171191
return typed, nil
172192
}
173193

194+
// GetMessageIdFromString gets a chat message ID from the string representation
195+
func GetMessageIdFromString(value string) (MessageId, error) {
196+
decoded, err := uuid.Parse(value)
197+
if err != nil {
198+
return MessageId{}, errors.Wrap(err, "value is not a uuid string")
199+
}
200+
201+
return GetMessageIdFromBytes(decoded[:])
202+
}
203+
174204
// GetMessageIdFromProto gets a message ID from the protobuf variant
175205
func GetMessageIdFromProto(proto *chatpb.ChatMessageId) (MessageId, error) {
176206
if err := proto.Validate(); err != nil {

pkg/code/server/grpc/chat/v2/server.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,45 @@ func NewChatServer(data code_data.Provider, auth *auth_util.RPCSignatureVerifier
6868
go s.asyncChatEventStreamNotifier(i, channel)
6969
}
7070

71+
// todo: Remove when testing is complete
72+
s.setupMockChat()
73+
7174
return s
7275
}
7376

77+
func (s *server) setupMockChat() {
78+
ctx := context.Background()
79+
80+
chatId, _ := chat.GetChatIdFromString("c355fcec8c521e7937d45283d83bbfc63a0c688004f2386a535fc817218f917b")
81+
chatRecord := &chat.ChatRecord{
82+
ChatId: chatId,
83+
ChatType: chat.ChatTypeTwoWay,
84+
IsVerified: true,
85+
CreatedAt: time.Now(),
86+
}
87+
s.data.PutChatV2(ctx, chatRecord)
88+
89+
memberId1, _ := chat.GetMemberIdFromString("034dda45-b4c2-45db-b1da-181298898a16")
90+
memberRecord1 := &chat.MemberRecord{
91+
ChatId: chatId,
92+
MemberId: memberId1,
93+
Platform: chat.PlatformCode,
94+
PlatformId: "8bw4gaRQk91w7vtgTN4E12GnKecY2y6CjPai7WUvWBQ8",
95+
JoinedAt: time.Now(),
96+
}
97+
s.data.PutChatMemberV2(ctx, memberRecord1)
98+
99+
memberId2, _ := chat.GetMemberIdFromString("a9d27058-f2d8-4034-bf52-b20c09a670de")
100+
memberRecord2 := &chat.MemberRecord{
101+
ChatId: chatId,
102+
MemberId: memberId2,
103+
Platform: chat.PlatformCode,
104+
PlatformId: "EDknQfoUnj73L56vKtEc6Qqw5VoHaF32eHYdz3V4y27M",
105+
JoinedAt: time.Now(),
106+
}
107+
s.data.PutChatMemberV2(ctx, memberRecord2)
108+
}
109+
74110
func (s *server) GetChats(ctx context.Context, req *chatpb.GetChatsRequest) (*chatpb.GetChatsResponse, error) {
75111
log := s.log.WithField("method", "GetChats")
76112
log = client.InjectLoggingMetadata(ctx, log)

0 commit comments

Comments
 (0)