Skip to content

Commit afb2368

Browse files
committed
Add spec for cli generate cohort-import
These were missing, but they're useful to ensure the cli command continues to work.
1 parent 57ede3c commit afb2368

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# frozen_string_literal: true
2+
3+
describe "mavis generate cohort-imports" do
4+
it "generates a cohort import CSV file" do
5+
given_an_organisation_exists
6+
and_there_are_three_sessions_in_the_organisation
7+
when_i_run_the_generate_cohort_imports_command
8+
then_a_cohort_import_csv_file_is_created
9+
end
10+
11+
def given_an_organisation_exists
12+
@programme = Programme.hpv.first || create(:programme, :hpv)
13+
@organisation = create(:organisation, ods_code: "R1Y")
14+
end
15+
16+
def and_there_are_three_sessions_in_the_organisation
17+
@sessions =
18+
create_list(
19+
:session,
20+
3,
21+
organisation: @organisation,
22+
programmes: [@programme]
23+
)
24+
end
25+
26+
def when_i_run_the_generate_cohort_imports_command
27+
freeze_time do
28+
@output =
29+
capture_output do
30+
Dry::CLI.new(MavisCLI).call(
31+
arguments: %w[generate cohort-imports -o R1Y -p 100]
32+
)
33+
end
34+
@timestamp = Time.current.strftime("%Y%m%d%H%M%S")
35+
end
36+
end
37+
38+
def then_a_cohort_import_csv_file_is_created
39+
expect(@output).to include(
40+
"Generating cohort import for ods code R1Y with 100 patients"
41+
)
42+
expect(@output).to match(
43+
/Cohort import CSV generated:.*cohort-import-R1Y-hpv-100-#{@timestamp}.csv/
44+
)
45+
46+
expect(
47+
File.readlines(
48+
Rails.root.join("tmp", "cohort-import-R1Y-hpv-100-#{@timestamp}.csv")
49+
).length
50+
).to eq 101
51+
end
52+
end

0 commit comments

Comments
 (0)