Skip to content

Commit

Permalink
Address feedback (#5)
Browse files Browse the repository at this point in the history
* chore: use testable macro

* chore: add target dependency

* chore: delete unneeded file, fix test workflow

* chore: merged build and test into one workflow

* chore: fix indentation

* chore: rename workflow

---------

Co-authored-by: Anton Yarmolenko <[email protected]>
  • Loading branch information
rnr and rnr authored Jan 21, 2025
1 parent 00fedee commit 91e343d
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will test a Swift project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift

name: Unit Tests
name: Xcode

on:
- pull_request
Expand All @@ -12,7 +12,7 @@ concurrency:

jobs:
test-ios:
name: iOS 18.1
name: Build and Test (iOS 18.1)
runs-on: macos-latest
env:
DEVELOPER_DIR: "/Applications/Xcode_16.1.app/Contents/Developer"
Expand All @@ -22,12 +22,20 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

# Run Unit Tests
# Build
- name: Build
run: |
xcodebuild build\
-scheme EDXMobileAnalytics \
-destination 'platform=iOS Simulator,name=iPhone SE (3rd generation)' \
-skipPackagePluginValidation \
-skipMacroValidation
# Run Unit Tests
- name: Run tests
run: |
xcodebuild test \
-scheme EDXMobileAnalytics \
-sdk iphonesimulator \
-destination "OS=18.1,name=iPhone 16 Pro" \
-skipPackagePluginValidation \
-skipMacroValidation
22 changes: 0 additions & 22 deletions .github/workflows/xcodebuild.yml

This file was deleted.

20 changes: 19 additions & 1 deletion Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "24865ce1a5bdb12bdf2082dc9a6b3b327986ee32238127921bf6e08f58b56e7f",
"originHash" : "aa75406ff97bf77af672c326455e75425b255f9dca089e8766327c96248e2f30",
"pins" : [
{
"identity" : "abseil-cpp-binary",
Expand Down Expand Up @@ -217,6 +217,15 @@
"version" : "1.28.2"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-syntax.git",
"state" : {
"revision" : "0687f71944021d616d34d922343dcef086855920",
"version" : "600.0.1"
}
},
{
"identity" : "swiftlintplugins",
"kind" : "remoteSourceControl",
Expand All @@ -243,6 +252,15 @@
"revision" : "be9dbcc7b86811bc131539a20c6f9c2d3e56919f",
"version" : "2.9.1"
}
},
{
"identity" : "testablemacro",
"kind" : "remoteSourceControl",
"location" : "https://github.com/fernandolucheti/TestableMacro.git",
"state" : {
"revision" : "84b111ae97f2e5cb4d84115edd0ebc145147ee00",
"version" : "0.0.2"
}
}
],
"version" : 3
Expand Down
6 changes: 4 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ let package = Package(
.package(url: "https://github.com/segmentio/analytics-swift.git", from: "1.5.3"),
.package(url: "https://github.com/segment-integrations/analytics-swift-firebase", from: "1.3.5"),
.package(url: "https://github.com/braze-inc/braze-segment-swift.git", from: "2.2.0"),
.package(url: "https://github.com/SimplyDanny/SwiftLintPlugins", from: "0.57.0")
.package(url: "https://github.com/SimplyDanny/SwiftLintPlugins", from: "0.57.0"),
.package(url: "https://github.com/fernandolucheti/TestableMacro.git", from: "0.0.2")
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
Expand All @@ -30,7 +31,8 @@ let package = Package(
.product(name: "OEXFoundation", package: "openedx-app-foundation-ios"),
.product(name: "Segment", package: "analytics-swift"),
.product(name: "SegmentFirebase", package: "analytics-swift-firebase"),
.product(name: "SegmentBraze", package: "braze-segment-swift")
.product(name: "SegmentBraze", package: "braze-segment-swift"),
.product(name: "TestableMacro", package: "TestableMacro")
],
plugins: [
.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLintPlugins")
Expand Down
2 changes: 2 additions & 0 deletions Sources/EDXMobileAnalytics/Braze/BrazeListener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

import Foundation
import OEXFoundation
import TestableMacro

@Testable
public class BrazeListener: PushNotificationsListener {

private let deepLinkManager: DeepLinkManagerProtocol
Expand Down
2 changes: 0 additions & 2 deletions Sources/EDXMobileAnalytics/EDXMobileAnalytics.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import Foundation
import OEXFoundation
@preconcurrency import Segment
import SegmentFirebase
import TestableMacro

public protocol SegmentAnalyticsServiceProtocol: AnalyticsService {
func receivedRemoteNotification(userInfo: [AnyHashable: Any])
func registeredForRemoteNotifications(deviceToken: Data)
func add(plugin: Plugin)
}

@Testable
final public class SegmentAnalyticsService: SegmentAnalyticsServiceProtocol {
private let analytics: Analytics

Expand Down
3 changes: 1 addition & 2 deletions Tests/EDXMobileAnalyticsTests/BrazeListenerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ private extension BrazeListenerTests {
@Test("Should set default value") func check1() async throws {
let deepLinkMananger = DeepLinkManagerProtocolMock()
let brazeListener = BrazeListener(deepLinkManager: deepLinkMananger)
let analyticsService = Mirror(reflecting: brazeListener)
.descendant("segmentAnalyticsService") as? SegmentAnalyticsServiceProtocol
let analyticsService = brazeListener.testHooks.segmentAnalyticsService
#expect(analyticsService == nil)
}
}
Expand Down
18 changes: 10 additions & 8 deletions Tests/EDXMobileAnalyticsTests/SegmentAnalyticsServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@ import Foundation
@Suite struct SegmentAnalyticsServiceTests {
@Suite(".init") struct InitTest {
@Test("When addFirebaseAnalytics is false shouldn't add plugin") func check1() async throws {
let writeKey = UUID().uuidString
let analyticsService = SegmentAnalyticsService(
writeKey: UUID().uuidString,
writeKey: writeKey,
addFirebaseAnalytics: false
)
let analytics = Mirror(reflecting: analyticsService).descendant("analytics") as? Analytics
#expect(analytics != nil)
#expect(analytics?.find(pluginType: FirebaseDestination.self) == nil)
let analytics = analyticsService.testHooks.analytics
#expect(analytics.writeKey == writeKey)
#expect(analytics.find(pluginType: FirebaseDestination.self) == nil)
}

@Test("When addFirebaseAnalytics is true should add plugin") func check2() async throws {
let writeKey = UUID().uuidString
let analyticsService = SegmentAnalyticsService(
writeKey: UUID().uuidString,
writeKey: writeKey,
addFirebaseAnalytics: true
)
let analytics = Mirror(reflecting: analyticsService).descendant("analytics") as? Analytics
#expect(analytics != nil)
#expect(analytics?.find(pluginType: FirebaseDestination.self) != nil)
let analytics = analyticsService.testHooks.analytics
#expect(analytics.writeKey == writeKey)
#expect(analytics.find(pluginType: FirebaseDestination.self) != nil)
}
}
}

0 comments on commit 91e343d

Please sign in to comment.