|
4 | 4 | require 'stub_helper' |
5 | 5 | require 'nokogiri' |
6 | 6 |
|
7 | | -# rubocop :disable Lint/ConstantDefinitionInBlock, Style/MutableConstant |
| 7 | +# rubocop :disable Lint/ConstantDefinitionInBlock, Style/MutableConstant, Metrics/BlockLength: |
8 | 8 | describe SIS do |
9 | | - it 'runs sis' do |
10 | | - # Make VERSION dynamic: |
11 | | - # Note - applicaiton_version is set in config/settings.yml: applicaiton_version |
12 | | - expected_version = (ENV['VERSION'] || '1.0.0').to_s |
| 9 | + describe '#run_sis' do |
| 10 | + it 'runs sis' do |
| 11 | + # Make VERSION dynamic: |
| 12 | + # Note - applicaiton_version is set in config/settings.yml: applicaiton_version |
| 13 | + expected_version = (ENV['VERSION'] || '1.0.0').to_s |
13 | 14 |
|
14 | | - expected_file = File.read('spec/data/sis/expected_xml_3.xml') |
| 15 | + expected_file = File.read('spec/data/sis/expected_xml_3.xml') |
15 | 16 |
|
16 | | - allow(Date).to receive(:today).and_return Date.new(2022, 6, 1) |
17 | | - expected_file.gsub!(/<!-- VERSION: .+? -->/, "<!-- VERSION: #{expected_version} -->") |
| 17 | + allow(Date).to receive(:today).and_return Date.new(2022, 6, 1) |
| 18 | + expected_file.gsub!(/<!-- VERSION: .+? -->/, "<!-- VERSION: #{expected_version} -->") |
18 | 19 |
|
19 | | - term_id = '2222' |
20 | | - stub_past_sis_data(term_id, '2022-04-10', 1) |
21 | | - stub_past_sis_data(term_id, '2022-04-10', 2) |
22 | | - stub_sis_data(term_id, 1) |
23 | | - stub_sis_data(term_id, 2) |
| 20 | + term_id = '2222' |
| 21 | + stub_past_sis_data(term_id, '2022-04-10', 1) |
| 22 | + stub_past_sis_data(term_id, '2022-04-10', 2) |
| 23 | + stub_sis_data(term_id, 1) |
| 24 | + stub_sis_data(term_id, 2) |
| 25 | + |
| 26 | + Dir.mktmpdir do |dir| |
| 27 | + outpath = Pathname.new(dir) |
| 28 | + |
| 29 | + ARGV = ['--type', 'sis', '-s', '2022-04-10', '--term', '2222', '--outdir', outpath] |
| 30 | + setup = Helpers::Setup.new |
| 31 | + SIS.run_sis setup |
| 32 | + |
| 33 | + expect(File.exist?(setup.zip_path)).to eq(true) |
| 34 | + expect(File.read(setup.xml_path)).to eq(expected_file) |
| 35 | + end |
| 36 | + end |
| 37 | + |
| 38 | + it 'skips users listed in the SIS ignore file' do |
| 39 | + allow(Date).to receive(:today).and_return Date.new(2022, 6, 1) |
| 40 | + |
| 41 | + term_id = '2222' |
| 42 | + stub_past_sis_data(term_id, '2022-04-10', 1) |
| 43 | + stub_past_sis_data(term_id, '2022-04-10', 2) |
| 44 | + stub_sis_data(term_id, 1) |
| 45 | + stub_sis_data(term_id, 2) |
| 46 | + |
| 47 | + allow(SIS).to receive(:load_ignored_sis_ids).and_return(Set['10162050']) |
24 | 48 |
|
25 | | - Dir.mktmpdir do |dir| |
26 | | - outpath = Pathname.new(dir) |
| 49 | + Dir.mktmpdir do |dir| |
| 50 | + outpath = Pathname.new(dir) |
27 | 51 |
|
28 | | - ARGV = ['--type', 'sis', '-s', '2022-04-10', '--term', '2222', '--outdir', outpath] |
29 | | - setup = Helpers::Setup.new |
30 | | - SIS.run_sis setup |
| 52 | + ARGV = ['--type', 'sis', '-s', '2022-04-10', '--term', '2222', '--outdir', outpath] |
| 53 | + setup = Helpers::Setup.new |
| 54 | + |
| 55 | + SIS.run_sis(setup) |
| 56 | + |
| 57 | + xml = Nokogiri::XML(File.read(setup.xml_path)) |
| 58 | + primary_ids = xml.xpath('//user/primary_id').map(&:text) |
| 59 | + |
| 60 | + expect(primary_ids).not_to include('30012345') |
| 61 | + expect(primary_ids.length).to eq(1) |
| 62 | + end |
| 63 | + end |
| 64 | + end |
| 65 | + |
| 66 | + describe '.load_ignored_sis_ids' do |
| 67 | + it 'loads ignored sis ids from a text file' do |
| 68 | + Dir.mktmpdir do |dir| |
| 69 | + path = File.join(dir, 'sis_ignore_ids.txt') |
| 70 | + |
| 71 | + File.write(path, <<~TEXT) |
| 72 | + # Ignore these users |
| 73 | + 30000001 |
| 74 | +
|
| 75 | + 30000002 |
| 76 | + TEXT |
| 77 | + |
| 78 | + expect(SIS.load_ignored_sis_ids(path)).to eq(Set['30000001', '30000002']) |
| 79 | + end |
| 80 | + end |
31 | 81 |
|
32 | | - expect(File.exist?(setup.zip_path)).to eq(true) |
33 | | - expect(File.read(setup.xml_path)).to eq(expected_file) |
| 82 | + it 'returns an empty set when the file does not exist' do |
| 83 | + expect(SIS.load_ignored_sis_ids('does/not/exist.txt')).to eq(Set.new) |
34 | 84 | end |
35 | 85 | end |
36 | 86 | end |
37 | | -# rubocop :enable Lint/ConstantDefinitionInBlock, Style/MutableConstant |
| 87 | +# rubocop :enable Lint/ConstantDefinitionInBlock, Style/MutableConstant, Metrics/BlockLength: |
38 | 88 |
|
39 | 89 | # rubocop:disable Metrics/BlockLength |
40 | 90 | describe SIS::API do |
|
0 commit comments