From dd4e995a1831f3b29992fd1ecf2f2e1f8828f2ed Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki <dariusz@elixxir.io> Date: Wed, 7 Sep 2022 22:40:40 +0200 Subject: [PATCH 01/10] Add FactHelpers --- .../XXMessengerClient/Utils/FactHelpers.swift | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Sources/XXMessengerClient/Utils/FactHelpers.swift diff --git a/Sources/XXMessengerClient/Utils/FactHelpers.swift b/Sources/XXMessengerClient/Utils/FactHelpers.swift new file mode 100644 index 00000000..b948f2eb --- /dev/null +++ b/Sources/XXMessengerClient/Utils/FactHelpers.swift @@ -0,0 +1,36 @@ +import XXClient + +extension Array where Element == Fact { + public var username: String? { + get { first(where: { $0.type == 0 })?.fact } + set { + removeAll(where: { $0.type == 0 }) + if let newValue = newValue { + append(Fact(fact: newValue, type: 0)) + sort(by: { $0.type < $1.type }) + } + } + } + + public var email: String? { + get { first(where: { $0.type == 1 })?.fact } + set { + removeAll(where: { $0.type == 1 }) + if let newValue = newValue { + append(Fact(fact: newValue, type: 1)) + sort(by: { $0.type < $1.type }) + } + } + } + + public var phone: String? { + get { first(where: { $0.type == 2 })?.fact } + set { + removeAll(where: { $0.type == 2 }) + if let newValue = newValue { + append(Fact(fact: newValue, type: 2)) + sort(by: { $0.type < $1.type }) + } + } + } +} -- GitLab From 6a4c64eebb3fe93fe011a4ae7414533ecd80431b Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki <dariusz@elixxir.io> Date: Wed, 7 Sep 2022 23:50:23 +0200 Subject: [PATCH 02/10] Add FactType model --- Sources/XXClient/Models/FactType.swift | 39 ++++++++++++++++ .../XXClientTests/Models/FactTypeTests.swift | 44 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 Sources/XXClient/Models/FactType.swift create mode 100644 Tests/XXClientTests/Models/FactTypeTests.swift diff --git a/Sources/XXClient/Models/FactType.swift b/Sources/XXClient/Models/FactType.swift new file mode 100644 index 00000000..96caa0ff --- /dev/null +++ b/Sources/XXClient/Models/FactType.swift @@ -0,0 +1,39 @@ +import Foundation + +public enum FactType: Equatable { + case username + case email + case phone + case other(Int) + + public static let knownTypes: [FactType] = [.username, .email, .phone] + + public init(rawValue: Int) { + if let known = FactType.knownTypes.first(where: { $0.rawValue == rawValue }) { + self = known + } else { + self = .other(rawValue) + } + } + + public var rawValue: Int { + switch self { + case .username: return 0 + case .email: return 1 + case .phone: return 2 + case .other(let rawValue): return rawValue + } + } +} + +extension FactType: Codable { + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + self.init(rawValue: try container.decode(Int.self)) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(rawValue) + } +} diff --git a/Tests/XXClientTests/Models/FactTypeTests.swift b/Tests/XXClientTests/Models/FactTypeTests.swift new file mode 100644 index 00000000..f8c3347b --- /dev/null +++ b/Tests/XXClientTests/Models/FactTypeTests.swift @@ -0,0 +1,44 @@ +import CustomDump +import Foundation +import XCTest +@testable import XXClient + +final class FactTypeTests: XCTestCase { + func testDecoding() throws { + let decoder = Foundation.JSONDecoder() + + XCTAssertNoDifference( + [ + try decoder.decode(FactType.self, from: "0".data(using: .utf8)!), + try decoder.decode(FactType.self, from: "1".data(using: .utf8)!), + try decoder.decode(FactType.self, from: "2".data(using: .utf8)!), + try decoder.decode(FactType.self, from: "3".data(using: .utf8)!), + ], + [ + FactType.username, + FactType.email, + FactType.phone, + FactType.other(3), + ] + ) + } + + func testEncoding() throws { + let encoder = Foundation.JSONEncoder() + + XCTAssertNoDifference( + [ + try encoder.encode(FactType.username), + try encoder.encode(FactType.email), + try encoder.encode(FactType.phone), + try encoder.encode(FactType.other(3)), + ], + [ + "0".data(using: .utf8)!, + "1".data(using: .utf8)!, + "2".data(using: .utf8)!, + "3".data(using: .utf8)!, + ] + ) + } +} -- GitLab From f538f821e09ae8ede47f6a10bfc211ea1782fd43 Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki <dariusz@elixxir.io> Date: Wed, 7 Sep 2022 23:56:10 +0200 Subject: [PATCH 03/10] Add convenient getter & setter to Fact array --- Sources/XXClient/Models/Fact.swift | 14 +++++++ Tests/XXClientTests/Models/FactTests.swift | 45 ++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/Sources/XXClient/Models/Fact.swift b/Sources/XXClient/Models/Fact.swift index 2ee8a6b3..f239a86d 100644 --- a/Sources/XXClient/Models/Fact.swift +++ b/Sources/XXClient/Models/Fact.swift @@ -43,3 +43,17 @@ extension Array where Element == Fact { return try JSONEncoder().encode(self) } } + +extension Array where Element == Fact { + public func get(_ type: FactType) -> Fact? { + first(where: { $0.type == type.rawValue }) + } + + public mutating func set(_ type: FactType, _ value: String?) { + removeAll(where: { $0.type == type.rawValue }) + if let value = value { + append(Fact(fact: value, type: type.rawValue)) + sort(by: { $0.type < $1.type }) + } + } +} diff --git a/Tests/XXClientTests/Models/FactTests.swift b/Tests/XXClientTests/Models/FactTests.swift index c844af66..0e777e7d 100644 --- a/Tests/XXClientTests/Models/FactTests.swift +++ b/Tests/XXClientTests/Models/FactTests.swift @@ -51,4 +51,49 @@ final class FactTests: XCTestCase { XCTAssertNoDifference(encodedModels, jsonData) } + + func testArrayGetter() { + let facts = [ + Fact(fact: "username", type: 0), + Fact(fact: "email", type: 1), + Fact(fact: "phone", type: 2), + Fact(fact: "other", type: 3), + ] + + XCTAssertNoDifference( + [ + facts.get(.username), + facts.get(.email), + facts.get(.phone), + facts.get(.other(3)), + facts.get(.other(4)), + ], + [ + Fact(fact: "username", type: 0), + Fact(fact: "email", type: 1), + Fact(fact: "phone", type: 2), + Fact(fact: "other", type: 3), + nil + ] + ) + } + + func testArraySetter() { + var facts: [Fact] = [] + + facts.set(.email, "email") + facts.set(.phone, "phone") + facts.set(.other(3), "other") + facts.set(.username, "username") + + XCTAssertNoDifference( + facts, + [ + Fact(fact: "username", type: 0), + Fact(fact: "email", type: 1), + Fact(fact: "phone", type: 2), + Fact(fact: "other", type: 3), + ] + ) + } } -- GitLab From 593d5f1073f77d4fc5b6a8ea811452b8553cffe6 Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki <dariusz@elixxir.io> Date: Thu, 8 Sep 2022 00:04:30 +0200 Subject: [PATCH 04/10] Add convenient fact getter and setter to Contact --- Sources/XXClient/Models/Contact.swift | 12 ++++ Tests/XXClientTests/Models/ContactTests.swift | 61 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 Tests/XXClientTests/Models/ContactTests.swift diff --git a/Sources/XXClient/Models/Contact.swift b/Sources/XXClient/Models/Contact.swift index 03e08f2a..6bc9b769 100644 --- a/Sources/XXClient/Models/Contact.swift +++ b/Sources/XXClient/Models/Contact.swift @@ -44,6 +44,18 @@ extension Contact: Equatable { } } +extension Contact { + public func getFact(_ type: FactType) throws -> Fact? { + try getFacts().get(type) + } + + public mutating func setFact(_ type: FactType, _ value: String?) throws { + var facts = try getFacts() + facts.set(type, value) + try setFacts(facts) + } +} + extension Contact { public static func live( _ data: Data, diff --git a/Tests/XXClientTests/Models/ContactTests.swift b/Tests/XXClientTests/Models/ContactTests.swift new file mode 100644 index 00000000..8347e0dc --- /dev/null +++ b/Tests/XXClientTests/Models/ContactTests.swift @@ -0,0 +1,61 @@ +import CustomDump +import XCTest +@testable import XXClient + +final class ContactTests: XCTestCase { + func testGetFact() throws { + var contact = Contact.unimplemented("contact-data".data(using: .utf8)!) + contact.getFactsFromContact.run = { _ in + [ + Fact(fact: "username", type: 0), + Fact(fact: "email", type: 1), + Fact(fact: "phone", type: 2), + Fact(fact: "other", type: 3), + ] + } + + XCTAssertNoDifference( + [ + try contact.getFact(.username), + try contact.getFact(.email), + try contact.getFact(.phone), + try contact.getFact(.other(3)), + try contact.getFact(.other(4)), + ], + [ + Fact(fact: "username", type: 0), + Fact(fact: "email", type: 1), + Fact(fact: "phone", type: 2), + Fact(fact: "other", type: 3), + nil + ] + ) + } + + func testSetFact() throws { + var contact = Contact.unimplemented("contact-data".data(using: .utf8)!) + var facts: [Fact] = [ + Fact(fact: "username", type: 0), + Fact(fact: "email", type: 1), + Fact(fact: "phone", type: 2), + Fact(fact: "other-3", type: 3), + ] + contact.getFactsFromContact.run = { _ in facts } + contact.setFactsOnContact.run = { data, newFacts in + facts = newFacts + return data + } + + try contact.setFact(.username, "new-username") + try contact.setFact(.other(4), "new-other-4") + try contact.setFact(.other(3), "new-other-3") + try contact.setFact(.email, nil) + + XCTAssertNoDifference(facts, [ + Fact(fact: "new-username", type: 0), + Fact(fact: "phone", type: 2), + Fact(fact: "new-other-3", type: 3), + Fact(fact: "new-other-4", type: 4), + ]) + } +} -- GitLab From 1c5f710c8d380aeb259de58eb17ddbd2286e86de Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki <dariusz@elixxir.io> Date: Thu, 8 Sep 2022 00:08:25 +0200 Subject: [PATCH 05/10] Confirm FactType to RawRepresentable --- Sources/XXClient/Models/FactType.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/XXClient/Models/FactType.swift b/Sources/XXClient/Models/FactType.swift index 96caa0ff..94c28639 100644 --- a/Sources/XXClient/Models/FactType.swift +++ b/Sources/XXClient/Models/FactType.swift @@ -1,13 +1,15 @@ import Foundation public enum FactType: Equatable { + public static let knownTypes: [FactType] = [.username, .email, .phone] + case username case email case phone case other(Int) +} - public static let knownTypes: [FactType] = [.username, .email, .phone] - +extension FactType: RawRepresentable { public init(rawValue: Int) { if let known = FactType.knownTypes.first(where: { $0.rawValue == rawValue }) { self = known -- GitLab From 0c4c6b0f76d462fb1f95343e71c70e27c311290f Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki <dariusz@elixxir.io> Date: Thu, 8 Sep 2022 00:18:51 +0200 Subject: [PATCH 06/10] Remove unused FactHelpers --- .../XXMessengerClient/Utils/FactHelpers.swift | 36 ------------------- 1 file changed, 36 deletions(-) delete mode 100644 Sources/XXMessengerClient/Utils/FactHelpers.swift diff --git a/Sources/XXMessengerClient/Utils/FactHelpers.swift b/Sources/XXMessengerClient/Utils/FactHelpers.swift deleted file mode 100644 index b948f2eb..00000000 --- a/Sources/XXMessengerClient/Utils/FactHelpers.swift +++ /dev/null @@ -1,36 +0,0 @@ -import XXClient - -extension Array where Element == Fact { - public var username: String? { - get { first(where: { $0.type == 0 })?.fact } - set { - removeAll(where: { $0.type == 0 }) - if let newValue = newValue { - append(Fact(fact: newValue, type: 0)) - sort(by: { $0.type < $1.type }) - } - } - } - - public var email: String? { - get { first(where: { $0.type == 1 })?.fact } - set { - removeAll(where: { $0.type == 1 }) - if let newValue = newValue { - append(Fact(fact: newValue, type: 1)) - sort(by: { $0.type < $1.type }) - } - } - } - - public var phone: String? { - get { first(where: { $0.type == 2 })?.fact } - set { - removeAll(where: { $0.type == 2 }) - if let newValue = newValue { - append(Fact(fact: newValue, type: 2)) - sort(by: { $0.type < $1.type }) - } - } - } -} -- GitLab From ccdc8e7bdcb0a85b8d047b2239470478ca9dce54 Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki <dariusz@elixxir.io> Date: Thu, 8 Sep 2022 00:20:31 +0200 Subject: [PATCH 07/10] Conform FactType to ExpressibleByIntegerLiteral --- Sources/XXClient/Models/FactType.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/XXClient/Models/FactType.swift b/Sources/XXClient/Models/FactType.swift index 94c28639..7e245ba1 100644 --- a/Sources/XXClient/Models/FactType.swift +++ b/Sources/XXClient/Models/FactType.swift @@ -28,6 +28,12 @@ extension FactType: RawRepresentable { } } +extension FactType: ExpressibleByIntegerLiteral { + public init(integerLiteral value: IntegerLiteralType) { + self.init(rawValue: value) + } +} + extension FactType: Codable { public init(from decoder: Decoder) throws { let container = try decoder.singleValueContainer() -- GitLab From 0d5af7e34908b29e7d55880d825296829289e439 Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki <dariusz@elixxir.io> Date: Thu, 8 Sep 2022 00:22:40 +0200 Subject: [PATCH 08/10] Conform FactType to Comparable --- Sources/XXClient/Models/FactType.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/XXClient/Models/FactType.swift b/Sources/XXClient/Models/FactType.swift index 7e245ba1..cbae1a7e 100644 --- a/Sources/XXClient/Models/FactType.swift +++ b/Sources/XXClient/Models/FactType.swift @@ -34,6 +34,8 @@ extension FactType: ExpressibleByIntegerLiteral { } } +extension FactType: Comparable {} + extension FactType: Codable { public init(from decoder: Decoder) throws { let container = try decoder.singleValueContainer() -- GitLab From 4fef1f7f786291651afdac3728743e40d48a0604 Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki <dariusz@elixxir.io> Date: Thu, 8 Sep 2022 00:24:55 +0200 Subject: [PATCH 09/10] Change type of Fact.type property to FactType --- Sources/XXClient/Models/Fact.swift | 10 +++++----- Tests/XXClientTests/Models/FactTests.swift | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/XXClient/Models/Fact.swift b/Sources/XXClient/Models/Fact.swift index f239a86d..4fb4134c 100644 --- a/Sources/XXClient/Models/Fact.swift +++ b/Sources/XXClient/Models/Fact.swift @@ -3,14 +3,14 @@ import Foundation public struct Fact: Equatable { public init( fact: String, - type: Int + type: FactType ) { self.fact = fact self.type = type } public var fact: String - public var type: Int + public var type: FactType } extension Fact: Codable { @@ -46,13 +46,13 @@ extension Array where Element == Fact { extension Array where Element == Fact { public func get(_ type: FactType) -> Fact? { - first(where: { $0.type == type.rawValue }) + first(where: { $0.type == type }) } public mutating func set(_ type: FactType, _ value: String?) { - removeAll(where: { $0.type == type.rawValue }) + removeAll(where: { $0.type == type }) if let value = value { - append(Fact(fact: value, type: type.rawValue)) + append(Fact(fact: value, type: type)) sort(by: { $0.type < $1.type }) } } diff --git a/Tests/XXClientTests/Models/FactTests.swift b/Tests/XXClientTests/Models/FactTests.swift index 0e777e7d..5c218ad0 100644 --- a/Tests/XXClientTests/Models/FactTests.swift +++ b/Tests/XXClientTests/Models/FactTests.swift @@ -5,7 +5,7 @@ import XCTest final class FactTests: XCTestCase { func testCoding() throws { let factValue = "Zezima" - let factType: Int = 0 + let factType: Int = 123 let jsonString = """ { "Fact": "\(factValue)", @@ -17,7 +17,7 @@ final class FactTests: XCTestCase { XCTAssertNoDifference(model, Fact( fact: factValue, - type: factType + type: 123 )) let encodedModel = try model.encode() -- GitLab From af9b26e2860c4bbbe6f1e61b3ef4c6e8e8af1e4f Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki <dariusz@elixxir.io> Date: Thu, 8 Sep 2022 00:39:45 +0200 Subject: [PATCH 10/10] Refactor Fact properties --- Sources/XXClient/Models/Fact.swift | 27 +++++++++++---- .../Functions/MessengerSearchUsers.swift | 6 ++-- Tests/XXClientTests/Models/ContactTests.swift | 32 ++++++++--------- Tests/XXClientTests/Models/FactTests.swift | 34 +++++++++---------- .../Functions/MessengerSearchUsersTests.swift | 8 ++--- 5 files changed, 61 insertions(+), 46 deletions(-) diff --git a/Sources/XXClient/Models/Fact.swift b/Sources/XXClient/Models/Fact.swift index 4fb4134c..8b2de9f7 100644 --- a/Sources/XXClient/Models/Fact.swift +++ b/Sources/XXClient/Models/Fact.swift @@ -2,21 +2,21 @@ import Foundation public struct Fact: Equatable { public init( - fact: String, - type: FactType + type: FactType, + value: String ) { - self.fact = fact self.type = type + self.value = value } - public var fact: String public var type: FactType + public var value: String } extension Fact: Codable { enum CodingKeys: String, CodingKey { - case fact = "Fact" case type = "T" + case value = "Fact" } public static func decode(_ data: Data) throws -> Self { @@ -28,6 +28,21 @@ extension Fact: Codable { } } +extension Fact { + @available(iOS, deprecated: 9999.0, message: "This API has been soft-deprecated in favor of `Fact.init(type:value:)`.") + @available(macOS, deprecated: 9999.0, message: "This API has been soft-deprecated in favor of `Fact.init(type:value:)`.") + public init(fact: String, type: Int) { + self.init(type: .init(rawValue: type), value: fact) + } + + @available(iOS, deprecated: 9999.0, message: "This API has been soft-deprecated in favor of `Fact.value`.") + @available(macOS, deprecated: 9999.0, message: "This API has been soft-deprecated in favor of `Fact.value`.") + public var fact: String { + get { value } + set { value = newValue } + } +} + extension Array where Element == Fact { public static func decode(_ data: Data) throws -> Self { if let string = String(data: data, encoding: .utf8), string == "null" { @@ -52,7 +67,7 @@ extension Array where Element == Fact { public mutating func set(_ type: FactType, _ value: String?) { removeAll(where: { $0.type == type }) if let value = value { - append(Fact(fact: value, type: type)) + append(Fact(type: type, value: value)) sort(by: { $0.type < $1.type }) } } diff --git a/Sources/XXMessengerClient/Messenger/Functions/MessengerSearchUsers.swift b/Sources/XXMessengerClient/Messenger/Functions/MessengerSearchUsers.swift index a24a7652..5acd76d7 100644 --- a/Sources/XXMessengerClient/Messenger/Functions/MessengerSearchUsers.swift +++ b/Sources/XXMessengerClient/Messenger/Functions/MessengerSearchUsers.swift @@ -74,13 +74,13 @@ extension MessengerSearchUsers.Query { var facts: [Fact] { var facts: [Fact] = [] if let username = username, username.isEmpty == false { - facts.append(Fact(fact: username, type: 0)) + facts.set(.username, username) } if let email = email, email.isEmpty == false { - facts.append(Fact(fact: email, type: 1)) + facts.set(.email, email) } if let phone = phone, phone.isEmpty == false { - facts.append(Fact(fact: phone, type: 2)) + facts.set(.phone, phone) } return facts } diff --git a/Tests/XXClientTests/Models/ContactTests.swift b/Tests/XXClientTests/Models/ContactTests.swift index 8347e0dc..91dc4149 100644 --- a/Tests/XXClientTests/Models/ContactTests.swift +++ b/Tests/XXClientTests/Models/ContactTests.swift @@ -7,10 +7,10 @@ final class ContactTests: XCTestCase { var contact = Contact.unimplemented("contact-data".data(using: .utf8)!) contact.getFactsFromContact.run = { _ in [ - Fact(fact: "username", type: 0), - Fact(fact: "email", type: 1), - Fact(fact: "phone", type: 2), - Fact(fact: "other", type: 3), + Fact(type: .username, value: "username"), + Fact(type: .email, value: "email"), + Fact(type: .phone, value: "phone"), + Fact(type: .other(3), value: "other"), ] } @@ -23,10 +23,10 @@ final class ContactTests: XCTestCase { try contact.getFact(.other(4)), ], [ - Fact(fact: "username", type: 0), - Fact(fact: "email", type: 1), - Fact(fact: "phone", type: 2), - Fact(fact: "other", type: 3), + Fact(type: .username, value: "username"), + Fact(type: .email, value: "email"), + Fact(type: .phone, value: "phone"), + Fact(type: .other(3), value: "other"), nil ] ) @@ -35,10 +35,10 @@ final class ContactTests: XCTestCase { func testSetFact() throws { var contact = Contact.unimplemented("contact-data".data(using: .utf8)!) var facts: [Fact] = [ - Fact(fact: "username", type: 0), - Fact(fact: "email", type: 1), - Fact(fact: "phone", type: 2), - Fact(fact: "other-3", type: 3), + Fact(type: .username, value: "username"), + Fact(type: .email, value: "email"), + Fact(type: .phone, value: "phone"), + Fact(type: .other(3), value: "other-3"), ] contact.getFactsFromContact.run = { _ in facts } contact.setFactsOnContact.run = { data, newFacts in @@ -52,10 +52,10 @@ final class ContactTests: XCTestCase { try contact.setFact(.email, nil) XCTAssertNoDifference(facts, [ - Fact(fact: "new-username", type: 0), - Fact(fact: "phone", type: 2), - Fact(fact: "new-other-3", type: 3), - Fact(fact: "new-other-4", type: 4), + Fact(type: .username, value: "new-username"), + Fact(type: .phone, value: "phone"), + Fact(type: .other(3), value: "new-other-3"), + Fact(type: .other(4), value: "new-other-4"), ]) } } diff --git a/Tests/XXClientTests/Models/FactTests.swift b/Tests/XXClientTests/Models/FactTests.swift index 5c218ad0..38b6c560 100644 --- a/Tests/XXClientTests/Models/FactTests.swift +++ b/Tests/XXClientTests/Models/FactTests.swift @@ -16,8 +16,8 @@ final class FactTests: XCTestCase { let model = try Fact.decode(jsonData) XCTAssertNoDifference(model, Fact( - fact: factValue, - type: 123 + type: .other(123), + value: factValue )) let encodedModel = try model.encode() @@ -28,9 +28,9 @@ final class FactTests: XCTestCase { func testCodingArray() throws { let models = [ - Fact(fact: "abcd", type: 0), - Fact(fact: "efgh", type: 1), - Fact(fact: "ijkl", type: 2), + Fact(type: .username, value: "abcd"), + Fact(type: .email, value: "efgh"), + Fact(type: .phone, value: "ijkl"), ] let encodedModels = try models.encode() @@ -54,10 +54,10 @@ final class FactTests: XCTestCase { func testArrayGetter() { let facts = [ - Fact(fact: "username", type: 0), - Fact(fact: "email", type: 1), - Fact(fact: "phone", type: 2), - Fact(fact: "other", type: 3), + Fact(type: .username, value: "username"), + Fact(type: .email, value: "email"), + Fact(type: .phone, value: "phone"), + Fact(type: .other(3), value: "other"), ] XCTAssertNoDifference( @@ -69,10 +69,10 @@ final class FactTests: XCTestCase { facts.get(.other(4)), ], [ - Fact(fact: "username", type: 0), - Fact(fact: "email", type: 1), - Fact(fact: "phone", type: 2), - Fact(fact: "other", type: 3), + Fact(type: .username, value: "username"), + Fact(type: .email, value: "email"), + Fact(type: .phone, value: "phone"), + Fact(type: .other(3), value: "other"), nil ] ) @@ -89,10 +89,10 @@ final class FactTests: XCTestCase { XCTAssertNoDifference( facts, [ - Fact(fact: "username", type: 0), - Fact(fact: "email", type: 1), - Fact(fact: "phone", type: 2), - Fact(fact: "other", type: 3), + Fact(type: .username, value: "username"), + Fact(type: .email, value: "email"), + Fact(type: .phone, value: "phone"), + Fact(type: .other(3), value: "other"), ] ) } diff --git a/Tests/XXMessengerClientTests/Messenger/Functions/MessengerSearchUsersTests.swift b/Tests/XXMessengerClientTests/Messenger/Functions/MessengerSearchUsersTests.swift index b6eaac39..9ffa1c82 100644 --- a/Tests/XXMessengerClientTests/Messenger/Functions/MessengerSearchUsersTests.swift +++ b/Tests/XXMessengerClientTests/Messenger/Functions/MessengerSearchUsersTests.swift @@ -181,9 +181,9 @@ final class MessengerSearchUsersTests: XCTestCase { phone: "phone" ).facts, [ - Fact(fact: "username", type: 0), - Fact(fact: "email", type: 1), - Fact(fact: "phone", type: 2), + Fact(type: .username, value: "username"), + Fact(type: .email, value: "email"), + Fact(type: .phone, value: "phone"), ] ) @@ -194,7 +194,7 @@ final class MessengerSearchUsersTests: XCTestCase { phone: nil ).facts, [ - Fact(fact: "username", type: 0), + Fact(type: .username, value: "username"), ] ) } -- GitLab