-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrating-grpc_test.go
130 lines (97 loc) · 3.25 KB
/
rating-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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package goautowp
import (
"context"
"math/rand"
"strconv"
"testing"
"time"
"github.com/autowp/goautowp/config"
"github.com/autowp/goautowp/schema"
"github.com/doug-martin/goqu/v9"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/metadata"
"google.golang.org/protobuf/types/known/emptypb"
)
func TestLikesRating(t *testing.T) {
t.Parallel()
ctx := context.Background()
client := NewRatingClient(conn)
r, err := client.GetUserCommentsRating(ctx, &emptypb.Empty{})
require.NoError(t, err)
for _, item := range r.GetUsers() {
_, err = client.GetUserCommentsRatingFans(ctx, &UserRatingDetailsRequest{UserId: item.GetUserId()})
require.NoError(t, err)
}
}
func TestPictureLikesRating(t *testing.T) {
t.Parallel()
ctx := context.Background()
cfg := config.LoadConfig("..")
goquDB, err := cnt.GoquDB()
require.NoError(t, err)
kc := cnt.Keycloak()
usersClient := NewUsersClient(conn)
// 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)
// admin
adminToken, err := kc.Login(ctx, "frontend", "", cfg.Keycloak.Realm, adminUsername, adminPassword)
require.NoError(t, err)
require.NotNil(t, adminToken)
random := rand.New(rand.NewSource(time.Now().UnixNano())) //nolint: gosec
identity := "p" + strconv.Itoa(random.Int())[:6]
res, err := goquDB.Insert(schema.PictureTable).Rows(goqu.Record{
schema.PictureTableIdentityColName: identity,
schema.PictureTableStatusColName: schema.PictureStatusAccepted,
schema.PictureTableIPColName: "",
schema.PictureTableOwnerIDColName: tester.GetId(),
}).Executor().ExecContext(ctx)
require.NoError(t, err)
pictureID, err := res.LastInsertId()
require.NoError(t, err)
picturesClient := NewPicturesClient(conn)
_, err = picturesClient.Vote(
metadata.AppendToOutgoingContext(ctx, authorizationHeader, bearerPrefix+adminToken.AccessToken),
&PicturesVoteRequest{PictureId: pictureID, Value: 1},
)
require.NoError(t, err)
client := NewRatingClient(conn)
r, err := client.GetUserPictureLikesRating(ctx, &emptypb.Empty{})
require.NoError(t, err)
for _, item := range r.GetUsers() {
_, err = client.GetUserPictureLikesRatingFans(ctx, &UserRatingDetailsRequest{UserId: item.GetUserId()})
require.NoError(t, err)
}
}
func TestPicturesRating(t *testing.T) {
t.Parallel()
ctx := context.Background()
client := NewRatingClient(conn)
r, err := client.GetUserPicturesRating(ctx, &emptypb.Empty{})
require.NoError(t, err)
for _, item := range r.GetUsers() {
_, err = client.GetUserPicturesRatingBrands(ctx, &UserRatingDetailsRequest{
UserId: item.GetUserId(),
Language: "en",
})
require.NoError(t, err)
}
}
func TestSpecsRating(t *testing.T) {
t.Parallel()
ctx := context.Background()
client := NewRatingClient(conn)
r, err := client.GetUserSpecsRating(ctx, &emptypb.Empty{})
require.NoError(t, err)
for _, item := range r.GetUsers() {
_, err = client.GetUserSpecsRatingBrands(ctx, &UserRatingDetailsRequest{UserId: item.GetUserId()})
require.NoError(t, err)
}
}