Skip to content

Commit e48a021

Browse files
authored
chore: kickoff release
2 parents f57b88c + 97d3da0 commit e48a021

File tree

6 files changed

+60
-18
lines changed

6 files changed

+60
-18
lines changed

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/Helpers/ListDevicesOutputResponse+Helper.swift

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,20 @@ import AWSPluginsCore
1313
extension CognitoIdentityProviderClientTypes.DeviceType {
1414

1515
func toAWSAuthDevice() -> AuthDevice {
16-
let id = deviceKey ?? ""
17-
let name = ""
1816
var attributes: [String: String] = [:]
19-
if deviceAttributes != nil {
20-
for attr in deviceAttributes! {
17+
if let deviceAttributes {
18+
for attr in deviceAttributes {
2119
if let attrName = attr.name, let attrValue = attr.value {
2220
attributes[attrName] = attrValue
2321
}
2422
}
2523
}
26-
let device = AWSAuthDevice(id: id,
27-
name: name,
28-
attributes: attributes,
29-
createdDate: deviceCreateDate,
30-
lastAuthenticatedDate: deviceLastAuthenticatedDate,
31-
lastModifiedDate: deviceLastModifiedDate)
32-
33-
return device
24+
return AWSAuthDevice(
25+
id: deviceKey ?? "",
26+
name: attributes["device_name", default: ""],
27+
attributes: attributes,
28+
createdDate: deviceCreateDate,
29+
lastAuthenticatedDate: deviceLastAuthenticatedDate,
30+
lastModifiedDate: deviceLastModifiedDate)
3431
}
3532
}

AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/DeviceBehaviorTests/DeviceBehaviorFetchDevicesTests.swift

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,40 @@ class DeviceBehaviorFetchDevicesTests: BasePluginTest {
6969
/// - I should get a successful result with one device fetched
7070
///
7171
func testSuccessfulListDevices() async throws {
72-
72+
let dateToTest = Date()
73+
let deviceName = "test device"
74+
let deviceId = "deviceId"
7375
mockIdentityProvider = MockIdentityProvider(
7476
mockListDevicesOutput: { _ in
75-
ListDevicesOutput(devices: [CognitoIdentityProviderClientTypes.DeviceType(deviceKey: "id")], paginationToken: nil)
77+
ListDevicesOutput(
78+
devices: [
79+
CognitoIdentityProviderClientTypes.DeviceType(
80+
deviceAttributes: [
81+
.init(name: "device_name", value: deviceName)
82+
],
83+
deviceCreateDate: dateToTest,
84+
deviceKey: deviceId,
85+
deviceLastAuthenticatedDate: dateToTest,
86+
deviceLastModifiedDate: dateToTest
87+
)
88+
], paginationToken: nil)
7689
}
7790
)
7891
let listDevicesResult = try await plugin.fetchDevices()
7992
guard listDevicesResult.count == 1 else {
8093
XCTFail("Result should have device count of 1")
8194
return
8295
}
96+
guard let awsAuthDevice = listDevicesResult.first as? AWSAuthDevice else {
97+
XCTFail("Resultant device type should be AWSAuthDevice")
98+
return
99+
}
100+
XCTAssertEqual(awsAuthDevice.name, deviceName)
101+
XCTAssertEqual(awsAuthDevice.id, deviceId)
102+
XCTAssertNotEqual(awsAuthDevice.attributes?.count, 0)
103+
XCTAssertEqual(awsAuthDevice.createdDate, dateToTest)
104+
XCTAssertEqual(awsAuthDevice.lastAuthenticatedDate, dateToTest)
105+
XCTAssertEqual(awsAuthDevice.lastModifiedDate, dateToTest)
83106
}
84107

85108
/// Test a fetchDevices call with invalid response from service

AmplifyPlugins/Auth/Tests/AuthHostApp/AuthIntegrationTests/DeviceTests/AuthFetchDeviceTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,15 @@ class AuthFetchDeviceTests: AWSAuthBaseTest {
6363
let devices = try await Amplify.Auth.fetchDevices()
6464
XCTAssertNotNil(devices)
6565
XCTAssertEqual(devices.count, 1)
66+
XCTAssertEqual(devices.first?.name.isEmpty, false)
67+
XCTAssertEqual(devices.first?.id.isEmpty, false)
68+
guard let awsDevice = devices.first as? AWSAuthDevice else {
69+
XCTFail("Should be able to cast to AWSAuthDevice")
70+
return
71+
}
72+
XCTAssertEqual(awsDevice.attributes.isEmpty, false)
73+
XCTAssertNotNil(awsDevice.createdDate)
74+
XCTAssertNotNil(awsDevice.lastAuthenticatedDate)
75+
XCTAssertNotNil(awsDevice.lastModifiedDate)
6676
}
6777
}

AmplifyPlugins/Auth/Tests/AuthHostApp/AuthIntegrationTests/DeviceTests/AuthRememberDeviceTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,15 @@ class AuthRememberDeviceTests: AWSAuthBaseTest {
6060
let devices = try await Amplify.Auth.fetchDevices()
6161
XCTAssertNotNil(devices)
6262
XCTAssertGreaterThan(devices.count, 0)
63+
XCTAssertEqual(devices.first?.name.isEmpty, false)
64+
XCTAssertEqual(devices.first?.id.isEmpty, false)
65+
guard let awsDevice = devices.first as? AWSAuthDevice else {
66+
XCTFail("Should be able to cast to AWSAuthDevice")
67+
return
68+
}
69+
XCTAssertEqual(awsDevice.attributes.isEmpty, false)
70+
XCTAssertNotNil(awsDevice.createdDate)
71+
XCTAssertNotNil(awsDevice.lastAuthenticatedDate)
72+
XCTAssertNotNil(awsDevice.lastModifiedDate)
6373
}
6474
}

AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/Attempt.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Foundation
1313
/// - fail: error handler
1414
/// - Returns: optional result
1515
func attempt<T>(_ expression: @autoclosure () throws -> T,
16-
fail: @autoclosure () -> ((Swift.Error) -> Void) = { _ in }) -> T? {
16+
fail: @autoclosure () -> ((Swift.Error) -> Void)) -> T? {
1717
do {
1818
return try expression()
1919
} catch {
@@ -29,7 +29,7 @@ func attempt<T>(_ expression: @autoclosure () throws -> T,
2929
/// - Returns: success
3030
@discardableResult
3131
func attempt(_ expression: @autoclosure () throws -> Void,
32-
fail: @autoclosure () -> ((Swift.Error) -> Void) = { _ in }) -> Bool {
32+
fail: @autoclosure () -> ((Swift.Error) -> Void)) -> Bool {
3333
do {
3434
try expression()
3535
return true

AmplifyPlugins/Storage/Tests/AWSS3StoragePluginTests/Support/Internal/AttemptTests.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ class AttemptTests: XCTestCase {
4848
}
4949

5050
func testAttemptNoFailClosureNoThrow() throws {
51-
let result = attempt(try work1(number: badNumber))
51+
let result = attempt(try work1(number: badNumber),
52+
fail: { error in })
5253
XCTAssertNil(result)
5354
}
5455

5556
func testAttemptNoFailClosureThrow() throws {
56-
let result = attempt(try work2(number: badNumber))
57+
let result = attempt(try work2(number: badNumber),
58+
fail: { error in })
5759
XCTAssertEqual(false, result)
5860
}
5961

0 commit comments

Comments
 (0)