-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_complete_test.go
85 lines (69 loc) · 2.27 KB
/
user_complete_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
//go:build integration
package user
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"github.com/corbado/corbado-go/v2"
"github.com/corbado/corbado-go/v2/pkg/generated/api"
"github.com/corbado/corbado-go/v2/tests/integration"
)
func TestUserOperations(t *testing.T) {
ctx := context.TODO()
testUserID := ""
t.Run("UserCreate", func(t *testing.T) {
t.Run("ValidationError", func(t *testing.T) {
rsp, err := integration.SDK(t).Users().Create(ctx, api.UserCreateReq{})
require.Nil(t, rsp)
require.Error(t, err)
serverErr := corbado.AsServerError(err)
require.NotNil(t, serverErr)
require.Equal(t, "status: cannot be blank", serverErr.GetValidationMessage())
})
t.Run("Success", func(t *testing.T) {
rsp, err := integration.SDK(t).Users().Create(ctx, api.UserCreateReq{
FullName: integration.CreateRandomTestName(t),
Status: api.UserStatusActive,
})
require.NotNil(t, rsp)
require.NoError(t, err)
testUserID = rsp.UserID
})
t.Run("SuccessActiveUser", func(t *testing.T) {
rsp, err := integration.SDK(t).Users().CreateActiveByName(ctx, *integration.CreateRandomTestName(t))
require.NotNil(t, rsp)
require.NoError(t, err)
})
})
t.Run("UserGet", func(t *testing.T) {
t.Run("NotFound", func(t *testing.T) {
rsp, err := integration.SDK(t).Users().Get(ctx, "usr-123456789")
require.Nil(t, rsp)
require.Error(t, err)
serverErr := corbado.AsServerError(err)
require.NotNil(t, serverErr)
require.Equal(t, int32(400), serverErr.HTTPStatusCode)
})
t.Run("Success", func(t *testing.T) {
rsp, err := integration.SDK(t).Users().Get(ctx, testUserID)
require.NotNil(t, rsp)
require.NoError(t, err)
})
})
t.Run("UserDelete", func(t *testing.T) {
t.Run("ValidationError", func(t *testing.T) {
rsp, err := integration.SDK(t).Users().Delete(ctx, "usr-123456789")
require.Nil(t, rsp)
require.Error(t, err)
serverErr := corbado.AsServerError(err)
require.NotNil(t, serverErr)
require.Equal(t, int32(400), serverErr.HTTPStatusCode)
require.Equal(t, "userID: does not exist", serverErr.GetValidationMessage())
})
t.Run("Success", func(t *testing.T) {
rsp, err := integration.SDK(t).Users().Delete(ctx, testUserID)
require.NotNil(t, rsp)
require.NoError(t, err)
})
})
}