File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments