|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require_relative "../../app/lib/mavis_cli" |
| 4 | + |
| 5 | +describe "mavis generate consents" do |
| 6 | + it "generates consents" do |
| 7 | + given_an_organisation_exists |
| 8 | + and_there_are_three_patients_in_a_session |
| 9 | + when_i_run_the_generate_consents_command |
| 10 | + then_consents_are_created_with_the_given_statuses |
| 11 | + end |
| 12 | + |
| 13 | + def given_an_organisation_exists |
| 14 | + @organisation = create(:organisation) |
| 15 | + @programme = create(:programme, type: "hpv") |
| 16 | + end |
| 17 | + |
| 18 | + def and_there_are_three_patients_in_a_session |
| 19 | + @session = |
| 20 | + create(:session, organisation: @organisation, programmes: [@programme]) |
| 21 | + parent = create(:parent) |
| 22 | + create_list( |
| 23 | + :patient, |
| 24 | + 3, |
| 25 | + organisation: @organisation, |
| 26 | + session: @session, |
| 27 | + programmes: [@programme], |
| 28 | + parents: [parent] |
| 29 | + ) |
| 30 | + end |
| 31 | + |
| 32 | + def when_i_run_the_generate_consents_command |
| 33 | + @consent_count_before = @organisation.consents.count |
| 34 | + |
| 35 | + Dry::CLI.new(MavisCLI).call( |
| 36 | + arguments: [ |
| 37 | + "generate", |
| 38 | + "consents", |
| 39 | + "-o", |
| 40 | + @organisation.ods_code.to_s, |
| 41 | + "-p", |
| 42 | + @programme.type, |
| 43 | + "-s", |
| 44 | + @session.id.to_s, |
| 45 | + "-g", |
| 46 | + "1", |
| 47 | + "-N", |
| 48 | + "1", |
| 49 | + "-r", |
| 50 | + "1" |
| 51 | + ] |
| 52 | + ) |
| 53 | + end |
| 54 | + |
| 55 | + def then_consents_are_created_with_the_given_statuses |
| 56 | + expect(@organisation.consents.count).to eq @consent_count_before + 3 |
| 57 | + |
| 58 | + expect( |
| 59 | + @organisation |
| 60 | + .patient_sessions |
| 61 | + .has_consent_status(:given, programme: @programme) |
| 62 | + .has_triage_status(:not_required, programme: @programme) |
| 63 | + .count |
| 64 | + ).to eq 1 |
| 65 | + end |
| 66 | +end |
0 commit comments