diff --git a/Sources/EmbraceConfigInternal/NetworkPayloadCaptureRule.swift b/Sources/EmbraceConfigInternal/NetworkPayloadCaptureRule.swift index 79ceaa90..021ec9b0 100644 --- a/Sources/EmbraceConfigInternal/NetworkPayloadCaptureRule.swift +++ b/Sources/EmbraceConfigInternal/NetworkPayloadCaptureRule.swift @@ -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]? @@ -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" @@ -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 } diff --git a/Tests/EmbraceConfigInternalTests/EmbraceConfigurable/RemoteConfigTests.swift b/Tests/EmbraceConfigInternalTests/EmbraceConfigurable/RemoteConfigTests.swift index 4a826b7d..623884bf 100644 --- a/Tests/EmbraceConfigInternalTests/EmbraceConfigurable/RemoteConfigTests.swift +++ b/Tests/EmbraceConfigInternalTests/EmbraceConfigurable/RemoteConfigTests.swift @@ -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]) + } }