Skip to content

Commit 6b6727b

Browse files
committed
Added mocks for subscription, clients, strings etc.
1 parent 240d70c commit 6b6727b

File tree

4 files changed

+548
-0
lines changed

4 files changed

+548
-0
lines changed

Example/AblyChatExample.xcodeproj/project.pbxproj

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
21F09AA22C60CAF00025AF73 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21F09AA12C60CAF00025AF73 /* ContentView.swift */; };
1414
21F09AA42C60CAF20025AF73 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 21F09AA32C60CAF20025AF73 /* Assets.xcassets */; };
1515
21F09AA82C60CAF20025AF73 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 21F09AA72C60CAF20025AF73 /* Preview Assets.xcassets */; };
16+
849393602C8507A2000D7165 /* Misc.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8493935F2C8507A2000D7165 /* Misc.swift */; };
17+
849D2E982C7BD09D00EC88A5 /* MockClients.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849D2E972C7BD09D00EC88A5 /* MockClients.swift */; };
18+
84CCAE1A2C89EDD00014C1E6 /* MockSubscription.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84CCAE192C89EDD00014C1E6 /* MockSubscription.swift */; };
19+
84ED7E3C2C95A62E00E8D97E /* AsyncAlgorithms in Frameworks */ = {isa = PBXBuildFile; productRef = 84ED7E3B2C95A62E00E8D97E /* AsyncAlgorithms */; };
1620
/* End PBXBuildFile section */
1721

1822
/* Begin PBXFileReference section */
@@ -24,6 +28,9 @@
2428
21F09AA32C60CAF20025AF73 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
2529
21F09AA52C60CAF20025AF73 /* AblyChatExample.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = AblyChatExample.entitlements; sourceTree = "<group>"; };
2630
21F09AA72C60CAF20025AF73 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
31+
8493935F2C8507A2000D7165 /* Misc.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Misc.swift; sourceTree = "<group>"; };
32+
849D2E972C7BD09D00EC88A5 /* MockClients.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MockClients.swift; sourceTree = "<group>"; };
33+
84CCAE192C89EDD00014C1E6 /* MockSubscription.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MockSubscription.swift; sourceTree = "<group>"; };
2734
/* End PBXFileReference section */
2835

2936
/* Begin PBXFrameworksBuildPhase section */
@@ -32,6 +39,7 @@
3239
buildActionMask = 2147483647;
3340
files = (
3441
21971DFF2C60D89C0074B8AE /* AblyChat in Frameworks */,
42+
84ED7E3C2C95A62E00E8D97E /* AsyncAlgorithms in Frameworks */,
3543
);
3644
runOnlyForDeploymentPostprocessing = 0;
3745
};
@@ -42,6 +50,9 @@
4250
isa = PBXGroup;
4351
children = (
4452
212F95A62C6CAD9300420287 /* MockRealtime.swift */,
53+
849D2E972C7BD09D00EC88A5 /* MockClients.swift */,
54+
84CCAE192C89EDD00014C1E6 /* MockSubscription.swift */,
55+
8493935F2C8507A2000D7165 /* Misc.swift */,
4556
);
4657
path = Mocks;
4758
sourceTree = "<group>";
@@ -110,6 +121,7 @@
110121
name = AblyChatExample;
111122
packageProductDependencies = (
112123
21971DFE2C60D89C0074B8AE /* AblyChat */,
124+
84ED7E3B2C95A62E00E8D97E /* AsyncAlgorithms */,
113125
);
114126
productName = AblyChatExample;
115127
productReference = 21F09A9C2C60CAF00025AF73 /* AblyChatExample.app */;
@@ -139,6 +151,9 @@
139151
Base,
140152
);
141153
mainGroup = 21F09A932C60CAF00025AF73;
154+
packageReferences = (
155+
84ED7E3A2C95A62E00E8D97E /* XCRemoteSwiftPackageReference "swift-async-algorithms" */,
156+
);
142157
productRefGroup = 21F09A9D2C60CAF00025AF73 /* Products */;
143158
projectDirPath = "";
144159
projectRoot = "";
@@ -168,6 +183,9 @@
168183
212F95A72C6CAD9300420287 /* MockRealtime.swift in Sources */,
169184
21F09AA22C60CAF00025AF73 /* ContentView.swift in Sources */,
170185
21F09AA02C60CAF00025AF73 /* AblyChatExampleApp.swift in Sources */,
186+
849393602C8507A2000D7165 /* Misc.swift in Sources */,
187+
849D2E982C7BD09D00EC88A5 /* MockClients.swift in Sources */,
188+
84CCAE1A2C89EDD00014C1E6 /* MockSubscription.swift in Sources */,
171189
);
172190
runOnlyForDeploymentPostprocessing = 0;
173191
};
@@ -397,11 +415,27 @@
397415
};
398416
/* End XCConfigurationList section */
399417

