ForgejoKit/Tests/ForgejoKitTests/AdminServiceTests.swift
Stefan Hausotte 0c2fc12ded feat: add new models and services
New model:
  - Token — id, name, sha1, tokenLastEight

New services:
  - AdminService — createUser()
  - UserService — createToken()

RepositoryService additions:
  - createRepository()
  - editRepository()
  - createLabel()
  - createMilestone()
  - addCollaborator()
  - createFile()

remove MARKS
2026-03-11 21:57:40 +01:00

36 lines
1.3 KiB
Swift

import Foundation
import Testing
@testable import ForgejoKit
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)
let dict = try 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")
}
}