| 1 | import Foundation |
| 2 | import Testing |
| 3 | @testable import EquipoKit |
| 4 | #if os(macOS) |
| 5 | import AppKit |
| 6 | import SwiftUI |
| 7 | @testable import EquipoMac |
| 8 | #endif |
| 9 | |
| 10 | extension ProjectsReviewTests { |
| 11 | @Test func nextComposerSendClearsReleasedSelectionNotice() async throws { |
| 12 | let t = ScriptedTransport(); let s = try session(t) |
| 13 | t.on("POST /messages", .failure(.offline)) |
| 14 | s.projectCatalog.releaseSelection("gone") |
| 15 | #expect(s.projectCatalog.selectionNotice != nil) |
| 16 | await s.sendFromComposer("An ordinary request").value |
| 17 | #expect(s.projectCatalog.selectionNotice == nil) |
| 18 | #expect(try body(#require(t.sent("POST /messages").first))["project_id"] == nil) |
| 19 | #expect(s.outgoing.first?.state == .waiting) |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | extension ProjectsReviewTests { |
| 24 | @Test func onlyEquipoProjectNotFoundReleasesTheRetrySelection() async throws { |
| 25 | let cases: [(Int, String?, String?, String?, String?, Bool)] = [ |
| 26 | (404, "not_found", "api.not_found", "p_star", nil, true), |
| 27 | (404, "route_missing", "api.not_found", "p_star", nil, false), |
| 28 | (404, "not_found", "proxy.not_found", "p_star", nil, false), |
| 29 | (404, nil, nil, "p_star", nil, false), |
| 30 | (500, "not_found", "api.not_found", "p_star", nil, false), |
| 31 | (404, "not_found", "api.not_found", nil, nil, false), |
| 32 | (404, "not_found", "api.not_found", "p_star", "tk1", false), |
| 33 | ] |
| 34 | for (status, code, key, project, task, releases) in cases { |
| 35 | let t = ScriptedTransport(); let s = try session(t) |
| 36 | let route = task.map { "POST /tasks/\($0)/thread" } ?? "POST /messages" |
| 37 | let data = code.map { Data("{\"code\":\"\($0)\",\"copy_key\":\"\(key!)\",\"request_id\":\"r\"}".utf8) } ?? Data("Not found".utf8) |
| 38 | t.on(route, .success(APIResponse(status: status, data: data))) |
| 39 | await s.send("Fix it", inThreadOf: task, projectID: project) |
| 40 | let outgoing = try #require(s.outgoing.first) |
| 41 | #expect(outgoing.goneProject == releases, "status=\(status), code=\(code ?? "none"), key=\(key ?? "none"), task=\(task ?? "none")") |
| 42 | #expect((s.projectCatalog.selectionNotice != nil) == releases) |
| 43 | await s.retry(outgoing.id) |
| 44 | let sent = t.sent(route) |
| 45 | #expect(sent.count == 2) |
| 46 | #expect((sent[0].body == sent[1].body) == !releases) |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | |