Skip to content

Commit

Permalink
Updates RemoteConfigTests with addition of NetworkPayloadCaptureRule
Browse files Browse the repository at this point in the history
  • Loading branch information
atreat committed Sep 6, 2024
1 parent c7e7797 commit 2451abc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
22 changes: 20 additions & 2 deletions Sources/EmbraceConfigInternal/NetworkPayloadCaptureRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import Foundation

@objc
public class NetworkPayloadCaptureRule: NSObject, Decodable {
public final class NetworkPayloadCaptureRule: NSObject {
public let id: String
public let urlRegex: String
public let statusCodes: [Int]?
Expand All @@ -17,6 +17,24 @@ public class NetworkPayloadCaptureRule: NSObject, Decodable {
return Date(timeIntervalSince1970: expiration)
}

init(
id: String,
urlRegex: String,
statusCodes: [Int]?,
methods: [String]?,
expiration: Double,
publicKey: String
) {
self.id = id
self.urlRegex = urlRegex
self.statusCodes = statusCodes
self.methods = methods
self.expiration = expiration
self.publicKey = publicKey
}
}

extension NetworkPayloadCaptureRule: Decodable {
enum CodingKeys: String, CodingKey {
case id
case urlRegex = "url"
Expand All @@ -27,7 +45,7 @@ public class NetworkPayloadCaptureRule: NSObject, Decodable {
}
}

extension NetworkPayloadCaptureRule {
extension NetworkPayloadCaptureRule /* Equatable */ {
public static func == (lhs: NetworkPayloadCaptureRule, rhs: NetworkPayloadCaptureRule) -> Bool {
lhs.id == rhs.id
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,30 @@ final class RemoteConfigTests: XCTestCase {
InternalLogLimits(trace: 10, debug: 20, info: 30, warning: 40, error: 50)
)
}

func test_networkPayloadCaptureRules() {
// given a config
let config = RemoteConfig(fetcher: fetcher, deviceIdHexValue: 128, deviceIdUsedDigits: 2)

let rule1 = NetworkPayloadCaptureRule(
id: "test1",
urlRegex: "https://example.com/.*",
statusCodes: [200],
methods: ["GET"],
expiration: 0,
publicKey: ""
)

let rule2 = NetworkPayloadCaptureRule(
id: "test2",
urlRegex: "https://test.com/.*",
statusCodes: [404],
methods: ["GET"],
expiration: 0,
publicKey: ""
)

config.payload.networkPayloadCaptureRules = [rule1, rule2]
XCTAssertEqual(config.networkPayloadCaptureRules, [rule1, rule2])
}
}

0 comments on commit 2451abc

Please sign in to comment.