|
589 | 589 | describe 'POST #import_start' do
|
590 | 590 | let(:valid_file) { fixture_file_upload('proforma_import/testfile.zip', 'application/zip') }
|
591 | 591 | let(:invalid_file) { 'invalid_file' }
|
592 |
| - let(:mock_uploader) { instance_double(ProformaZipUploader) } |
593 | 592 | let(:uuid) { 'mocked-uuid' }
|
594 | 593 | let(:post_request) { post :import_start, params: {file: file} }
|
595 | 594 | let(:file) { valid_file }
|
596 | 595 |
|
597 | 596 | before do
|
598 | 597 | allow(controller).to receive(:current_user).and_return(user)
|
599 |
| - allow(ProformaZipUploader).to receive(:new).and_return(mock_uploader) |
600 | 598 | end
|
601 | 599 |
|
602 | 600 | context 'when the file is valid' do
|
603 | 601 | before do
|
604 | 602 | allow(ProformaService::UuidFromZip).to receive(:call).and_return(uuid)
|
605 |
| - allow(mock_uploader).to receive(:cache!) |
606 |
| - allow(mock_uploader).to receive(:cache_name).and_return('mocked-cache-name') |
| 603 | + end |
| 604 | + |
| 605 | + it 'saves the file to the server' do |
| 606 | + expect { post_request }.to change(ActiveStorage::Blob, :count).by(1) |
607 | 607 | end
|
608 | 608 |
|
609 | 609 | context 'when the exercise exists and is updatable' do
|
|
658 | 658 | context 'when the file is invalid' do
|
659 | 659 | let(:file) { invalid_file }
|
660 | 660 |
|
| 661 | + it 'does not save the file to the server' do |
| 662 | + expect { post_request }.not_to change(ActiveStorage::Blob, :count) |
| 663 | + end |
| 664 | + |
661 | 665 | it 'renders failure JSON with correct error' do
|
662 | 666 | post_request
|
663 | 667 |
|
|
685 | 689 |
|
686 | 690 | describe 'POST #import_confirm' do
|
687 | 691 | let(:file_id) { 'file_id' }
|
688 |
| - let(:mock_uploader) { instance_double(ProformaZipUploader, file: 'mocked_file') } |
689 | 692 | let(:post_request) { post :import_confirm, params: {file_id: file_id} }
|
690 | 693 |
|
691 |
| - before do |
692 |
| - allow(ProformaZipUploader).to receive(:new).and_return(mock_uploader) |
693 |
| - end |
694 |
| - |
695 | 694 | context 'when the import is successful' do
|
696 | 695 | before do
|
697 |
| - allow(mock_uploader).to receive(:retrieve_from_cache!).with(file_id) |
698 | 696 | allow(ProformaService::Import).to receive(:call).with(zip: 'mocked_file', user: user).and_return(exercise)
|
699 | 697 | allow(exercise).to receive(:save!).and_return(true)
|
700 | 698 | end
|
|
711 | 709 |
|
712 | 710 | context 'when ProformaError or validation error occurs' do
|
713 | 711 | before do
|
714 |
| - allow(mock_uploader).to receive(:retrieve_from_cache!).with(file_id) |
715 | 712 | allow(ProformaService::Import).to receive(:call).and_raise(ProformaXML::ProformaError, 'Proforma error')
|
716 | 713 | end
|
717 | 714 |
|
|
727 | 724 |
|
728 | 725 | context 'when StandardError occurs' do
|
729 | 726 | before do
|
730 |
| - allow(mock_uploader).to receive(:retrieve_from_cache!).and_raise(StandardError, 'Unexpected error') |
731 | 727 | allow(Sentry).to receive(:capture_exception)
|
732 | 728 | end
|
733 | 729 |
|
|
0 commit comments