Skip to content

Commit aa846e9

Browse files
authored
fix: auth category should throw AuthError instead of PredictionsError (#830)
1 parent 8153149 commit aa846e9

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

Amplify/Categories/Auth/AuthCategory.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ final public class AuthCategory: Category {
5151
let key = plugin.key
5252
guard !key.isEmpty else {
5353
let pluginDescription = String(describing: plugin)
54-
let error = PredictionsError.configuration("Plugin \(pluginDescription) has an empty `key`.",
54+
let error = AuthError.configuration("Plugin \(pluginDescription) has an empty `key`.",
5555
"Set the `key` property for \(String(describing: plugin))")
5656
throw error
5757
}

AmplifyTestCommon/Mocks/MockAuthCategoryPlugin.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ class MockSecondAuthCategoryPlugin: MockAuthCategoryPlugin {
181181
}
182182
}
183183

184+
class MockAuthCategoryPluginWithoutKey: MockAuthCategoryPlugin {
185+
override var key: String {
186+
return ""
187+
}
188+
}
189+
184190
class MockAuthChangePasswordOperation: AmplifyOperation<AuthChangePasswordRequest, Void, AuthError>,
185191
AuthChangePasswordOperation {
186192

AmplifyTests/CategoryTests/Auth/AuthCategoryConfigurationTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,4 +392,18 @@ class AuthCategoryConfigurationTests: XCTestCase {
392392
waitForExpectations(timeout: 0.1)
393393
}
394394

395+
/// Test that Amplify throws an `AuthError` if it encounters a plugin without a key
396+
///
397+
/// - Given: Unconfigured Amplify Framework
398+
/// - When:
399+
/// - I add an Auth plugin without a key
400+
/// - Then:
401+
/// - An `AuthError` is thrown
402+
///
403+
func testThrowsPluginWithoutKey() {
404+
let plugin = MockAuthCategoryPluginWithoutKey()
405+
XCTAssertThrowsError(try Amplify.add(plugin: plugin)) { error in
406+
XCTAssertNotNil(error as? AuthError)
407+
}
408+
}
395409
}

0 commit comments

Comments
 (0)