Skip to content

Commit c752ba0

Browse files
committed
[CI] Implement new mock server
1 parent ab527b3 commit c752ba0

File tree

89 files changed

+967
-10873
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+967
-10873
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ app-thinning.plist
9292
*.dmg
9393
*.pkg*
9494
*LinkMap.txt
95+
stream-chat-test-mock-server
9596

9697
# gcloud
9798
google-cloud-sdk

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
<p align="center">
99
<a href="https://getstream.io/chat/docs/sdk/ios/"><img src="https://img.shields.io/badge/iOS-13%2B-lightblue" /></a>
1010
<a href="https://swift.org"><img src="https://img.shields.io/badge/Swift-6.0%2B-orange.svg" /></a>
11-
<a href="https://github.com/GetStream/stream-chat-swift/actions"><img src="https://github.com/GetStream/stream-chat-swift/actions/workflows/cron-checks.yml/badge.svg" /></a>
1211
<a href="https://sonarcloud.io/summary/new_code?id=GetStream_stream-chat-swift"><img src="https://sonarcloud.io/api/project_badges/measure?project=GetStream_stream-chat-swift&metric=coverage" /></a>
1312
</p>
1413
<p align="center">

StreamChat.xcodeproj/project.pbxproj

Lines changed: 19 additions & 273 deletions
Large diffs are not rendered by default.

StreamChat.xcodeproj/xcshareddata/xcschemes/StreamChatUITestsApp.xcscheme

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
<TestPlanReference
3636
reference = "container:StreamChatUITestsAppUITests/Performance.xctestplan">
3737
</TestPlanReference>
38+
<TestPlanReference
39+
reference = "container:StreamChatUITestsAppUITests/Backend.xctestplan">
40+
</TestPlanReference>
3841
</TestPlans>
3942
<Testables>
4043
<TestableReference

