Skip to content

Commit

Permalink
updated swiftformat rules
Browse files Browse the repository at this point in the history
  • Loading branch information
phantumcode committed Sep 9, 2024
1 parent cfa8421 commit 0af759d
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,20 @@ public extension AWSPinpointPushNotificationsPlugin {
if let userProfile {
currentEndpointProfile.addUserProfile(userProfile)
}
try await pinpoint.updateEndpoint(with: currentEndpointProfile,
source: .pushNotifications)
try await pinpoint.updateEndpoint(
with: currentEndpointProfile,
source: .pushNotifications
)
}

func registerDevice(apnsToken: Data) async throws {
var currentEndpointProfile = await pinpoint.currentEndpointProfile()
currentEndpointProfile.setAPNsToken(apnsToken)
do {
try await pinpoint.updateEndpoint(with: currentEndpointProfile,
source: .pushNotifications)
try await pinpoint.updateEndpoint(
with: currentEndpointProfile,
source: .pushNotifications
)
} catch {
throw error.pushNotificationsError
}
Expand Down Expand Up @@ -67,10 +71,11 @@ public extension AWSPinpointPushNotificationsPlugin {
pinpoint.pinpointClient
}

private func recordNotification(_ userInfo: [String: Any],
applicationState: ApplicationState,
action: PushNotification.Action) async
{
private func recordNotification(
_ userInfo: [String: Any],
applicationState: ApplicationState,
action: PushNotification.Action
) async {
let userInfo: PushNotification.UserInfo = Dictionary(uniqueKeysWithValues: userInfo.map {($0, $1)})
await recordNotification(
userInfo,
Expand All @@ -79,10 +84,11 @@ public extension AWSPinpointPushNotificationsPlugin {
)
}

private func recordNotification(_ userInfo: PushNotification.UserInfo,
applicationState: ApplicationState,
action: PushNotification.Action) async
{
private func recordNotification(
_ userInfo: PushNotification.UserInfo,
applicationState: ApplicationState,
action: PushNotification.Action
) async {
// Retrieve the payload from the notification
guard let payload = userInfo.payload else {
log.error(
Expand All @@ -101,8 +107,10 @@ public extension AWSPinpointPushNotificationsPlugin {

// Add application state
let applicationStateAttribute = applicationState.pinpointAttribute
pushNotificationEvent.addAttribute(applicationStateAttribute.value,
forKey: applicationStateAttribute.key)
pushNotificationEvent.addAttribute(
applicationStateAttribute.value,
forKey: applicationStateAttribute.key
)

// Set global remote attributes
await pinpoint.setRemoteGlobalAttributes(payload.attributes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ extension AWSPinpointPushNotificationsPlugin {

pluginConfiguration = AWSPinpointPluginConfiguration(
appId: notifications.amazonPinpointAppId,
region: notifications.awsRegion)
region: notifications.awsRegion
)
} else if let config = configuration as? JSONValue {
pluginConfiguration = try AWSPinpointPluginConfiguration(config)
} else {
Expand All @@ -51,8 +52,10 @@ extension AWSPinpointPushNotificationsPlugin {
region: configuration.region
)

configure(pinpoint: pinpoint,
remoteNotificationsHelper: .default)
configure(
pinpoint: pinpoint,
remoteNotificationsHelper: .default
)
}

private func requestNotificationsPermissions(using helper: RemoteNotificationsBehaviour) async {
Expand All @@ -70,9 +73,10 @@ extension AWSPinpointPushNotificationsPlugin {

// MARK: Internal
/// Internal configure method to set the properties of the plugin
func configure(pinpoint: AWSPinpointBehavior,
remoteNotificationsHelper: RemoteNotificationsBehaviour)
{
func configure(
pinpoint: AWSPinpointBehavior,
remoteNotificationsHelper: RemoteNotificationsBehaviour
) {
self.pinpoint = pinpoint
Task {
await remoteNotificationsHelper.registerForRemoteNotifications()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ extension PushNotification.UserInfo {

var deeplinkUrl: URL? {
if let urlString = root?[Constants.Keys.deeplink] as? String,
let deeplinkUrl = URL(string: urlString)
{
let deeplinkUrl = URL(string: urlString) {
return deeplinkUrl
}
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import XCTest
class AWSPinpointPushNotificationsPluginClientBehaviourTests: AWSPinpointPushNotificationsPluginTestBase {
override func setUp() async throws {
try await super.setUp()
plugin.configure(pinpoint: mockPinpoint,
remoteNotificationsHelper: mockRemoteNotifications)
plugin.configure(
pinpoint: mockPinpoint,
remoteNotificationsHelper: mockRemoteNotifications
)
}

// MARK: - Identify User tests
Expand Down Expand Up @@ -254,9 +256,11 @@ class AWSPinpointPushNotificationsPluginClientBehaviourTests: AWSPinpointPushNot
case "notification":
return UNNotification(coder: self) as Any
case "request":
return UNNotificationRequest(identifier: "identifier",
content: UNNotificationContent(coder: self)!,
trigger: nil)
return UNNotificationRequest(
identifier: "identifier",
content: UNNotificationContent(coder: self)!,
trigger: nil
)
case "userInfo":
return userInfo
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class AWSPinpointPushNotificationsPluginConfigureTests: AWSPinpointPushNotificat
let pinpointConfiguration = JSONValue(
dictionaryLiteral:
(AWSPinpointPluginConfiguration.appIdConfigKey, appId),
(AWSPinpointPluginConfiguration.regionConfigKey, region)
(AWSPinpointPluginConfiguration.regionConfigKey, region)
)

return pinpointConfiguration
Expand All @@ -188,6 +188,7 @@ class AWSPinpointPushNotificationsPluginConfigureTests: AWSPinpointPushNotificat
.init(notifications: .init(
awsRegion: testRegion,
amazonPinpointAppId: testAppId,
channels: [.apns]))
channels: [.apns]
))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ extension ErrorPushNotificationsTests {
/// Then: A .unknown error is returned
func testPushNotificationError_withUnknownAWSHTTPServiceError_shouldReturnUnknownError() {
let error = UnknownAWSHTTPServiceError(
httpResponse: .init(body: .empty, statusCode: .accepted), message: "UnknownAWSHTTPServiceError", requestID: nil, typeName: nil)
httpResponse: .init(body: .empty, statusCode: .accepted), message: "UnknownAWSHTTPServiceError", requestID: nil, typeName: nil
)
let pushNotificationsError = error.pushNotificationsError
switch pushNotificationsError {
case .unknown(let errorDescription, let underlyingError):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ class MockAWSPinpoint: AWSPinpointBehavior {

var updateEndpointCount = 0
var updatedPinpointEndpointProfile: PinpointEndpointProfile?
func updateEndpoint(with endpointProfile: PinpointEndpointProfile,
source: AWSPinpointSource) async throws
{
func updateEndpoint(
with endpointProfile: PinpointEndpointProfile,
source: AWSPinpointSource
) async throws {
updateEndpointCount += 1
updatedPinpointEndpointProfile = endpointProfile
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ final class PushNotificationHostAppUITests: XCTestCase {

let firstAlert = firstAlertElement()
if !firstAlert.waitForExistence(timeout: timeout) ||
!anyElementContains(text: "Identified User", scope: firstAlert).waitForExistence(timeout: timeout)
{
!anyElementContains(text: "Identified User", scope: firstAlert).waitForExistence(timeout: timeout) {
XCTFail("Failed to identify user")
}
}
Expand All @@ -102,8 +101,7 @@ final class PushNotificationHostAppUITests: XCTestCase {

let firstAlert = firstAlertElement()
if !firstAlert.waitForExistence(timeout: timeout) ||
!anyElementContains(text: "Registered Device", scope: firstAlert).waitForExistence(timeout: timeout)
{
!anyElementContains(text: "Registered Device", scope: firstAlert).waitForExistence(timeout: timeout) {
XCTFail("Failed to register device")
}
}
Expand Down

0 comments on commit 0af759d

Please sign in to comment.