From cd4e8b5d524350a52f1f1a64fa55d30943f5468e Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 25 May 2025 19:24:58 +0200 Subject: [PATCH] Final fixes for Swift tests to compile - Remove references to non-existent ServerStatus type - Fix ListCommandTests to use actual WindowsSubcommand properties - Update PermissionsCheckerTests to test actual error types - Remove tests for properties that don't exist in the implementation --- .../peekabooTests/ListCommandTests.swift | 20 +---- .../PermissionsCheckerTests.swift | 81 ++++++++----------- 2 files changed, 38 insertions(+), 63 deletions(-) diff --git a/peekaboo-cli/Tests/peekabooTests/ListCommandTests.swift b/peekaboo-cli/Tests/peekabooTests/ListCommandTests.swift index c8baba4..25b4ed5 100644 --- a/peekaboo-cli/Tests/peekabooTests/ListCommandTests.swift +++ b/peekaboo-cli/Tests/peekabooTests/ListCommandTests.swift @@ -30,32 +30,18 @@ final class ListCommandTests: XCTestCase { XCTAssertEqual(command.app, "Finder") XCTAssertFalse(command.jsonOutput) - XCTAssertFalse(command.includeOffScreen) - XCTAssertEqual(command.details, []) + XCTAssertNil(command.includeDetails) } func testWindowsSubcommandWithDetails() throws { // Test windows subcommand with detail options let command = try WindowsSubcommand.parse([ "--app", "Finder", - "--details", "bounds", - "--details", "ids" + "--include-details", "bounds,ids" ]) XCTAssertEqual(command.app, "Finder") - XCTAssertTrue(command.details.contains(.bounds)) - XCTAssertTrue(command.details.contains(.ids)) - } - - func testWindowsSubcommandWithOffScreen() throws { - // Test windows subcommand with off-screen option - let command = try WindowsSubcommand.parse([ - "--app", "Safari", - "--include-off-screen" - ]) - - XCTAssertEqual(command.app, "Safari") - XCTAssertTrue(command.includeOffScreen) + XCTAssertEqual(command.includeDetails, "bounds,ids") } // MARK: - Data Structure Tests diff --git a/peekaboo-cli/Tests/peekabooTests/PermissionsCheckerTests.swift b/peekaboo-cli/Tests/peekabooTests/PermissionsCheckerTests.swift index 1590bcf..c530ace 100644 --- a/peekaboo-cli/Tests/peekabooTests/PermissionsCheckerTests.swift +++ b/peekaboo-cli/Tests/peekabooTests/PermissionsCheckerTests.swift @@ -64,31 +64,24 @@ final class PermissionsCheckerTests: XCTestCase { // MARK: - Permission State Tests - func testPermissionStateEncoding() throws { - // Test that permission states can be properly encoded to JSON - let serverStatus = ServerStatus( - hasScreenRecordingPermission: true, - hasAccessibilityPermission: false - ) - - let encoder = JSONEncoder() - encoder.keyEncodingStrategy = .convertToSnakeCase - - let data = try encoder.encode(serverStatus) - let json = try JSONSerialization.jsonObject(with: data) as? [String: Any] - - XCTAssertNotNil(json) - XCTAssertEqual(json?["has_screen_recording_permission"] as? Bool, true) - XCTAssertEqual(json?["has_accessibility_permission"] as? Bool, false) + func testPermissionErrors() { + // Test permission error types + let screenError = PermissionError.screenRecordingDenied + let accessError = PermissionError.accessibilityDenied + + XCTAssertNotNil(screenError) + XCTAssertNotNil(accessError) } // MARK: - Error Handling Tests - func testPermissionDeniedError() { + func testCaptureError() { // Test error creation for permission denied let error = CaptureError.capturePermissionDenied - XCTAssertEqual(error.description, "Screen recording permission is required") + // CaptureError conforms to LocalizedError, so it has errorDescription + XCTAssertNotNil(error.errorDescription) + XCTAssertTrue(error.errorDescription?.contains("permission") ?? false) } // MARK: - Performance Tests @@ -101,33 +94,29 @@ final class PermissionsCheckerTests: XCTestCase { } } - // MARK: - Mock Tests (for CI/CD) - - func testMockPermissionScenarios() { - // Test various permission scenarios for error handling - - // Scenario 1: No permissions - var status = ServerStatus( - hasScreenRecordingPermission: false, - hasAccessibilityPermission: false - ) - XCTAssertFalse(status.hasScreenRecordingPermission) - XCTAssertFalse(status.hasAccessibilityPermission) - - // Scenario 2: Only screen recording - status = ServerStatus( - hasScreenRecordingPermission: true, - hasAccessibilityPermission: false - ) - XCTAssertTrue(status.hasScreenRecordingPermission) - XCTAssertFalse(status.hasAccessibilityPermission) - - // Scenario 3: Both permissions - status = ServerStatus( - hasScreenRecordingPermission: true, - hasAccessibilityPermission: true - ) - XCTAssertTrue(status.hasScreenRecordingPermission) - XCTAssertTrue(status.hasAccessibilityPermission) + // MARK: - Require Permission Tests + + func testRequireScreenRecordingPermission() { + // Test the require method - it should throw if permission is denied + do { + try PermissionsChecker.requireScreenRecordingPermission() + // If we get here, permission was granted + XCTAssertTrue(true) + } catch { + // If permission is denied, we should get CaptureError + XCTAssertTrue(error is CaptureError) + } + } + + func testRequireAccessibilityPermission() { + // Test the require method - it should throw if permission is denied + do { + try PermissionsChecker.requireAccessibilityPermission() + // If we get here, permission was granted + XCTAssertTrue(true) + } catch { + // If permission is denied, we should get CaptureError + XCTAssertTrue(error is CaptureError) + } } }