mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
- Squawks: defer an inoperative item under 91.213(d) once each condition is confirmed (pilots may too); deferred items stop grounding and are listed for awareness. Resolving can record the fix as a logbook entry (43.9 fields) or link an existing one - Expiration dates on components (ELT battery, 91.207(c)) and documents; new document types (registration, airworthiness certificate, insurance, radio license). Expired replacement-critical parts and an expired registration (91.203) ground; others warn; registration warns 90 days out - Standard inspections: one click adds annual, 100-hour, 91.411, 91.413, ELT (91.207(d)) and VOR (91.171) checks with the right rules, skipping ones already tracked and linking annual to 100-hour - Weekly Monday reminder email to owners when something needs attention; profile opt-out; admin "send me this week's reminder" - README feature table updated Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
73 lines
3.8 KiB
Ruby
73 lines
3.8 KiB
Ruby
require "test_helper"
|
|
|
|
# Deferring inoperative equipment (91.213(d)) and recording a squawk's fix
|
|
# in the logbook (43.9).
|
|
class SquawkWorkflowTest < ActionDispatch::IntegrationTest
|
|
setup do
|
|
@owner = create_user("owner@example.com")
|
|
@pilot = create_user("pilot@example.com")
|
|
@a = create_aircraft(owner: @owner, pilot: @pilot)
|
|
@squawk = @a.squawks.create!(priority: 0, issue_reported: "Left landing light inop", reported_by: @pilot)
|
|
end
|
|
|
|
test "a pilot defers an inoperative item once every 91.213(d) condition is confirmed" do
|
|
assert @a.reload.airworthiness.red?
|
|
sign_in @pilot
|
|
get aircraft_squawks_path(@a)
|
|
assert_select "a[href='#{deferral_aircraft_squawk_path(@a, @squawk)}']", text: "Defer"
|
|
get deferral_aircraft_squawk_path(@a, @squawk)
|
|
assert_select "input[name='checks[]']", Squawk::DEFERRAL_CHECKS.size
|
|
|
|
patch defer_aircraft_squawk_path(@a, @squawk), params: { checks: Squawk::DEFERRAL_CHECKS.keys.first(3),
|
|
deferral_action: "deactivated", deferred_by_name: "Jane Pilot", deferred_by_role: "pilot" }
|
|
assert_response :unprocessable_entity
|
|
assert_includes response.body, "Confirm: A pilot or certificated mechanic has determined"
|
|
refute @squawk.reload.deferred?
|
|
|
|
patch defer_aircraft_squawk_path(@a, @squawk), params: { checks: Squawk::DEFERRAL_CHECKS.keys,
|
|
deferral_action: "deactivated", deferred_by_name: "Jane Pilot", deferred_by_role: "pilot", deferral_notes: "Breaker collared" }
|
|
assert_redirected_to aircraft_squawks_path(@a)
|
|
@squawk.reload
|
|
assert [ @squawk.deferred?, !@squawk.grounding? ].all?
|
|
assert_equal "Deferred (91.213(d))", @squawk.priority_label
|
|
aw = @a.reload.airworthiness
|
|
assert_equal "GREEN", aw.status # listed, but no longer grounding
|
|
assert_equal [ "INFO", "Inoperative: Left landing light inop" ], [ aw.issues.sole.severity, aw.issues.sole.title ]
|
|
|
|
patch undefer_aircraft_squawk_path(@a, @squawk) # only owners undo
|
|
assert @squawk.reload.deferred?
|
|
sign_in @owner
|
|
patch undefer_aircraft_squawk_path(@a, @squawk)
|
|
refute @squawk.reload.deferred?
|
|
assert @a.reload.airworthiness.red?
|
|
end
|
|
|
|
test "resolving records the fix as a logbook entry, links an existing one, or neither" do
|
|
sign_in @owner
|
|
get resolution_aircraft_squawk_path(@a, @squawk)
|
|
assert_select "textarea[name='logbook_entry[text]']", text: /Corrected: Left landing light inop/
|
|
|
|
patch resolve_aircraft_squawk_path(@a, @squawk), params: { logbook: "new", logbook_entry: {
|
|
date: "2026-11-01", log_type: "AC", text: "Replaced left landing light lamp P/N 4509", aircraft_hours_at_entry: 1000,
|
|
signoff_person: "Sam Mechanic", signoff_certificate_type: "AP", signoff_certificate_number: "7654321" } }
|
|
assert_redirected_to aircraft_squawks_path(@a)
|
|
entry = @squawk.reload.logbook_entry
|
|
assert @squawk.resolved?
|
|
assert_equal [ "MAINTENANCE", "AP", "7654321", [] ], [ entry.entry_type, entry.signoff_certificate_type, entry.signoff_certificate_number, entry.missing_record_items ]
|
|
get aircraft_squawks_path(@a)
|
|
assert_select "a[href='#{aircraft_logbook_entry_path(@a, entry)}']", text: "Logbook 2026-11-01"
|
|
|
|
other = @a.squawks.create!(priority: 2, issue_reported: "Chipped paint")
|
|
patch resolve_aircraft_squawk_path(@a, other), params: { logbook: "existing", logbook_entry_id: entry.id }
|
|
assert_equal entry, other.reload.logbook_entry
|
|
third = @a.squawks.create!(priority: 3, issue_reported: "Not a defect")
|
|
patch resolve_aircraft_squawk_path(@a, third), params: { logbook: "none", resolution_notes: "Normal for type" }
|
|
assert [ third.reload.resolved?, third.logbook_entry.nil? ].all?
|
|
|
|
bad = @a.squawks.create!(priority: 1, issue_reported: "Bad")
|
|
patch resolve_aircraft_squawk_path(@a, bad), params: { logbook: "new", logbook_entry: { date: "", text: "" } }
|
|
assert_response :unprocessable_entity
|
|
refute bad.reload.resolved?
|
|
end
|
|
end
|