mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-23 00:18:27 +00:00
* core: delete agent file after every terminal XFTP upload event * ios: spec for XFTP uploads during suspension * core: pin simplexmq to evgeny-simplex fork for CI * core: skip agent file deletion for XFTP errors without file ID * ios: spec for counted XFTP uploads during suspension * docs: plan for agent file deletion after XFTP uploads * docs: revise plan for agent file deletion after XFTP uploads * docs: revise plan wording for agent file deletion after XFTP uploads * ios: spec wording for XFTP uploads during suspension * core: pin simplexmq to the rewritten fork commit * core: pin simplexmq with ended uploads excluded from suspension wait * ios: suspend the app chat at once when the share sheet opens * docs: plan decisions for the app yielding to the share extension * core: verify agent file deletion for an item deleted during upload * ios: spec wording for awaited XFTP uploads during suspension * core: pin simplexmq with renamed upload wait functions and tests * docs: plan wording, spec text and deletion test for agent files * ios: suspend the app at once for the share sheet only while suspending * docs: plan the narrowed share extension yielding * docs: share extension wait, NSE and residual cases in plan and spec * docs: plan tests for the remaining agent file deletion paths * core: verify agent file deletion on the remaining upload paths * core: pin simplexmq to the fork commit with merged master * docs: plan line references after merging master and flow diagrams * core: agent file deletion finalizer written with flip, as in the codebase * ios: spec states the conditions of the share extension wait and the instant suspension * docs: plan names the merged master base and the spec conditions * core: pin simplexmq to the fork commit with the review fixes * docs: spec and plan state when the share extension wait ends, link the simplexmq pull request, list the device test after app suspension * core: pin simplexmq to the fork commit with the separate suspend timeout thread * docs: spec and plan state that the share extension wait ends at the first check with both states suspended * core: pin simplexmq master commit with the merged upload changes * core, ios: test instant suspension on the share extension signal * ios: deliver the share extension signal to the app in the setup wait test * ios: await the delivery result outside the assertion * ios: keep the app running until each file upload ends * tests: record each upload fixture in its own test * ios: restore the suspension of the app and the share extension of master * tests: add the upload fixture files to record into * tests: record upload responses and events for app tests * core: update query plans * tests: delete the uploaded item after its upload ends * core: no error for upload events of a deleted file
93 lines
3.7 KiB
Swift
93 lines
3.7 KiB
Swift
import XCTest
|
|
@testable import SimpleX
|
|
@testable import SimpleXChat
|
|
|
|
final class FileUploadTests: XCTestCase {
|
|
private let sendCmd = sendSimpleXCmdStr
|
|
|
|
@MainActor
|
|
override func tearDown() async throws {
|
|
ChatModel.shared.fileUploads.values.forEach { $0() }
|
|
ChatModel.shared.messageDelivery.values.forEach { $0() }
|
|
sendSimpleXCmdStr = sendCmd
|
|
}
|
|
|
|
@MainActor
|
|
func testSentFileBeginsTask() async throws {
|
|
try replay("files/send-file")
|
|
_ = await apiSendMessages(type: .direct, id: 2, scope: nil, composedMessages: [ComposedMessage(fileSource: .plain("test.pdf"), msgContent: .file(""))])
|
|
XCTAssertEqual(Array(ChatModel.shared.fileUploads.keys), [1])
|
|
}
|
|
|
|
@MainActor
|
|
func testSentGroupFileBeginsTask() async throws {
|
|
try replay("files/send-group-file")
|
|
_ = await apiSendMessages(type: .group, id: 1, scope: nil, composedMessages: [ComposedMessage(fileSource: .plain("test.pdf"), msgContent: .file(""))])
|
|
XCTAssertEqual(Array(ChatModel.shared.fileUploads.keys), [1])
|
|
}
|
|
|
|
@MainActor
|
|
func testSentTextBeginsNoTask() async throws {
|
|
try replay("files/send-text")
|
|
_ = await apiSendMessages(type: .direct, id: 2, scope: nil, composedMessages: [ComposedMessage(msgContent: .text("hi"))])
|
|
XCTAssertEqual(Array(ChatModel.shared.fileUploads.keys), [])
|
|
}
|
|
|
|
@MainActor
|
|
func testCompletedUploadEndsTask() async throws {
|
|
beginUploadTask(fileId: 1)
|
|
await processReceivedMsg(try event(XCTUnwrap((try fixtureJSON("files/upload-complete") as? [Any])?.first)))
|
|
XCTAssertEqual(Array(ChatModel.shared.fileUploads.keys), [])
|
|
}
|
|
|
|
@MainActor
|
|
func testUploadErrorEndsTask() async throws {
|
|
beginUploadTask(fileId: 1)
|
|
await processReceivedMsg(try event(XCTUnwrap((try fixtureJSON("files/upload-error") as? [Any])?.first)))
|
|
XCTAssertEqual(Array(ChatModel.shared.fileUploads.keys), [])
|
|
}
|
|
|
|
@MainActor
|
|
func testCancelledUploadEndsTask() async throws {
|
|
beginUploadTask(fileId: 1)
|
|
try replay("files/cancel")
|
|
_ = await apiCancelFile(fileId: 1)
|
|
XCTAssertEqual(Array(ChatModel.shared.fileUploads.keys), [])
|
|
}
|
|
|
|
@MainActor
|
|
func testDeletedItemEndsTask() async throws {
|
|
beginUploadTask(fileId: 1)
|
|
try replay("files/delete")
|
|
_ = try await apiDeleteChatItems(type: .direct, id: 2, scope: nil, itemIds: [1], mode: .cidmInternal)
|
|
XCTAssertEqual(Array(ChatModel.shared.fileUploads.keys), [])
|
|
}
|
|
|
|
@MainActor
|
|
func testDeletedItemEventEndsTask() async throws {
|
|
beginUploadTask(fileId: 1)
|
|
await processReceivedMsg(try event(try response("files/delete")))
|
|
XCTAssertEqual(Array(ChatModel.shared.fileUploads.keys), [])
|
|
}
|
|
|
|
@MainActor
|
|
private func beginUploadTask(fileId: Int64) {
|
|
beginFileUploadTasks([ChatItem.getSample(1, .directSnd, .now, "", file: CIFile.getSample(fileId: fileId, fileStatus: .sndStored))])
|
|
}
|
|
|
|
private func response(_ fixture: String) throws -> Any {
|
|
try XCTUnwrap((try fixtureJSON(fixture) as? [String: [String: Any]])?["commands"]?.values.first)
|
|
}
|
|
|
|
private func replay(_ fixture: String) throws {
|
|
let recorded = try response(fixture)
|
|
sendSimpleXCmdStr = { _, _, _ in try? JSONSerialization.data(withJSONObject: singleFieldJSON(recorded)) }
|
|
}
|
|
|
|
private func event(_ json: Any) throws -> ChatEvent {
|
|
let decoded: APIResult<ChatEvent> = decodeAPIResult(try JSONSerialization.data(withJSONObject: singleFieldJSON(json)))
|
|
let event: ChatEvent? = if case let .result(r) = decoded { r } else { nil }
|
|
return try XCTUnwrap(event, "event not decoded: \(decoded.responseType)")
|
|
}
|
|
}
|