ImportServiceTests.swift (1919B)
1 import Foundation 2 import Testing 3 4 @testable import Crossmate 5 6 /// Pins down the open-URL import boundary: an oversized or unsupported file 7 /// is rejected by the streaming capped read before any conversion, iCloud 8 /// copy, or game creation. (These rejection paths return before 9 /// `DriveMonitor.importFile`, so no test touches a real iCloud container.) 10 @Suite("ImportService") 11 @MainActor 12 struct ImportServiceTests { 13 14 private func makeService() -> ImportService { 15 ImportService( 16 store: makeTestStore(persistence: makeTestPersistence()), 17 driveMonitor: DriveMonitor() 18 ) 19 } 20 21 private func writeTemp(_ data: Data, ext: String) throws -> URL { 22 let url = FileManager.default.temporaryDirectory 23 .appendingPathComponent("import-service-\(UUID().uuidString)") 24 .appendingPathExtension(ext) 25 try data.write(to: url) 26 return url 27 } 28 29 @Test("An oversized .xd is rejected") 30 func rejectsOversizedXD() throws { 31 let url = try writeTemp( 32 Data(repeating: UInt8(ascii: "A"), count: XD.maxSourceBytes + 1), 33 ext: "xd" 34 ) 35 defer { try? FileManager.default.removeItem(at: url) } 36 37 #expect(makeService().importGame(from: url) == nil) 38 } 39 40 @Test("An oversized .puz is rejected") 41 func rejectsOversizedPUZ() throws { 42 let url = try writeTemp( 43 Data(count: PUZToXDConverter.maxSourceBytes + 1), 44 ext: "puz" 45 ) 46 defer { try? FileManager.default.removeItem(at: url) } 47 48 #expect(makeService().importGame(from: url) == nil) 49 } 50 51 @Test("An unsupported extension is rejected") 52 func rejectsUnsupportedExtension() throws { 53 let url = try writeTemp(Data("not a puzzle".utf8), ext: "txt") 54 defer { try? FileManager.default.removeItem(at: url) } 55 56 #expect(makeService().importGame(from: url) == nil) 57 } 58 }