-
-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
25 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,28 @@ | ||
package idp | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/okta/okta-sdk-golang/v2/okta" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestParseOktaUser(t *testing.T) { | ||
type parseOktaUserTest struct { | ||
name string | ||
invite bool | ||
inputProfile *okta.User | ||
expectedUserData *UserData | ||
assertErrFunc assert.ErrorAssertionFunc | ||
} | ||
|
||
parseOktaTestCase1 := parseOktaUserTest{ | ||
name: "Good Request", | ||
invite: true, | ||
name: "Good Request", | ||
inputProfile: &okta.User{ | ||
Id: "123", | ||
Profile: &okta.UserProfile{ | ||
"email": "[email protected]", | ||
"firstName": "John", | ||
"lastName": "Doe", | ||
"wt_account_id": "456", | ||
"wt_pending_invite": true, | ||
"email": "[email protected]", | ||
"firstName": "John", | ||
"lastName": "Doe", | ||
}, | ||
}, | ||
expectedUserData: &UserData{ | ||
|
@@ -41,36 +38,17 @@ func TestParseOktaUser(t *testing.T) { | |
|
||
parseOktaTestCase2 := parseOktaUserTest{ | ||
name: "Invalid okta user", | ||
invite: true, | ||
inputProfile: nil, | ||
expectedUserData: nil, | ||
assertErrFunc: assert.Error, | ||
} | ||
|
||
parseOktaTestCase3 := parseOktaUserTest{ | ||
name: "Invalid pending invite type", | ||
invite: false, | ||
inputProfile: &okta.User{ | ||
Id: "123", | ||
Profile: &okta.UserProfile{ | ||
"email": "[email protected]", | ||
"firstName": "John", | ||
"lastName": "Doe", | ||
"wt_account_id": "456", | ||
"wt_pending_invite": "true", | ||
}, | ||
}, | ||
expectedUserData: nil, | ||
assertErrFunc: assert.Error, | ||
} | ||
|
||
for _, testCase := range []parseOktaUserTest{parseOktaTestCase1, parseOktaTestCase2, parseOktaTestCase3} { | ||
for _, testCase := range []parseOktaUserTest{parseOktaTestCase1, parseOktaTestCase2} { | ||
t.Run(testCase.name, func(t *testing.T) { | ||
userData, err := parseOktaUser(testCase.inputProfile) | ||
testCase.assertErrFunc(t, err, testCase.assertErrFunc) | ||
|
||
if err == nil { | ||
testCase.expectedUserData.AppMetadata.WTPendingInvite = &testCase.invite | ||
assert.True(t, userDataEqual(testCase.expectedUserData, userData), "user data should match") | ||
} | ||
}) | ||
|
@@ -83,13 +61,5 @@ func userDataEqual(a, b *UserData) bool { | |
if a.Email != b.Email || a.Name != b.Name || a.ID != b.ID { | ||
return false | ||
} | ||
if a.AppMetadata.WTAccountID != b.AppMetadata.WTAccountID { | ||
return false | ||
} | ||
|
||
if a.AppMetadata.WTPendingInvite != nil && b.AppMetadata.WTPendingInvite != nil && | ||
*a.AppMetadata.WTPendingInvite != *b.AppMetadata.WTPendingInvite { | ||
return false | ||
} | ||
return true | ||
} |