Skip to content

Commit 8c33196

Browse files
Adds missing tests for AuthenticateWithMagicAuth and SendMagicAuthCode
1 parent c84ebab commit 8c33196

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

pkg/users/users_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,3 +386,51 @@ func TestUsersAuthenticateWithPassword(t *testing.T) {
386386
require.NoError(t, err)
387387
require.Equal(t, expectedResponse, authenticationRes)
388388
}
389+
390+
func TestUsersAuthenticateWithMagicAuth(t *testing.T) {
391+
server := httptest.NewServer(http.HandlerFunc(authenticationResponseTestHandler))
392+
393+
defer server.Close()
394+
395+
DefaultClient = mockClient(server)
396+
397+
SetAPIKey("test")
398+
399+
expectedResponse := AuthenticationResponse{
400+
User: User{
401+
ID: "testUserID",
402+
FirstName: "John",
403+
LastName: "Doe",
404+
405+
},
406+
}
407+
408+
authenticationRes, err := AuthenticateWithMagicAuth(context.Background(), AuthenticateUserWithMagicAuthOpts{})
409+
410+
require.NoError(t, err)
411+
require.Equal(t, expectedResponse, authenticationRes)
412+
}
413+
414+
func TestUsersSendMagicAuthCode(t *testing.T) {
415+
server := httptest.NewServer(http.HandlerFunc(sendMagicAuthCodeTestHandler))
416+
417+
defer server.Close()
418+
419+
DefaultClient = mockClient(server)
420+
421+
SetAPIKey("test")
422+
423+
expectedResponse := User{
424+
ID: "user_01E3JC5F5Z1YJNPGVYWV9SX6GH",
425+
426+
FirstName: "Marcelina",
427+
LastName: "Davis",
428+
CreatedAt: "2021-06-25T19:07:33.155Z",
429+
UpdatedAt: "2021-06-25T19:07:33.155Z",
430+
}
431+
432+
authenticationRes, err := SendMagicAuthCode(context.Background(), SendMagicAuthCodeOpts{})
433+
434+
require.NoError(t, err)
435+
require.Equal(t, expectedResponse, authenticationRes)
436+
}

0 commit comments

Comments
 (0)