ForgejoKit/Tests/ForgejoKitTests/UserServiceTests.swift
Stefan Hausotte b78c57ffd9 feat: add Attachment model and image upload support
- Add Attachment model with isImage computed property
- Add assets field to Issue, IssueComment, and PullRequest
- Add multipart/form-data upload support to ForgejoClient
- Add uploadIssueAttachment and uploadCommentAttachment to IssueService
2026-06-15 09:48:47 +02:00

29 lines
1.4 KiB
Swift

@testable import ForgejoKit
import Foundation
import Testing
struct UserServiceTests {
@Test func `create token payload encodes correct keys`() throws {
let payload: [String: Any] = [
"name": "integration-test-token",
"scopes": ["read:user", "write:user"],
]
let data = try JSONSerialization.data(withJSONObject: payload)
let dict = try #require(JSONSerialization.jsonObject(with: data) as? [String: Any])
#expect(dict["name"] as? String == "integration-test-token")
#expect((dict["scopes"] as? [String])?.count == 2)
}
@Test func `create token URL construction`() throws {
let client = ForgejoClient(serverURL: "https://forgejo.example.com", username: "admin", password: "pass")
let url = try client.makeURL(path: "/api/v1/users/\(ForgejoClient.encodedPathSegment("testuser"))/tokens")
#expect(url.absoluteString == "https://forgejo.example.com/api/v1/users/testuser/tokens")
}
@Test func `create token URL encodes special characters`() throws {
let client = ForgejoClient(serverURL: "https://forgejo.example.com", username: "admin", password: "pass")
let encoded = ForgejoClient.encodedPathSegment("user name")
let url = try client.makeURL(path: "/api/v1/users/\(encoded)/tokens")
#expect(url.absoluteString.contains("user%20name"))
}
}