unit tests
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
import MultipeerConnectivity
|
||||
import Testing
|
||||
|
||||
@testable import Peered
|
||||
|
||||
extension NoteInvitation {
|
||||
fileprivate init(handler: @escaping (Bool) -> Void) {
|
||||
self.init(
|
||||
invitatorID: .init(
|
||||
displayName: "host"
|
||||
),
|
||||
note: .init(title: "Shared note", noteSnapshot: "Snapshot"),
|
||||
invitationHandler: handler
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Suite
|
||||
struct NoteInvitationTests {
|
||||
@Test
|
||||
func acceptCallsHandlerWithTrue() {
|
||||
var received: Bool? = nil
|
||||
var invitation = NoteInvitation { received = $0 }
|
||||
|
||||
invitation.accept()
|
||||
|
||||
#expect(received == true)
|
||||
}
|
||||
|
||||
@Test
|
||||
func declineCallsHandlerWithFalse() {
|
||||
var received: Bool? = nil
|
||||
var invitation = NoteInvitation { received = $0 }
|
||||
|
||||
invitation.decline()
|
||||
|
||||
#expect(received == false)
|
||||
}
|
||||
|
||||
@Test
|
||||
func acceptIsIdempotent() {
|
||||
var callCount = 0
|
||||
var invitation = NoteInvitation { _ in callCount += 1 }
|
||||
|
||||
invitation.accept()
|
||||
invitation.accept()
|
||||
|
||||
#expect(callCount == 1)
|
||||
}
|
||||
|
||||
@Test
|
||||
func declineIsIdempotent() {
|
||||
var callCount = 0
|
||||
var invitation = NoteInvitation { _ in callCount += 1 }
|
||||
|
||||
invitation.decline()
|
||||
invitation.decline()
|
||||
|
||||
#expect(callCount == 1)
|
||||
}
|
||||
|
||||
@Test
|
||||
func declineAfterAcceptIsNoOp() {
|
||||
var callCount = 0
|
||||
var invitation = NoteInvitation { _ in callCount += 1 }
|
||||
|
||||
invitation.accept()
|
||||
invitation.decline()
|
||||
|
||||
#expect(callCount == 1)
|
||||
}
|
||||
|
||||
@Test
|
||||
func noteNameReturnsTitle() {
|
||||
let invitation = NoteInvitation { _ in }
|
||||
#expect(invitation.noteName == "Shared note")
|
||||
}
|
||||
|
||||
@Test
|
||||
func idIsInvitatorPeerID() {
|
||||
let peerID = MCPeerID(displayName: "host")
|
||||
let invitation = NoteInvitation(
|
||||
invitatorID: peerID,
|
||||
note: .init(title: "T", noteSnapshot: "S")
|
||||
)
|
||||
#expect(invitation.id == peerID)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user