Files
rickyandClaude Opus 5.5 03b9ad65cb Workflow polish: setup checklist, next leg, grouped component limits
- Setup checklist on a new aircraft's Overview (owners): components,
  standard inspections, DRS AD import, registration/airworthiness
  certificate, weight and balance; hideable per device
- Log Flight: "Save and log next leg" reopens the form on the same date,
  starting where the leg ended
- Component form: limits in two collapsible groups (replacement and expiry;
  overhaul and TBO), open when in use
- Squawk form warns what "Ground Aircraft" does
- Logbook entry form: inspection result only for inspection entries
  (show-when controller); document names default from the file
- Dates in pickers, the activity log, airworthiness lines, search, audits
  and transcription notes use the app format
- No duplicate Report Squawk button on Squawks; "Record service" label

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 07:43:03 -05:00

71 lines
3.4 KiB
Ruby

require "test_helper"
class UserCertificatesTest < ActionDispatch::IntegrationTest
include ActionMailer::TestHelper
setup do
@owner = create_user("owner@example.com")
@owner.update!(name: "Sam Mechanic")
@a = create_aircraft(owner: @owner, tail_number: "N12345")
end
test "users add and remove their own certificates" do
sign_in @owner
get edit_profile_path
assert_select "#certificates select[name='user_certificate[kind]'] option[value=IA]"
post certificates_path, params: { user_certificate: { kind: "AP", number: " 7654321 " } }
post certificates_path, params: { user_certificate: { kind: "IA", number: "7654321", expires_on: "2027-03-31" } }
post certificates_path, params: { user_certificate: { kind: "BOGUS", number: "" } }
assert_match "Certificate not added", flash[:alert]
assert_equal [ [ "IA", "7654321" ], [ "AP", "7654321" ] ], @owner.certificates.reload.map { [ _1.kind, _1.number ] } # IA first
other = create_user("other@example.com")
theirs = other.certificates.create!(kind: "PILOT", number: "1111111")
delete certificate_path(theirs)
assert_response :not_found
delete certificate_path(@owner.certificates.find_by!(kind: "AP"))
assert_equal [ "IA" ], @owner.certificates.reload.map(&:kind)
sign_in create_user("admin@example.com", admin: true)
get admin_users_path
assert_includes response.body, "IA 7654321"
end
test "Sign as fills the logbook entry and squawk resolution from the user's certificates" do
@owner.certificates.create!(kind: "AP", number: "7654321")
@owner.certificates.create!(kind: "IA", number: "7654321", expires_on: 1.day.ago.to_date) # expired: not offered
sign_in @owner
get new_aircraft_logbook_entry_path(@a)
assert_select "form[data-controller~=signer]"
assert_select "select[data-signer-target=choice] option[data-kind=AP][data-number='7654321'][data-name='Sam Mechanic']"
assert_select "select[data-signer-target=choice] option[data-kind=IA]", 0
assert_select "input[name='logbook_entry[signoff_person]'][data-signer-target=name]"
assert_select "select[name='logbook_entry[signoff_certificate_type]'][data-signer-target=kind][data-entry-template-target=certificate]"
squawk = @a.squawks.create!(priority: 1, issue_reported: "Nav light out")
get resolution_aircraft_squawk_path(@a, squawk)
assert_select "[data-controller='signer component-times'] select[data-signer-target=choice]"
get deferral_aircraft_squawk_path(@a, squawk)
assert_select "select[name=deferred_by_role] option[selected][value=mechanic]"
nobody = create_user
@a.roles.create!(user: nobody, role: "owner")
sign_in nobody
get new_aircraft_logbook_entry_path(@a)
assert_select "select[data-signer-target=choice]", 0 # no certificates, no picker
end
test "an expiring certificate is in the weekly reminder, even with nothing else due" do
@owner.certificates.create!(kind: "IA", number: "7654321", expires_on: 30.days.from_now.to_date)
@owner.certificates.create!(kind: "PILOT", number: "1111111", expires_on: 2.years.ago.to_date) # long lapsed: not repeated
assert_emails 1 do
WeeklyReminderJob.perform_now
end
mail = ActionMailer::Base.deliveries.last
assert_equal "Certificate expiring", mail.subject
body = mail.text_part.body.to_s
assert_includes body, "A&P with Inspection Authorization 7654321"
refute_includes body, "1111111"
end
end