feat: support time_zone for user registration context
This commit is contained in:
@@ -20,6 +20,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const restClientEnsureTimeZone = "Europe/Kaliningrad"
|
||||
|
||||
func TestNewRESTClient(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -107,7 +109,13 @@ func TestRESTClientEndpointSuccessCases(t *testing.T) {
|
||||
{
|
||||
name: "ensure user by email",
|
||||
run: func(t *testing.T, client *RESTClient) {
|
||||
result, err := client.EnsureUserByEmail(context.Background(), common.Email("created@example.com"))
|
||||
result, err := client.EnsureUserByEmail(context.Background(), ports.EnsureUserInput{
|
||||
Email: common.Email("created@example.com"),
|
||||
RegistrationContext: &ports.RegistrationContext{
|
||||
PreferredLanguage: "en",
|
||||
TimeZone: restClientEnsureTimeZone,
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, ports.EnsureUserResult{
|
||||
Outcome: ports.EnsureUserOutcomeCreated,
|
||||
@@ -212,7 +220,7 @@ func TestRESTClientEndpointSuccessCases(t *testing.T) {
|
||||
Method: http.MethodPost,
|
||||
Path: ensureByEmailPath,
|
||||
ContentType: "application/json",
|
||||
Body: `{"email":"created@example.com"}`,
|
||||
Body: `{"email":"created@example.com","registration_context":{"preferred_language":"en","time_zone":"Europe/Kaliningrad"}}`,
|
||||
}, requests[0])
|
||||
case "block by user id":
|
||||
assert.Equal(t, capturedRequest{
|
||||
@@ -331,7 +339,13 @@ func TestRESTClientMutationMethodsDoNotRetry(t *testing.T) {
|
||||
{
|
||||
name: "ensure user by email",
|
||||
run: func(client *RESTClient) error {
|
||||
_, err := client.EnsureUserByEmail(context.Background(), common.Email("pilot@example.com"))
|
||||
_, err := client.EnsureUserByEmail(context.Background(), ports.EnsureUserInput{
|
||||
Email: common.Email("pilot@example.com"),
|
||||
RegistrationContext: &ports.RegistrationContext{
|
||||
PreferredLanguage: "en",
|
||||
TimeZone: restClientEnsureTimeZone,
|
||||
},
|
||||
})
|
||||
return err
|
||||
},
|
||||
},
|
||||
@@ -405,7 +419,13 @@ func TestRESTClientStrictDecodingAndUnexpectedStatuses(t *testing.T) {
|
||||
body: `{"outcome":"mystery"}`,
|
||||
wantErrText: "unsupported",
|
||||
run: func(client *RESTClient) error {
|
||||
_, err := client.EnsureUserByEmail(context.Background(), common.Email("pilot@example.com"))
|
||||
_, err := client.EnsureUserByEmail(context.Background(), ports.EnsureUserInput{
|
||||
Email: common.Email("pilot@example.com"),
|
||||
RegistrationContext: &ports.RegistrationContext{
|
||||
PreferredLanguage: "en",
|
||||
TimeZone: restClientEnsureTimeZone,
|
||||
},
|
||||
})
|
||||
return err
|
||||
},
|
||||
},
|
||||
@@ -415,7 +435,13 @@ func TestRESTClientStrictDecodingAndUnexpectedStatuses(t *testing.T) {
|
||||
body: `{"outcome":"created"}`,
|
||||
wantErrText: "user id",
|
||||
run: func(client *RESTClient) error {
|
||||
_, err := client.EnsureUserByEmail(context.Background(), common.Email("pilot@example.com"))
|
||||
_, err := client.EnsureUserByEmail(context.Background(), ports.EnsureUserInput{
|
||||
Email: common.Email("pilot@example.com"),
|
||||
RegistrationContext: &ports.RegistrationContext{
|
||||
PreferredLanguage: "en",
|
||||
TimeZone: restClientEnsureTimeZone,
|
||||
},
|
||||
})
|
||||
return err
|
||||
},
|
||||
},
|
||||
@@ -516,7 +542,22 @@ func TestRESTClientContextAndValidation(t *testing.T) {
|
||||
{
|
||||
name: "invalid email",
|
||||
run: func() error {
|
||||
_, err := client.EnsureUserByEmail(context.Background(), common.Email(" bad@example.com "))
|
||||
_, err := client.EnsureUserByEmail(context.Background(), ports.EnsureUserInput{
|
||||
Email: common.Email(" bad@example.com "),
|
||||
})
|
||||
return err
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "invalid registration context",
|
||||
run: func() error {
|
||||
_, err := client.EnsureUserByEmail(context.Background(), ports.EnsureUserInput{
|
||||
Email: common.Email("pilot@example.com"),
|
||||
RegistrationContext: &ports.RegistrationContext{
|
||||
PreferredLanguage: " en ",
|
||||
TimeZone: restClientEnsureTimeZone,
|
||||
},
|
||||
})
|
||||
return err
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user