| 1 | import Foundation |
| 2 | import Testing |
| 3 | @testable import EquipoActivity |
| 4 | @testable import EquipoKit |
| 5 | |
| 6 | /// A step Design makes is Engineering's kind with a maker (wire.Maker): |
| 7 | /// the apps name it Design, never Engineering; a plain step keeps its kind. |
| 8 | @MainActor struct MakerTests { |
| 9 | static func step(maker: String) -> String { |
| 10 | """ |
| 11 | {"id":"s1","specialist":"engineering","state":"running","reason":"","summary":"","headline":"","verdict":"","review_label":"","checks":"","gate":"","exit_code":null,"started_at":null,"finished_at":null\(maker)} |
| 12 | """ |
| 13 | } |
| 14 | |
| 15 | @Test func aDesignStepIsDesign() throws { |
| 16 | let step = try EquipoJSON.decoder.decode(ThinStep.self, from: Data(Self.step(maker: #","maker":{"id":"sp1","profile":"design-v1"}"#).utf8)) |
| 17 | #expect(step.maker == ThinMaker(id: "sp1", profile: "design-v1")) |
| 18 | #expect(step.who == "design") |
| 19 | #expect(Specialist(category: step.who) == .design) |
| 20 | } |
| 21 | |
| 22 | @Test func aPlainStepKeepsItsKind() throws { |
| 23 | let step = try EquipoJSON.decoder.decode(ThinStep.self, from: Data(Self.step(maker: "").utf8)) |
| 24 | #expect(step.maker == nil) |
| 25 | #expect(Specialist(category: step.who) == .engineering) |
| 26 | #expect(ThinMaker(id: "sp2", profile: "research-v1").category == "research") |
| 27 | } |
| 28 | |
| 29 | /// Design's first attempt failed: no running or finished step, so the |
| 30 | /// card names the task's maker, not Engineering. |
| 31 | @Test func aFailedFirstDesignAttemptIsStillDesign() throws { |
| 32 | let failed = Self.step(maker: #","maker":{"id":"sp1","profile":"design-v1"}"#).replacingOccurrences(of: #""state":"running""#, with: #""state":"failed""#) |
| 33 | let json = """ |
| 34 | {"id":"tk1","revision":3,"project_id":"p_1","project":"Shop","title":"Overhaul the shop design","brief":"","stage":"in_progress","branch":"","url":"","candidate_sha":"","checks":"","checks_reason":"","verdict":"","review_label":"","needs_you":"","creator":"paul@example.com","created_at":"2026-11-24T09:00:00Z","updated_at":"2026-11-24T09:00:00Z","maker":{"id":"sp1","profile":"design-v1"},"steps":[\(failed)]} |
| 35 | """ |
| 36 | let task = try EquipoJSON.decoder.decode(ThinTask.self, from: Data(json.utf8)) |
| 37 | #expect(TaskReport(task, needsYou: false).specialist == .design) |
| 38 | } |
| 39 | } |
| 40 | |