StreamChatUITestsApp/ViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ extension StreamChatWrapper {
210210
func mockTokenProvider(for userCredentials: UserCredentials) -> TokenProvider {
211211
{ completion in
212212
if ProcessInfo.processInfo.arguments.contains("MOCK_JWT") {
213-
let udid = ProcessInfo.processInfo.environment["SIMULATOR_UDID"] ?? ""
214-
let urlString = "http://localhost:4567/jwt/\(udid)?api_key=\(apiKeyString)&user_name=\(userCredentials.id)"
213+
let port = ProcessInfo.processInfo.environment["MOCK_SERVER_PORT"]!
214+
let urlString = "http://localhost:\(port)/jwt/get?platform=ios"
215215
guard let url = URL(string: urlString) else { return }
216216

217217
var request = URLRequest(url: url)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"configurations" : [
3+
{
4+
"id" : "EE3D2846-1E2B-4AC7-819B-FFA45AB6C270",
5+
"name" : "Configuration 1",
6+
"options" : {
7+
8+
}
9+
}
10+
],
11+
"defaultOptions" : {
12+
13+
},
14+
"testTargets" : [
15+
{
16+
"selectedTests" : [
17+
"Backend_Tests\/test_message()",
18+
"Backend_Tests\/test_reaction()"
19+
],
20+
"target" : {
21+
"containerPath" : "container:StreamChat.xcodeproj",
22+
"identifier" : "A34407DB27D8C3400044F150",
23+
"name" : "StreamChatUITestsAppUITests"
24+
}
25+
}
26+
],
27+
"version" : 1
28+
}

StreamChatUITestsAppUITests/Pages/ChannelListPage.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ enum ChannelListPage {
5555
cell.staticTexts["unreadCountLabel"]
5656
}
5757

58-
static func statusCheckmark(for status: MessageDeliveryStatus?, in cell: XCUIElement) -> XCUIElement {
58+
static func statusCheckmark(
59+
for status: StreamChatTestMockServer.MessageDeliveryStatus?,
60+
in cell: XCUIElement
61+
) -> XCUIElement {
5962
var identifier = "There is no status checkmark"
6063
if let status = status {
6164
identifier = "imageView_\(status.rawValue)"

StreamChatUITestsAppUITests/Pages/MessageListPage.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,10 @@ class MessageListPage {
208208
messageCell.staticTexts["messageReadСountsLabel"]
209209
}
210210

211-
static func statusCheckmark(for status: MessageDeliveryStatus?, in messageCell: XCUIElement) -> XCUIElement {
211+
static func statusCheckmark(
212+
for status: StreamChatTestMockServer.MessageDeliveryStatus?,
213+
in messageCell: XCUIElement
214+
) -> XCUIElement {
212215
var identifier = "There is no status checkmark"
213216
if let status = status {
214217
identifier = "imageView_\(status.rawValue)"

StreamChatUITestsAppUITests/Robots/UserRobot+Asserts.swift

Lines changed: 31 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//
44

55
import Foundation
6-
@testable import StreamChat
76
@testable import StreamChatUI
87
import XCTest
98

@@ -36,6 +35,25 @@ extension UserRobot {
3635
)
3736
return channelCells.element(boundBy: index)
3837
}
38+
39+
@discardableResult
40+
func assertChannelPreviewIsEmpty(
41+
at cellIndex: Int? = nil,
42+
file: StaticString = #filePath,
43+
line: UInt = #line
44+
) -> Self {
45+
let emptyChannelPreviewText = "No messages"
46+
let cell = channelCell(withIndex: cellIndex, file: file, line: line)
47+
let message = channelAttributes.lastMessage(in: cell)
48+
let actualText = message.waitForText(emptyChannelPreviewText, mustBeEqual: true).text
49+
XCTAssertEqual(
50+
actualText,
51+
emptyChannelPreviewText,
52+
file: file,
53+
line: line
54+
)
55+
return self
56+
}
3957

4058
@discardableResult
4159
func assertLastMessageInChannelPreview(
@@ -75,7 +93,7 @@ extension UserRobot {
7593

7694
@discardableResult
7795
func assertMessageDeliveryStatusInChannelPreview(
78-
_ deliveryStatus: MessageDeliveryStatus?,
96+
_ deliveryStatus: StreamChatTestMockServer.MessageDeliveryStatus?,
7997
at cellIndex: Int? = nil,
8098
file: StaticString = #filePath,
8199
line: UInt = #line
@@ -229,8 +247,8 @@ extension UserRobot {
229247

230248
@discardableResult
231249
func assertPushNotification(
232-
withText text: String,
233-
from sender: String,
250+
title: String,
251+
body: String,
234252
file: StaticString = #filePath,
235253
line: UInt = #line
236254
) -> Self {
@@ -244,14 +262,14 @@ extension UserRobot {
244262

245263
let pushNotificationContent = pushNotification.text
246264
XCTAssertTrue(
247-
pushNotificationContent.contains(text),
248-
"\(pushNotificationContent) does not contain \(text)",
265+
pushNotificationContent.contains(body),
266+
"\(pushNotificationContent) does not contain \(body)",
249267
file: file,
250268
line: line
251269
)
252270
XCTAssertTrue(
253-
pushNotificationContent.contains(sender),
254-
"\(pushNotificationContent) does not contain \(sender)",
271+
pushNotificationContent.contains(title),
272+
"\(pushNotificationContent) does not contain \(title)",
255273
file: file,
256274
line: line
257275
)
@@ -519,7 +537,7 @@ extension UserRobot {
519537

520538
@discardableResult
521539
func waitForMessageDeliveryStatus(
522-
_ deliveryStatus: MessageDeliveryStatus?,
540+
_ deliveryStatus: StreamChatTestMockServer.MessageDeliveryStatus?,
523541
at messageCellIndex: Int? = nil,
524542
file: StaticString = #filePath,
525543
line: UInt = #line
@@ -535,7 +553,7 @@ extension UserRobot {
535553

536554
@discardableResult
537555
func assertMessageDeliveryStatus(
538-
_ deliveryStatus: MessageDeliveryStatus?,
556+
_ deliveryStatus: StreamChatTestMockServer.MessageDeliveryStatus?,
539557
at messageCellIndex: Int? = nil,
540558
file: StaticString = #filePath,
541559
line: UInt = #line
@@ -678,9 +696,8 @@ extension UserRobot {
678696
}
679697

680698
@discardableResult
681-
func assertMentionWasApplied(file: StaticString = #filePath, line: UInt = #line) -> Self {
699+
func assertMentionWasApplied(userName: String, file: StaticString = #filePath, line: UInt = #line) -> Self {
682700
let additionalSpace = " "
683-
let userName = UserDetails.countDookuName
684701
let expectedText = "@\(userName)\(additionalSpace)"
685702
let actualText = MessageListPage.Composer.textView.waitForText(expectedText).text
686703
XCTAssertEqual(expectedText, actualText, file: file, line: line)
@@ -848,7 +865,7 @@ extension UserRobot {
848865

849866
@discardableResult
850867
func assertThreadReplyDeliveryStatus(
851-
_ deliveryStatus: MessageDeliveryStatus?,
868+
_ deliveryStatus: StreamChatTestMockServer.MessageDeliveryStatus?,
852869
at messageCellIndex: Int? = nil,
853870
file: StaticString = #filePath,
854871
line: UInt = #line
@@ -1037,7 +1054,7 @@ extension UserRobot {
10371054
line: UInt = #line
10381055
) -> Self {
10391056
let cell = messageCell(withIndex: messageCellIndex, file: file, line: line).wait()
1040-
let expectedText = Message.message(withInvalidCommand: invalidCommand)
1057+
let expectedText = "Sorry, command \(invalidCommand) doesn't exist. Try posting your message without the starting /"
10411058
let actualText = attributes.text(in: cell).waitForText(expectedText).text
10421059
XCTAssertEqual(actualText, expectedText, file: file, line: line)
10431060
return self
@@ -1120,35 +1137,3 @@ extension UserRobot {
11201137
return self
11211138
}
11221139
}
1123-
1124-
// MARK: UserDetails
1125-
1126-
extension UserRobot {
1127-
@discardableResult
1128-
func assertUserDetails(_ details: [String: Any]?) -> Self {
1129-
let userDetails = details?[WebSocketConnectPayload.CodingKeys.userDetails.rawValue] as? [String: Any]
1130-
1131-
let serverDeterminesConnectionId = details?[WebSocketConnectPayload.CodingKeys.serverDeterminesConnectionId.rawValue] as? Bool
1132-
XCTAssertEqual(true, serverDeterminesConnectionId)
1133-
1134-
let userId = details?[WebSocketConnectPayload.CodingKeys.userId.rawValue] as? String
1135-
XCTAssertEqual(UserDetails.lukeSkywalkerId, userId)
1136-
1137-
let id = userDetails?[UserWebSocketPayload.CodingKeys.id.rawValue] as? String
1138-
XCTAssertEqual(UserDetails.lukeSkywalkerId, id)
1139-
1140-
let isInvisible = userDetails?[UserWebSocketPayload.CodingKeys.isInvisible.rawValue] as? Bool
1141-
XCTAssertEqual(nil, isInvisible)
1142-
1143-
let name = userDetails?[UserWebSocketPayload.CodingKeys.name.rawValue] as? String
1144-
XCTAssertEqual(UserDetails.lukeSkywalkerName, name)
1145-
1146-
let imageURL = userDetails?[UserWebSocketPayload.CodingKeys.imageURL.rawValue] as? String
1147-
XCTAssertEqual(UserDetails.lukeSkywalkerImageURL, imageURL)
1148-
1149-
let birthland = userDetails?["birthland"] as? String
1150-
XCTAssertEqual("Tatooine", birthland)
1151-
1152-
return self
1153-
}
1154-
}

StreamChatUITestsAppUITests/Robots/UserRobot.swift

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,6 @@ final class UserRobot: Robot {
3333
func waitForChannelListToLoad() -> Self {
3434
let timeout = 15.0
3535
let cells = ChannelListPage.cells.waitCount(1, timeout: timeout)
36-
37-
// TODO: CIS-1737
38-
if !cells.firstMatch.exists {
39-
for _ in 0...10 {
40-
app.terminate()
41-
server.stop()
42-
_ = server.start(port: MockServerConfiguration.port)
43-
sleep(1)
44-
app.launch()
45-
login()
46-
cells.waitCount(1, timeout: timeout)
47-
if cells.firstMatch.exists { break }
48-
}
49-
}
50-
5136
XCTAssertGreaterThanOrEqual(cells.count, 1, "Channel list has not been loaded")
5237
return self
5338
}
@@ -61,7 +46,14 @@ final class UserRobot: Robot {
6146

6247
@discardableResult
6348
public func waitForJwtToExpire() -> Self {
64-
let sleepTime = UInt32(StreamMockServer.jwtTimeout * 1_000_000)
49+
let sleepTime = UInt32((StreamMockServer.jwtTimeout + 2) * 1_000_000)
50+
usleep(sleepTime)
51+
return self
52+
}
53+
54+
@discardableResult
55+
public func sleep(_ seconds: Double) -> Self {
56+
let sleepTime = UInt32(seconds * 1_000_000)
6557
usleep(sleepTime)
6658
return self
6759
}
@@ -94,15 +86,10 @@ extension UserRobot {
9486
file: StaticString = #filePath,
9587
line: UInt = #line
9688
) -> Self {
97-
server.channelsEndpointWasCalled = false
98-
9989
typeText(text)
10090
composer.sendButton.safeTap()
10191

10292
if waitForAppearance {
103-
server.waitForWebsocketMessage(withText: text)
104-
server.waitForHttpMessage(withText: text)
105-
10693
let cell = messageCell(withIndex: messageCellIndex, file: file, line: line).wait()
10794
let textView = attributes.text(in: cell)
10895
_ = textView.waitForText(text)
@@ -153,7 +140,7 @@ extension UserRobot {
153140

154141
@discardableResult
155142
private func reactionAction(
156-
reactionType: TestData.Reactions,
143+
reactionType: ReactionType,
157144
eventType: EventType,
158145
messageCellIndex: Int
159146
) -> Self {
@@ -179,7 +166,7 @@ extension UserRobot {
179166
}
180167

181168
@discardableResult
182-
func addReaction(type: TestData.Reactions, messageCellIndex: Int = 0) -> Self {
169+
func addReaction(type: ReactionType, messageCellIndex: Int = 0) -> Self {
183170
reactionAction(
184171
reactionType: type,
185172
eventType: .reactionNew,
@@ -188,7 +175,7 @@ extension UserRobot {
188175
}
189176

190177
@discardableResult
191-
func deleteReaction(type: TestData.Reactions, messageCellIndex: Int = 0) -> Self {
178+
func deleteReaction(type: ReactionType, messageCellIndex: Int = 0) -> Self {
192179
reactionAction(
193180
reactionType: type,
194181
eventType: .reactionDeleted,
@@ -277,7 +264,7 @@ extension UserRobot {
277264
}
278265

279266
@discardableResult
280-
func replyToMessageInThread(
267+
func sendMessageInThread(
281268
_ text: String,
282269
alsoSendInChannel: Bool = false,
283270
messageCellIndex: Int = 0,
@@ -377,7 +364,7 @@ extension UserRobot {
377364
}
378365

379366
@discardableResult
380-
func sendGiphy(text: String = "Test", useComposerCommand: Bool = false, send: Bool = true) -> Self {
367+
func uploadGiphy(text: String = "Test", useComposerCommand: Bool = false, send: Bool = true) -> Self {
381368
if useComposerCommand {
382369
openComposerCommands()
383370
MessageListPage.ComposerCommands.giphyImage.wait().safeTap()
@@ -394,7 +381,7 @@ extension UserRobot {
394381
func replyWithGiphy(useComposerCommand: Bool = false, messageCellIndex: Int = 0) -> Self {
395382
return self
396383
.selectOptionFromContextMenu(option: .reply, forMessageAtIndex: messageCellIndex)
397-
.sendGiphy(useComposerCommand: useComposerCommand)
384+
.uploadGiphy(useComposerCommand: useComposerCommand)
398385
}
399386

400387
@discardableResult
@@ -410,7 +397,7 @@ extension UserRobot {
410397
if alsoSendInChannel {
411398
threadCheckbox.wait().safeTap()
412399
}
413-
return sendGiphy(useComposerCommand: useComposerCommand)
400+
return uploadGiphy(useComposerCommand: useComposerCommand)
414401
}
415402

416403
@discardableResult
@@ -476,8 +463,8 @@ extension UserRobot {
476463
}
477464

478465
@discardableResult
479-
func mentionParticipant(manually: Bool = false) -> Self {
480-
let text = "@\(UserDetails.countDookuId)"
466+
func mentionParticipant(_ userId: String, manually: Bool = false) -> Self {
467+
let text = "@\(userId)"
481468
if manually {
482469
typeText(text)
483470
} else {
@@ -498,7 +485,7 @@ extension UserRobot {
498485
}
499486

500487
@discardableResult
501-
func addParticipant(withUserId userId: String = UserDetails.leiaOrganaId) -> Self {
488+
func addParticipant(withUserId userId: String = "leia_organa") -> Self {
502489
tapOnDebugMenu()
503490
debugAlert.addMember.firstMatch.safeTap()
504491
debugAlert.addMemberTextField.firstMatch
@@ -509,7 +496,7 @@ extension UserRobot {
509496
}
510497

511498
@discardableResult
512-
func removeParticipant(withUserId userId: String = UserDetails.leiaOrganaId) -> Self {
499+
func removeParticipant(withUserId userId: String = "leia_organa") -> Self {
513500
tapOnDebugMenu()
514501
debugAlert.removeMember.firstMatch.safeTap()
515502
debugAlert.selectMember(withUserId: userId).firstMatch.safeTap()

0 commit comments

Comments
 (0)