Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Update ci.yaml #6

Merged
merged 5 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
run: swift-format lint -r ./JellyfishClientSdk/Sources/**/*.swift --configuration swift-format-config.json
- name: Generate mocks
- name: Run lint 👀
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

- name: Run tests
- name: Run tests 💀
run: set -o pipefail && xcodebuild -scheme JellyfishClientSdkTests test -destination "platform=iOS Simulator,name=iPhone 14,OS=latest" | xcbeautify
Original file line number Diff line number Diff line change
@@ -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()
}
}