|
| 1 | +// SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 2 | +// SPDX-License-Identifier: LGPL-3.0-or-later |
| 3 | + |
| 4 | +@testable import NextcloudCapabilitiesKit |
| 5 | +import Testing |
| 6 | + |
| 7 | +@Suite("Client Integration App Tests") |
| 8 | +struct ClientIntegrationAppTests { |
| 9 | + @Test("Decode with double version") |
| 10 | + func decodeWithDoubleVersion() throws { |
| 11 | + let data: [String: Any] = [ |
| 12 | + "version": 1.2, |
| 13 | + "context-menu": [ |
| 14 | + [ |
| 15 | + "icon": "/apps/assistant/img/client_integration/summarize.svg", |
| 16 | + "method": "POST", |
| 17 | + "mimetype_filters": "text/, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.oasis.opendocument.text, application/pdf", |
| 18 | + "name": "Summarize using AI", |
| 19 | + "url": "/ocs/v2.php/apps/assistant/api/v1/file-action/{fileId}/core:text2text:summary" |
| 20 | + ] |
| 21 | + ] |
| 22 | + ] |
| 23 | + |
| 24 | + let result = ClientIntegrationApp(app: "example", data: data) |
| 25 | + #expect(result != nil) |
| 26 | + |
| 27 | + let app = try #require(result) |
| 28 | + |
| 29 | + // Verify identifier |
| 30 | + #expect(app.identifier == "example") |
| 31 | + |
| 32 | + // Verify version |
| 33 | + #expect(app.version == 1.2) |
| 34 | + } |
| 35 | + |
| 36 | + @Test("Decode with integer version") |
| 37 | + func decodeWithIntegerVersion() throws { |
| 38 | + let data: [String: Any] = [ |
| 39 | + "version": 2, |
| 40 | + "context-menu": [] |
| 41 | + ] |
| 42 | + |
| 43 | + let result = ClientIntegrationApp(app: "test-app", data: data) |
| 44 | + #expect(result != nil) |
| 45 | + |
| 46 | + let app = try #require(result) |
| 47 | + |
| 48 | + // Verify integer version is converted to double |
| 49 | + #expect(app.version == 2.0) |
| 50 | + #expect(app.identifier == "test-app") |
| 51 | + #expect(app.contextMenuItems.isEmpty) |
| 52 | + } |
| 53 | + |
| 54 | + // MARK: - Negative Tests |
| 55 | + |
| 56 | + @Test("Decode fails with missing version") |
| 57 | + func decodeFailsWithMissingVersion() { |
| 58 | + let data: [String: Any] = [ |
| 59 | + "context-menu": [] |
| 60 | + ] |
| 61 | + |
| 62 | + let result = ClientIntegrationApp(app: "no-version", data: data) |
| 63 | + #expect(result == nil) |
| 64 | + } |
| 65 | + |
| 66 | + @Test("Decode fails with invalid version type") |
| 67 | + func decodeFailsWithInvalidVersionType() { |
| 68 | + let data: [String: Any] = [ |
| 69 | + "version": "1.2.3", |
| 70 | + "context-menu": [] |
| 71 | + ] |
| 72 | + |
| 73 | + let result = ClientIntegrationApp(app: "invalid-version", data: data) |
| 74 | + #expect(result == nil) |
| 75 | + } |
| 76 | + |
| 77 | + @Test("Decode fails with missing context-menu") |
| 78 | + func decodeFailsWithMissingContextMenu() { |
| 79 | + let data: [String: Any] = [ |
| 80 | + "version": 1.0 |
| 81 | + ] |
| 82 | + |
| 83 | + let result = ClientIntegrationApp(app: "no-context-menu", data: data) |
| 84 | + #expect(result == nil) |
| 85 | + } |
| 86 | + |
| 87 | + @Test("Decode fails with invalid context-menu type") |
| 88 | + func decodeFailsWithInvalidContextMenuType() { |
| 89 | + let data: [String: Any] = [ |
| 90 | + "version": 1.0, |
| 91 | + "context-menu": "not an array" |
| 92 | + ] |
| 93 | + |
| 94 | + let result = ClientIntegrationApp(app: "invalid-context-menu", data: data) |
| 95 | + #expect(result == nil) |
| 96 | + } |
| 97 | +} |
0 commit comments