Skip to content

Commit

Permalink
fix(auth): configure with standardAttributes snake case values (#3686)
Browse files Browse the repository at this point in the history
  • Loading branch information
lawmicha authored May 8, 2024
1 parent 668095a commit b864d41
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
12 changes: 6 additions & 6 deletions Amplify/Core/Configuration/AmplifyOutputsData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,19 @@ public struct AmplifyOutputsData: Codable {
case address
case birthdate
case email
case familyName
case familyName = "family_name"
case gender
case givenName
case givenName = "given_name"
case locale
case middleName
case middleName = "middle_name"
case name
case nickname
case phoneNumber
case phoneNumber = "phone_number"
case picture
case preferredUsername
case preferredUsername = "preferred_username"
case profile
case sub
case updatedAt
case updatedAt = "updated_at"
case website
case zoneinfo
}
Expand Down
22 changes: 21 additions & 1 deletion AmplifyTests/CoreTests/AmplifyOutputsInitializationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class AmplifyOutputsInitializationTests: XCTestCase {
}
}


/// Given: A data object with valid AmplifyOutputs JSON
/// When: Amplify.configure(with: .data(:)) is invoked
/// Then: Decoded data should contain the correct data, decoding snake case to camel case.
Expand All @@ -97,6 +96,27 @@ class AmplifyOutputsInitializationTests: XCTestCase {
XCTAssertEqual(config.analytics?.amazonPinpoint?.awsRegion, "us-east-1")
}

/// Given: A data object with valid AmplifyOutputs JSON containing snake case values.
/// When: Amplify.configure(with: .data(:)) is invoked
/// Then: Decoded data should contain the correct data, decoding snake case values to camel case enum cases.
func testSnakeCaseJSONValues() throws {
let validAmplifyOutputsJSON = #"{"version": "1", "auth": { "aws_region": "us-east-1", "user_pool_id": "poolId123", "user_pool_client_id": "clientId123", "standard_required_attributes": [ "family_name", "given_name", "middle_name", "phone_number", "preferred_username", "updated_at" ]}}"#
let configData = Data(validAmplifyOutputsJSON.utf8)

try Amplify.configure(with: .data(configData))
let config = try AmplifyOutputsData.decodeAmplifyOutputsData(from: configData)
XCTAssertEqual(config.version, "1")

guard let auth = config.auth, let attributes = auth.standardRequiredAttributes else {
XCTFail("Missing auth config after decoding")
return
}
XCTAssertEqual(auth.awsRegion, "us-east-1")
XCTAssertEqual(auth.userPoolId, "poolId123")
XCTAssertEqual(auth.userPoolClientId, "clientId123")
XCTAssertEqual(attributes.count, 6)
}

/// - Given: A valid configuration
/// - When:
/// - Amplify is finished configuring its plugins
Expand Down

0 comments on commit b864d41

Please sign in to comment.