|
861 | 861 | end
|
862 | 862 | end
|
863 | 863 | end
|
| 864 | + describe '#get_docs' do |
| 865 | + let(:submission_id) { 1 } |
| 866 | + let(:uuid) { 'some-uuid' } |
| 867 | + let(:submission) { build(:form526_submission, id: submission_id) } |
| 868 | + let(:parsed_forms) do |
| 869 | + { |
| 870 | + 'form0781' => { 'content_0781' => 'value_0781' }, |
| 871 | + 'form0781a' => { 'content_0781a' => 'value_0781a' }, |
| 872 | + 'form0781v2' => nil |
| 873 | + } |
| 874 | + end |
| 875 | + |
| 876 | + before do |
| 877 | + allow(Form526Submission).to receive(:find_by).with(id: submission_id).and_return(submission) |
| 878 | + allow_any_instance_of(described_class).to receive(:parsed_forms).and_return(parsed_forms) |
| 879 | + allow_any_instance_of(described_class).to receive(:process_0781).and_return('file_path') # rubocop:disable Naming/VariableNumber |
| 880 | + end |
| 881 | + |
| 882 | + it 'returns the correct file type and file objects' do |
| 883 | + result = subject.new.get_docs(submission_id, uuid) |
| 884 | + |
| 885 | + expect(result).to eq([ |
| 886 | + { type: described_class::FORM_ID_0781, |
| 887 | + file: 'file_path' }, |
| 888 | + { type: described_class::FORM_ID_0781A, |
| 889 | + file: 'file_path' } |
| 890 | + ]) |
| 891 | + end |
| 892 | + |
| 893 | + it 'does not include forms with no content' do |
| 894 | + result = subject.new.get_docs(submission_id, uuid) |
| 895 | + |
| 896 | + expect(result).not_to include({ type: described_class::FORM_ID_0781V2, |
| 897 | + file: 'file_path' }) |
| 898 | + end |
| 899 | + |
| 900 | + it 'correctly discerns whether to process a 0781 or 0781a' do |
| 901 | + expect_any_instance_of(described_class).to receive(:process_0781).with(uuid, described_class::FORM_ID_0781, # rubocop:disable Naming/VariableNumber |
| 902 | + parsed_forms['form0781'], upload: false) |
| 903 | + expect_any_instance_of(described_class).to receive(:process_0781).with(uuid, described_class::FORM_ID_0781A, # rubocop:disable Naming/VariableNumber |
| 904 | + parsed_forms['form0781a'], upload: false) |
| 905 | + expect_any_instance_of(described_class).not_to receive(:process_0781).with(uuid, # rubocop:disable Naming/VariableNumber |
| 906 | + described_class::FORM_ID_0781V2, |
| 907 | + parsed_forms['form0781v2'], |
| 908 | + upload: false) |
| 909 | + subject.new.get_docs(submission_id, uuid) |
| 910 | + end |
| 911 | + end |
864 | 912 | end
|
0 commit comments