import Foundation import Testing @testable import EquipoKit #if os(macOS) import AppKit import SwiftUI @testable import EquipoMac #endif extension ProjectsReviewTests { @Test func nextComposerSendClearsReleasedSelectionNotice() async throws { let t = ScriptedTransport(); let s = try session(t) t.on("POST /messages", .failure(.offline)) s.projectCatalog.releaseSelection("gone") #expect(s.projectCatalog.selectionNotice != nil) await s.sendFromComposer("An ordinary request").value #expect(s.projectCatalog.selectionNotice == nil) #expect(try body(#require(t.sent("POST /messages").first))["project_id"] == nil) #expect(s.outgoing.first?.state == .waiting) } } extension ProjectsReviewTests { @Test func onlyEquipoProjectNotFoundReleasesTheRetrySelection() async throws { let cases: [(Int, String?, String?, String?, String?, Bool)] = [ (404, "not_found", "api.not_found", "p_star", nil, true), (404, "route_missing", "api.not_found", "p_star", nil, false), (404, "not_found", "proxy.not_found", "p_star", nil, false), (404, nil, nil, "p_star", nil, false), (500, "not_found", "api.not_found", "p_star", nil, false), (404, "not_found", "api.not_found", nil, nil, false), (404, "not_found", "api.not_found", "p_star", "tk1", false), ] for (status, code, key, project, task, releases) in cases { let t = ScriptedTransport(); let s = try session(t) let route = task.map { "POST /tasks/\($0)/thread" } ?? "POST /messages" let data = code.map { Data("{\"code\":\"\($0)\",\"copy_key\":\"\(key!)\",\"request_id\":\"r\"}".utf8) } ?? Data("Not found".utf8) t.on(route, .success(APIResponse(status: status, data: data))) await s.send("Fix it", inThreadOf: task, projectID: project) let outgoing = try #require(s.outgoing.first) #expect(outgoing.goneProject == releases, "status=\(status), code=\(code ?? "none"), key=\(key ?? "none"), task=\(task ?? "none")") #expect((s.projectCatalog.selectionNotice != nil) == releases) await s.retry(outgoing.id) let sent = t.sent(route) #expect(sent.count == 2) #expect((sent[0].body == sent[1].body) == !releases) } } }