-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessaging-grpc_test.go
93 lines (76 loc) · 2.56 KB
/
messaging-grpc_test.go
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package goautowp
import (
"context"
"testing"
"github.com/autowp/goautowp/config"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/metadata"
"google.golang.org/protobuf/types/known/emptypb"
)
func TestMessaging(t *testing.T) {
t.Parallel()
ctx := context.Background()
messagingClient := NewMessagingClient(conn)
cfg := config.LoadConfig(".")
kc := cnt.Keycloak()
usersClient := NewUsersClient(conn)
// admin
adminToken, err := kc.Login(ctx, "frontend", "", cfg.Keycloak.Realm, adminUsername, adminPassword)
require.NoError(t, err)
require.NotNil(t, adminToken)
// tester
testerToken, err := kc.Login(ctx, "frontend", "", cfg.Keycloak.Realm, testUsername, testPassword)
require.NoError(t, err)
require.NotNil(t, testerToken)
// tester (me)
tester, err := usersClient.Me(
metadata.AppendToOutgoingContext(ctx, authorizationHeader, bearerPrefix+testerToken.AccessToken),
&APIMeRequest{},
)
require.NoError(t, err)
// create
_, err = messagingClient.CreateMessage(
metadata.AppendToOutgoingContext(ctx, authorizationHeader, bearerPrefix+adminToken.AccessToken),
&MessagingCreateMessage{
UserId: tester.GetId(),
Text: "Test message",
},
)
require.NoError(t, err)
// get message
res, err := messagingClient.GetMessages(
metadata.AppendToOutgoingContext(ctx, authorizationHeader, bearerPrefix+adminToken.AccessToken),
&MessagingGetMessagesRequest{
UserId: tester.GetId(),
Folder: "sent",
Page: 1,
},
)
require.NoError(t, err)
require.Equal(t, "Test message", res.GetItems()[0].GetText())
_, err = messagingClient.GetMessagesNewCount(
metadata.AppendToOutgoingContext(ctx, authorizationHeader, bearerPrefix+adminToken.AccessToken),
&emptypb.Empty{},
)
require.NoError(t, err)
_, err = messagingClient.GetMessagesSummary(
metadata.AppendToOutgoingContext(ctx, authorizationHeader, bearerPrefix+adminToken.AccessToken),
&emptypb.Empty{},
)
require.NoError(t, err)
_, err = messagingClient.DeleteMessage(
metadata.AppendToOutgoingContext(ctx, authorizationHeader, bearerPrefix+adminToken.AccessToken),
&MessagingDeleteMessage{MessageId: res.GetItems()[0].GetId()},
)
require.NoError(t, err)
_, err = messagingClient.ClearFolder(
metadata.AppendToOutgoingContext(ctx, authorizationHeader, bearerPrefix+adminToken.AccessToken),
&MessagingClearFolder{Folder: "sent"},
)
require.NoError(t, err)
_, err = messagingClient.ClearFolder(
metadata.AppendToOutgoingContext(ctx, authorizationHeader, bearerPrefix+adminToken.AccessToken),
&MessagingClearFolder{Folder: "system"},
)
require.NoError(t, err)
}