ForgejoKit/Tests/ForgejoKitTests/AdminServiceTests.swift

36 lines
1.3 KiB
Swift
Raw Normal View History

2026-06-04 02:29:23 -07:00
@testable import ForgejoKit
import Foundation
import Testing
struct AdminServiceTests {
@Test func createUserPayloadEncodesCorrectKeys() throws {
let json = """
{
"username": "testbot",
"password": "testbot1234",
"email": "testbot@test.local",
"login_name": "testbot",
"full_name": "Test Bot",
"must_change_password": false,
"send_notify": false,
"source_id": 0,
"visibility": "public"
}
"""
let data = Data(json.utf8)
2026-06-04 02:29:23 -07:00
let dict = try #require(JSONSerialization.jsonObject(with: data) as? [String: Any])
#expect(dict["username"] as? String == "testbot")
#expect(dict["login_name"] as? String == "testbot")
#expect(dict["must_change_password"] as? Bool == false)
#expect(dict["send_notify"] as? Bool == false)
#expect(dict["source_id"] as? Int == 0)
#expect(dict["visibility"] as? String == "public")
}
@Test func createUserURLConstruction() throws {
let client = ForgejoClient(serverURL: "https://forgejo.example.com", username: "admin", password: "pass")
let url = try client.makeURL(path: "/api/v1/admin/users")
#expect(url.absoluteString == "https://forgejo.example.com/api/v1/admin/users")
}
}