From b6e0d36492f4a9541183d629f434263b2b4c6d76 Mon Sep 17 00:00:00 2001 From: "leojoseph.r" <58416454+rleojoseph@users.noreply.github.com> Date: Wed, 2 Aug 2023 15:21:58 +0900 Subject: [PATCH] [MINI-6243] Refactor to use constants (#522) * Refactor to use constants * Codecov fix --- .circleci/config.yml | 9 --------- .github/workflows/fastlane.yml | 4 ++++ Example/AppDelegate.swift | 2 +- .../SwiftUI/Features/Bundle/MiniAppFromBundle.swift | 9 +++++---- .../SwiftUI/Features/MiniAppFeatureListView.swift | 3 ++- .../SwiftUI/Features/Single/MiniAppSingleView.swift | 2 +- Example/Utils/Global.swift | 8 ++++++++ Sample.xcodeproj/project.pbxproj | 4 ++++ .../CustomPermissionsRequestViewController.swift | 2 +- Sources/Classes/core/Extensions/Bundle+Environment.swift | 2 +- Sources/Classes/core/Utilities/Constants.swift | 4 ++++ Sources/Classes/core/View/MiniAppView.swift | 2 +- Sources/Classes/core/View/MiniAppViewHandler.swift | 4 ++-- Tests/Unit/MiniAppViewTests.swift | 2 +- 14 files changed, 35 insertions(+), 22 deletions(-) create mode 100644 Example/Utils/Global.swift diff --git a/.circleci/config.yml b/.circleci/config.yml index 5dd22027..fc33fbf0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,7 +7,6 @@ orbs: gh: circleci/github-cli@1.0.4 macos: circleci/macos@2 ruby: circleci/ruby@1.2.0 - codecov: codecov/codecov@3.1.1 app-center: rakutentech/app-center@0.1.3 container_medium: &container_medium @@ -37,8 +36,6 @@ jobs: - run: name: Execute Tests command: fastlane ci - - store_artifacts: - path: ./artifacts/unit-tests - persist_to_workspace: root: . paths: @@ -47,12 +44,6 @@ jobs: root: ../ paths: - MiniApp-Secrets.xcconfig - - codecov/upload: - file: "artifacts/unit-tests/report.junit" - - codecov/upload: - file: "artifacts/unit-tests/report.html" - - codecov/upload: - file: "artifacts/unit-tests/compile_commands.json" app-center-publish-sim: <<: *container_medium diff --git a/.github/workflows/fastlane.yml b/.github/workflows/fastlane.yml index 94e9a6a0..90e4d7be 100644 --- a/.github/workflows/fastlane.yml +++ b/.github/workflows/fastlane.yml @@ -1,6 +1,10 @@ name: Build and Test using Fastlane on: + push: + branches: + - master + - candidate pull_request: jobs: diff --git a/Example/AppDelegate.swift b/Example/AppDelegate.swift index 2d301669..21dce6eb 100644 --- a/Example/AppDelegate.swift +++ b/Example/AppDelegate.swift @@ -13,7 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { MiniApp.configure() - MiniApp.unzipMiniApp(fileName: "js-miniapp-sample", miniAppId: "mini-app-testing-appid", versionId: "mini-app-testing-versionid") + MiniApp.unzipMiniApp(fileName: "js-miniapp-sample", miniAppId: Global.DemoApp.bundleMiniAppId, versionId: Global.DemoApp.bundleMiniAppVersionId) AppCenter.start(withAppSecret: Bundle.main.value(for: "AppCenterSecret"), services: [Crashes.self]) GADMobileAds.sharedInstance().start(completionHandler: nil) diff --git a/Example/Controllers/SwiftUI/Features/Bundle/MiniAppFromBundle.swift b/Example/Controllers/SwiftUI/Features/Bundle/MiniAppFromBundle.swift index b1d9a1c1..37d142d4 100644 --- a/Example/Controllers/SwiftUI/Features/Bundle/MiniAppFromBundle.swift +++ b/Example/Controllers/SwiftUI/Features/Bundle/MiniAppFromBundle.swift @@ -9,7 +9,7 @@ struct MiniAppFromBundle: View { VStack { MiniAppSUIView(params: miniAppViewParams(config: ListConfiguration(listType: .listI).sdkConfig), fromCache: true, handler: MiniAppSUIViewHandler(), fromBundle: true) } - .navigationTitle("MiniApp") + .navigationTitle(MiniAppSDKConstants.miniAppRootFolderName) } func miniAppViewParams(config: MiniAppSdkConfig) -> MiniAppViewParameters.DefaultParams { @@ -17,12 +17,13 @@ struct MiniAppFromBundle: View { config: MiniAppConfig( config: config, adsDisplayer: AdMobDisplayer(), - messageDelegate: MiniAppViewMessageDelegator(), + messageDelegate: MiniAppViewMessageDelegator(miniAppId: Global.DemoApp.bundleMiniAppId, + miniAppVersion: Global.DemoApp.bundleMiniAppVersionId), navigationDelegate: MiniAppViewNavigationDelegator() ), type: .miniapp, - appId: "mini-app-testing-appid", - version: "mini-app-testing-versionid", + appId: Global.DemoApp.bundleMiniAppId, + version: Global.DemoApp.bundleMiniAppVersionId, queryParams: getQueryParam() ) } diff --git a/Example/Controllers/SwiftUI/Features/MiniAppFeatureListView.swift b/Example/Controllers/SwiftUI/Features/MiniAppFeatureListView.swift index febca30e..f5502765 100644 --- a/Example/Controllers/SwiftUI/Features/MiniAppFeatureListView.swift +++ b/Example/Controllers/SwiftUI/Features/MiniAppFeatureListView.swift @@ -1,5 +1,6 @@ import SwiftUI import Combine +import MiniApp struct MiniAppFeatureListView: View { @@ -17,7 +18,7 @@ struct MiniAppFeatureListView: View { }) NavigationLink(destination: MiniAppFromBundle(), label: { MiniAppFeatureListCell( - title: "Miniapp", + title: MiniAppSDKConstants.miniAppRootFolderName, subTitle: "Open a miniapp from Bundle", active: true ) diff --git a/Example/Controllers/SwiftUI/Features/Single/MiniAppSingleView.swift b/Example/Controllers/SwiftUI/Features/Single/MiniAppSingleView.swift index 11e91557..30875621 100644 --- a/Example/Controllers/SwiftUI/Features/Single/MiniAppSingleView.swift +++ b/Example/Controllers/SwiftUI/Features/Single/MiniAppSingleView.swift @@ -42,7 +42,7 @@ struct MiniAppSingleView: View { VStack { MiniAppWithTermsView(viewModel: viewModel, handler: handler) } - .navigationTitle(handler.isActive ? handler.miniAppTitle?() ?? "MiniApp" : "MiniApp") + .navigationTitle(handler.isActive ? handler.miniAppTitle?() ?? MiniAppSDKConstants.miniAppRootFolderName : MiniAppSDKConstants.miniAppRootFolderName) .navigationBarTitleDisplayMode(.inline) .navigationBarBackButtonHidden(true) .toolbar(content: { diff --git a/Example/Utils/Global.swift b/Example/Utils/Global.swift new file mode 100644 index 00000000..bcce6365 --- /dev/null +++ b/Example/Utils/Global.swift @@ -0,0 +1,8 @@ +import Foundation + +struct Global { + struct DemoApp { + static let bundleMiniAppId = "mini-app-testing-appid" + static let bundleMiniAppVersionId = "mini-app-testing-versionid" + } +} diff --git a/Sample.xcodeproj/project.pbxproj b/Sample.xcodeproj/project.pbxproj index 7e4d0e85..bf1b10f6 100644 --- a/Sample.xcodeproj/project.pbxproj +++ b/Sample.xcodeproj/project.pbxproj @@ -22,6 +22,7 @@ 1CD1591829421FDF001E0E21 /* UniversalBridgeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CD1591729421FDF001E0E21 /* UniversalBridgeView.swift */; }; 2A52E3C12A42EFAC00DC8EFE /* js-miniapp-sample.zip in Resources */ = {isa = PBXBuildFile; fileRef = 2A52E3C02A42EFAC00DC8EFE /* js-miniapp-sample.zip */; }; 2A52E3C42A42F0F100DC8EFE /* MiniAppFromBundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A52E3C32A42F0F100DC8EFE /* MiniAppFromBundle.swift */; }; + 2A708B452A79F2C900E4E1BF /* Global.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A708B442A79F2C900E4E1BF /* Global.swift */; }; 2AB1B0A226A6CDEF004CAC1B /* MASDKLocaleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AB1B0A126A6CDEF004CAC1B /* MASDKLocaleTests.swift */; }; 2AB1B0E326A6D7DA004CAC1B /* MiniAppExternalWebViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AB1B0D926A6D7B4004CAC1B /* MiniAppExternalWebViewControllerTests.swift */; }; 2AB1B0E926A6D7F3004CAC1B /* CustomPermissionsViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AB1B0E826A6D7F3004CAC1B /* CustomPermissionsViewControllerTests.swift */; }; @@ -160,6 +161,7 @@ 1CD1591729421FDF001E0E21 /* UniversalBridgeView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UniversalBridgeView.swift; sourceTree = ""; }; 2A52E3C02A42EFAC00DC8EFE /* js-miniapp-sample.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = "js-miniapp-sample.zip"; sourceTree = ""; }; 2A52E3C32A42F0F100DC8EFE /* MiniAppFromBundle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MiniAppFromBundle.swift; sourceTree = ""; }; + 2A708B442A79F2C900E4E1BF /* Global.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Global.swift; sourceTree = ""; }; 2AB1B0A126A6CDEF004CAC1B /* MASDKLocaleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MASDKLocaleTests.swift; sourceTree = ""; }; 2AB1B0D926A6D7B4004CAC1B /* MiniAppExternalWebViewControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MiniAppExternalWebViewControllerTests.swift; sourceTree = ""; }; 2AB1B0E826A6D7F3004CAC1B /* CustomPermissionsViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomPermissionsViewControllerTests.swift; sourceTree = ""; }; @@ -435,6 +437,7 @@ 3857ED7D25DEE0690083F3E1 /* Bundle+MiniApp.swift */, 31850BC0269837F300CFE422 /* UIColor+MiniApp.swift */, D0CACE25281A68D700E39920 /* Base64UriHelper.swift */, + 2A708B442A79F2C900E4E1BF /* Global.swift */, ); path = Utils; sourceTree = ""; @@ -893,6 +896,7 @@ 38920AF2251D9C57004C5DDD /* ImageCache.swift in Sources */, F70DD8EF28D417C4003EF1F1 /* MiniAppSettingsGeneralView.swift in Sources */, F70DD8FD28D417C4003EF1F1 /* MiniAppListView.swift in Sources */, + 2A708B452A79F2C900E4E1BF /* Global.swift in Sources */, F70DD90628D417C4003EF1F1 /* LocationManager.swift in Sources */, A13C249826A15048003ADC6D /* UserPointsModel.swift in Sources */, F70DD8E728D417C4003EF1F1 /* MiniAppDashboardView.swift in Sources */, diff --git a/Sources/Classes/core/Display/ViewControllers/Custom Permissions/CustomPermissionsRequestViewController.swift b/Sources/Classes/core/Display/ViewControllers/Custom Permissions/CustomPermissionsRequestViewController.swift index 6295fd7a..733c574c 100644 --- a/Sources/Classes/core/Display/ViewControllers/Custom Permissions/CustomPermissionsRequestViewController.swift +++ b/Sources/Classes/core/Display/ViewControllers/Custom Permissions/CustomPermissionsRequestViewController.swift @@ -11,7 +11,7 @@ class CustomPermissionsRequestViewController: UIViewController { var customPermissionHandlerObj: CustomPermissionsCompletionHandler? var permissionsRequestList: [MASDKCustomPermissionModel]? - var miniAppTitle: String = "MiniApp" + var miniAppTitle: String = MiniAppSDKConstants.miniAppRootFolderName override func viewDidLoad() { super.viewDidLoad() diff --git a/Sources/Classes/core/Extensions/Bundle+Environment.swift b/Sources/Classes/core/Extensions/Bundle+Environment.swift index 306afa21..b631a575 100644 --- a/Sources/Classes/core/Extensions/Bundle+Environment.swift +++ b/Sources/Classes/core/Extensions/Bundle+Environment.swift @@ -39,7 +39,7 @@ extension Bundle { } public class var miniAppSDKBundle: Bundle { - miniAppBundle("MiniApp") + miniAppBundle(MiniAppSDKConstants.miniAppRootFolderName) } class var miniAppLocalizationBundle: Bundle { diff --git a/Sources/Classes/core/Utilities/Constants.swift b/Sources/Classes/core/Utilities/Constants.swift index 71b1e3cd..065dfd6e 100644 --- a/Sources/Classes/core/Utilities/Constants.swift +++ b/Sources/Classes/core/Utilities/Constants.swift @@ -17,3 +17,7 @@ enum Constants { public typealias MASDKDownloadedListPermissionsPair = [(MiniAppInfo, [MASDKCustomPermissionModel])] let offlineErrorCodeList: [Int] = [NSURLErrorNotConnectedToInternet, NSURLErrorTimedOut, NSURLErrorDataNotAllowed] + +public struct MiniAppSDKConstants { + public static let miniAppRootFolderName = "MiniApp" +} diff --git a/Sources/Classes/core/View/MiniAppView.swift b/Sources/Classes/core/View/MiniAppView.swift index 243a2768..068245a0 100644 --- a/Sources/Classes/core/View/MiniAppView.swift +++ b/Sources/Classes/core/View/MiniAppView.swift @@ -187,7 +187,7 @@ public class MiniAppView: UIView, MiniAppViewable { } public var miniAppTitle: String { - return miniAppHandler.title.isEmpty ? "MiniApp" : miniAppHandler.title + return miniAppHandler.title.isEmpty ? MiniAppSDKConstants.miniAppRootFolderName : miniAppHandler.title } public enum MiniAppLoadStatus { diff --git a/Sources/Classes/core/View/MiniAppViewHandler.swift b/Sources/Classes/core/View/MiniAppViewHandler.swift index d05bdf78..e6357b09 100644 --- a/Sources/Classes/core/View/MiniAppViewHandler.swift +++ b/Sources/Classes/core/View/MiniAppViewHandler.swift @@ -196,7 +196,7 @@ class MiniAppViewHandler: NSObject { } switch result { case .success(let info): - let miniAppTitle = info.displayName ?? "MiniApp" + let miniAppTitle = info.displayName ?? MiniAppSDKConstants.miniAppRootFolderName self.title = miniAppTitle self.downloadMiniApp(appInfo: info, queryParams: self.queryParams) { result in switch result { @@ -330,7 +330,7 @@ class MiniAppViewHandler: NSObject { func loadWebView( webView: MiniAppWebView, - miniAppTitle: String = "MiniApp", + miniAppTitle: String = MiniAppSDKConstants.miniAppRootFolderName, miniAppId: String, versionId: String, queryParams: String? = nil, diff --git a/Tests/Unit/MiniAppViewTests.swift b/Tests/Unit/MiniAppViewTests.swift index 322d3b54..f9396491 100644 --- a/Tests/Unit/MiniAppViewTests.swift +++ b/Tests/Unit/MiniAppViewTests.swift @@ -245,7 +245,7 @@ class MiniAppViewTests: XCTestCase { ) ) let view = MiniAppView(params: params) - XCTAssertEqual(view.miniAppTitle, "MiniApp") + XCTAssertEqual(view.miniAppTitle, MiniAppSDKConstants.miniAppRootFolderName) view.miniAppHandler.title = "MiniApp (Test)" XCTAssertEqual(view.miniAppTitle, "MiniApp (Test)")