From 0e9d45417b9aeef37f0b5a094a92777eb95cc672 Mon Sep 17 00:00:00 2001 From: Karol Sygiet Date: Thu, 22 Jun 2023 13:47:36 +0200 Subject: [PATCH 1/5] Update ci.yaml --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d2f90f1..1ebd002 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,7 +14,7 @@ jobs: run: swift-format format -i -r ./JellyfishClientSdk/Sources/**/*.swift --configuration swift-format-config.json - name: Run lint - run: swift-format lint -r ./JellyfishClientSdk/Sources/**/*.swift --configuration swift-format-config.json + run: swift-format lint -r ./JellyfishClientSdk/**/*.swift --configuration swift-format-config.json - name: Generate mocks run: cd JellyfishClientSdk && swift package update Mockingbird && ./gen-mocks.sh From 323c8caf4911b8274ccaaf8df52f9ecc7d80ce92 Mon Sep 17 00:00:00 2001 From: Karol Sygiet Date: Thu, 22 Jun 2023 13:52:36 +0200 Subject: [PATCH 2/5] Update ci.yaml --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1ebd002..84c3f2f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,7 +14,7 @@ jobs: run: swift-format format -i -r ./JellyfishClientSdk/Sources/**/*.swift --configuration swift-format-config.json - name: Run lint - run: swift-format lint -r ./JellyfishClientSdk/**/*.swift --configuration swift-format-config.json + run: swift-format lint -r ./JellyfishClientSdk/**/**/*.swift --configuration swift-format-config.json - name: Generate mocks run: cd JellyfishClientSdk && swift package update Mockingbird && ./gen-mocks.sh From db76b74fee7c87d356897e1d5985e4bd5dbfb663 Mon Sep 17 00:00:00 2001 From: Karol Sygiet Date: Thu, 22 Jun 2023 13:55:48 +0200 Subject: [PATCH 3/5] Update ci.yaml --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 84c3f2f..0ade322 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,7 +14,7 @@ jobs: run: swift-format format -i -r ./JellyfishClientSdk/Sources/**/*.swift --configuration swift-format-config.json - name: Run lint - run: swift-format lint -r ./JellyfishClientSdk/**/**/*.swift --configuration swift-format-config.json + run: swift-format lint -r -s ./JellyfishClientSdk/**/**/*.swift --configuration swift-format-config.json - name: Generate mocks run: cd JellyfishClientSdk && swift package update Mockingbird && ./gen-mocks.sh From 67888d3486c70435d531b43911a008a5f6234d1b Mon Sep 17 00:00:00 2001 From: skyman503 Date: Thu, 22 Jun 2023 14:02:51 +0200 Subject: [PATCH 4/5] init --- .../JellyfishClientSdkTests.swift | 212 +++++++++--------- 1 file changed, 106 insertions(+), 106 deletions(-) diff --git a/JellyfishClientSdk/Tests/JellyfishClientSdkTests/JellyfishClientSdkTests.swift b/JellyfishClientSdk/Tests/JellyfishClientSdkTests/JellyfishClientSdkTests.swift index 67bf7c3..11459de 100644 --- a/JellyfishClientSdk/Tests/JellyfishClientSdkTests/JellyfishClientSdkTests.swift +++ b/JellyfishClientSdk/Tests/JellyfishClientSdkTests/JellyfishClientSdkTests.swift @@ -1,116 +1,116 @@ import Foundation import MembraneRTC -import XCTest import Mockingbird +import XCTest -@testable import Starscream @testable import JellyfishClientSdk - +@testable import Starscream final class JellyfishClientSdkTests: XCTestCase { - let mockedWebSocket = mock(JellyfishWebsocket.self) - let jellyfishClientListener = mock(JellyfishClientListener.self) - let testConfig = Config(websocketUrl: "ws:\\test.com", token: "testTOKEN") - var jellyfishClient: JellyfishClientInternal? - var webrtc: JellyfishMembraneRTC? - - func getMockWebsocket(url: String) -> JellyfishWebsocket { - return self.mockedWebSocket; - } - - static func generateDataFromMessage(_ message: Jellyfish_PeerMessage) -> Data { - guard let serializedData = try? message.serializedData() else { - return Data() + let mockedWebSocket = mock(JellyfishWebsocket.self) + let jellyfishClientListener = mock(JellyfishClientListener.self) + let testConfig = Config(websocketUrl: "ws:\\test.com", token: "testTOKEN") + var jellyfishClient: JellyfishClientInternal? + var webrtc: JellyfishMembraneRTC? + + func getMockWebsocket(url: String) -> JellyfishWebsocket { + return self.mockedWebSocket + } + + static func generateDataFromMessage(_ message: Jellyfish_PeerMessage) -> Data { + guard let serializedData = try? message.serializedData() else { + return Data() + } + + return serializedData } - - return serializedData - } - - let authRequest = generateDataFromMessage( - Jellyfish_PeerMessage.with({ - $0.authRequest = Jellyfish_PeerMessage.AuthRequest.with({ - $0.token = "testTOKEN" - }) - })) - - let authResponse = generateDataFromMessage( - Jellyfish_PeerMessage.with({ - $0.authenticated = Jellyfish_PeerMessage.Authenticated() - })) - - let joinEvent = generateDataFromMessage( - Jellyfish_PeerMessage.with({ - $0.mediaEvent = Jellyfish_PeerMessage.MediaEvent.with({ - $0.data = "join" - }) - }) - ) - - let sdpOfferEvent = generateDataFromMessage( - Jellyfish_PeerMessage.with({ - $0.mediaEvent = Jellyfish_PeerMessage.MediaEvent.with({ - $0.data = "sdpOffer" - }) - }) - ) - - override func setUp() { - let webrtc = mock(JellyfishMembraneRTC.self) - let jellyfishClient = JellyfishClientInternal(listener: self.jellyfishClientListener, websocketFactory: getMockWebsocket) - jellyfishClient.webrtcClient = webrtc - self.jellyfishClient = jellyfishClient - self.webrtc = webrtc - - givenSwift(self.mockedWebSocket.connect()).will { - self.jellyfishClient?.websocketDidConnect() + + let authRequest = generateDataFromMessage( + Jellyfish_PeerMessage.with({ + $0.authRequest = Jellyfish_PeerMessage.AuthRequest.with({ + $0.token = "testTOKEN" + }) + })) + + let authResponse = generateDataFromMessage( + Jellyfish_PeerMessage.with({ + $0.authenticated = Jellyfish_PeerMessage.Authenticated() + })) + + let joinEvent = generateDataFromMessage( + Jellyfish_PeerMessage.with({ + $0.mediaEvent = Jellyfish_PeerMessage.MediaEvent.with({ + $0.data = "join" + }) + }) + ) + + let sdpOfferEvent = generateDataFromMessage( + Jellyfish_PeerMessage.with({ + $0.mediaEvent = Jellyfish_PeerMessage.MediaEvent.with({ + $0.data = "sdpOffer" + }) + }) + ) + + override func setUp() { + let webrtc = mock(JellyfishMembraneRTC.self) + let jellyfishClient = JellyfishClientInternal( + listener: self.jellyfishClientListener, websocketFactory: getMockWebsocket) + jellyfishClient.webrtcClient = webrtc + self.jellyfishClient = jellyfishClient + self.webrtc = webrtc + + givenSwift(self.mockedWebSocket.connect()).will { + self.jellyfishClient?.websocketDidConnect() + } + } + + func connect() { + jellyfishClient?.connect(config: self.testConfig) + verifyClientSent(authRequest) + sendToClient(authResponse) + } + + func sendToClient(_ data: Data) { + self.jellyfishClient?.websocketDidReceiveData(data: data) + } + + func verifyClientSent(_ data: Data) { + verify(self.mockedWebSocket.write(data: data)).wasCalled() + } + + func testConnectAndAuthenticate() throws { + connect() + verify(self.jellyfishClientListener.onAuthSuccess()).wasCalled() + } + + func testCleansUp() throws { + connect() + jellyfishClient?.cleanUp() + verify(self.mockedWebSocket.disconnect()).wasCalled() + verify(self.jellyfishClientListener.onDisconnected()).wasCalled() + verify(self.webrtc?.disconnect()).wasCalled() + } + + func testReceivesMediaEvents() throws { + connect() + sendToClient(sdpOfferEvent) + verify(self.webrtc?.receiveMediaEvent(mediaEvent: "sdpOffer")).wasCalled() + } + + func testSendsMediaEvents() throws { + connect() + jellyfishClient?.onSendMediaEvent(event: "join") + verifyClientSent(joinEvent) + } + + func testCloseWithError() throws { + let err = WSError(type: ErrorType.closeError, message: "Test reason", code: 1009) + + connect() + jellyfishClient?.websocketDidDisconnect(error: err) + + verify(self.jellyfishClientListener.onSocketClose(code: 1009, reason: "Test reason")).wasCalled() } - } - - func connect() { - jellyfishClient?.connect(config: self.testConfig) - verifyClientSent(authRequest) - sendToClient(authResponse) - } - - func sendToClient(_ data: Data) { - self.jellyfishClient?.websocketDidReceiveData(data: data) - } - - func verifyClientSent(_ data: Data) { - verify(self.mockedWebSocket.write(data: data)).wasCalled() - } - - func testConnectAndAuthenticate() throws { - connect() - verify(self.jellyfishClientListener.onAuthSuccess()).wasCalled() - } - - func testCleansUp() throws { - connect() - jellyfishClient?.cleanUp() - verify(self.mockedWebSocket.disconnect()).wasCalled() - verify(self.jellyfishClientListener.onDisconnected()).wasCalled() - verify(self.webrtc?.disconnect()).wasCalled() - } - - func testReceivesMediaEvents() throws { - connect() - sendToClient(sdpOfferEvent) - verify(self.webrtc?.receiveMediaEvent(mediaEvent: "sdpOffer")).wasCalled() - } - - func testSendsMediaEvents() throws { - connect() - jellyfishClient?.onSendMediaEvent(event: "join") - verifyClientSent(joinEvent) - } - - func testCloseWithError() throws { - let err = WSError(type: ErrorType.closeError, message: "Test reason", code: 1009) - - connect() - jellyfishClient?.websocketDidDisconnect(error: err) - - verify(self.jellyfishClientListener.onSocketClose(code: 1009, reason: "Test reason")).wasCalled() - } } From 533f27773253e1f53295e656cb4618c2e11c19c8 Mon Sep 17 00:00:00 2001 From: skyman503 Date: Thu, 22 Jun 2023 14:06:34 +0200 Subject: [PATCH 5/5] update ci --- .github/workflows/ci.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0ade322..d6914ec 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -7,17 +7,17 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Install deps + - name: Install deps 📡 run: brew install swift-format xcbeautify - - name: Run formatter + - name: Run formatter 🎨 run: swift-format format -i -r ./JellyfishClientSdk/Sources/**/*.swift --configuration swift-format-config.json - - name: Run lint + - name: Run lint 👀 run: swift-format lint -r -s ./JellyfishClientSdk/**/**/*.swift --configuration swift-format-config.json - - - name: Generate mocks + + - name: Generate mocks 🫥 run: cd JellyfishClientSdk && swift package update Mockingbird && ./gen-mocks.sh - - name: Run tests + - name: Run tests 💀 run: set -o pipefail && xcodebuild -scheme JellyfishClientSdkTests test -destination "platform=iOS Simulator,name=iPhone 14,OS=latest" | xcbeautify