418+
/* Begin XCRemoteSwiftPackageReference section */
419+
84ED7E3A2C95A62E00E8D97E /* XCRemoteSwiftPackageReference "swift-async-algorithms" */ = {
420+
isa = XCRemoteSwiftPackageReference;
421+
repositoryURL = "https://github.com/apple/swift-async-algorithms.git";
422+
requirement = {
423+
kind = upToNextMajorVersion;
424+
minimumVersion = 1.0.1;
425+
};
426+
};
427+
/* End XCRemoteSwiftPackageReference section */
428+
400429
/* Begin XCSwiftPackageProductDependency section */
401430
21971DFE2C60D89C0074B8AE /* AblyChat */ = {
402431
isa = XCSwiftPackageProductDependency;
403432
productName = AblyChat;
404433
};
434+
84ED7E3B2C95A62E00E8D97E /* AsyncAlgorithms */ = {
435+
isa = XCSwiftPackageProductDependency;
436+
package = 84ED7E3A2C95A62E00E8D97E /* XCRemoteSwiftPackageReference "swift-async-algorithms" */;
437+
productName = AsyncAlgorithms;
438+
};
405439
/* End XCSwiftPackageProductDependency section */
406440
};
407441
rootObject = 21F09A942C60CAF00025AF73 /* Project object */;
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import Ably
2+
import AblyChat
3+
4+
final class MockMessagesPaginatedResult: PaginatedResult {
5+
typealias T = Message
6+
7+
let clientID: String
8+
let roomID: String
9+
10+
var items: [T] {
11+
[
12+
Message(timeserial: "\(Date().timeIntervalSince1970)",
13+
clientID: self.clientID,
14+
roomID: self.roomID,
15+
text: MockStrings.randomPhrase(),
16+
createdAt: Date(),
17+
metadata: [:],
18+
headers: [:])
19+
]
20+
}
21+
22+
var hasNext: Bool { fatalError("Not implemented") }
23+
24+
var isLast: Bool { fatalError("Not implemented") }
25+
26+
var next: (any PaginatedResult<T>)? { fatalError("Not implemented") }
27+
28+
var first: any PaginatedResult<T> { fatalError("Not implemented") }
29+
30+
var current: any PaginatedResult<T> { fatalError("Not implemented") }
31+
32+
init(clientID: String, roomID: String) {
33+
self.clientID = clientID
34+
self.roomID = roomID
35+
}
36+
}
37+
38+
class MockStrings {
39+
40+
static let names = [ "Alice", "Bob", "Charlie", "Dave", "Eve" ]
41+
42+
static func randomWord(length: Int = Int.random(in: 1...10)) -> String {
43+
var word = ""
44+
for _ in 0..<length {
45+
let char = String(format: "%c", Int.random(in: 97..<123))
46+
word += char
47+
}
48+
return word
49+
}
50+
51+
static func randomPhrase(length: Int = Int.random(in: 1...10)) -> String {
52+
var phrase = ""
53+
for _ in 0..<length {
54+
phrase += randomWord() + " "
55+
}
56+
phrase += Int.random(in: 1...100) % 5 == 0 ? "😆" : ""
57+
return phrase.count % 33 == 0 ? "Bingo! 😂" : phrase
58+
}
59+
}
60+
61+
enum ReactionType: String, CaseIterable {
62+
case like, dislike, lol, rofl, ok, idk
63+
64+
var emoji: String {
65+
switch self {
66+
case .like:
67+
return "👍"
68+
case .dislike:
69+
return "👎"
70+
case .lol:
71+
return "😆"
72+
case .rofl:
73+
return "😂"
74+
case .ok:
75+
return "👌"
76+
default:
77+
return "🤷‍♀️"
78+
}
79+
}
80+
}
81+
82+
extension Reaction {
83+
84+
var displayedText: String {
85+
ReactionType(rawValue: type)?.emoji ?? ReactionType.idk.emoji
86+
}
87+
}

0 commit comments

Comments
 (0)