-
Notifications
You must be signed in to change notification settings - Fork 8
/
e2e_test.go
69 lines (55 loc) · 2.17 KB
/
e2e_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
package tests
import (
"context"
"testing"
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/common/client"
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/common/genproto/users"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
)
func TestCreateTraining(t *testing.T) {
t.Parallel()
hour := RelativeDate(12, 12)
userID := "TestCreateTraining-user"
trainerJWT := FakeTrainerJWT(t, uuid.New().String())
attendeeJWT := FakeAttendeeJWT(t, userID)
trainerHTTPClient := NewTrainerHTTPClient(t, trainerJWT)
trainingsHTTPClient := NewTrainingsHTTPClient(t, attendeeJWT)
usersHTTPClient := NewUsersHTTPClient(t, attendeeJWT)
usersGrpcClient, _, err := client.NewUsersClient()
require.NoError(t, err)
// Cancel the training if exists and make the hour available
trainings := trainingsHTTPClient.GetTrainings(t)
for _, training := range trainings.Trainings {
if training.Time.Equal(hour) {
trainingsTrainerHTTPClient := NewTrainingsHTTPClient(t, trainerJWT)
trainingsTrainerHTTPClient.CancelTraining(t, training.Uuid, 200)
break
}
}
hours := trainerHTTPClient.GetTrainerAvailableHours(t, hour, hour)
if len(hours) > 0 {
for _, h := range hours[0].Hours {
if h.Hour.Equal(hour) {
trainerHTTPClient.MakeHourUnavailable(t, hour)
break
}
}
}
trainerHTTPClient.MakeHourAvailable(t, hour)
user := usersHTTPClient.GetCurrentUser(t)
originalBalance := user.Balance
_, err = usersGrpcClient.UpdateTrainingBalance(context.Background(), &users.UpdateTrainingBalanceRequest{
UserId: userID,
AmountChange: 1,
})
require.NoError(t, err)
user = usersHTTPClient.GetCurrentUser(t)
require.Equal(t, originalBalance+1, user.Balance, "Attendee's balance should be updated")
trainingUUID := trainingsHTTPClient.CreateTraining(t, "some note", hour)
trainingsResponse := trainingsHTTPClient.GetTrainings(t)
require.Len(t, trainingsResponse.Trainings, 1)
require.Equal(t, trainingUUID, trainingsResponse.Trainings[0].Uuid, "Attendee should see the training")
user = usersHTTPClient.GetCurrentUser(t)
require.Equal(t, originalBalance, user.Balance, "Attendee's balance should be updated after a training is scheduled")
}