|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'rails_helper' |
| 4 | +require 'byebug' |
| 5 | + |
| 6 | +# see https://relishapp.com/rspec/rspec-rails/v/3-8/docs/request-specs/request-spec |
| 7 | +# rubocop:disable Metrics/BlockLength |
| 8 | +module StashEngine |
| 9 | + RSpec.describe LandingController, type: :request do |
| 10 | + |
| 11 | + include MerrittHelper |
| 12 | + include DatasetHelper |
| 13 | + include DatabaseHelper |
| 14 | + include Mocks::Datacite |
| 15 | + include Mocks::Repository |
| 16 | + include Mocks::RSolr |
| 17 | + include Mocks::Ror |
| 18 | + include Mocks::Stripe |
| 19 | + |
| 20 | + before(:each) do |
| 21 | + # kind of crazy to mock all this, but creating identifiers and the curation activity of published triggers all sorts of stuff |
| 22 | + mock_repository! |
| 23 | + mock_solr! |
| 24 | + mock_ror! |
| 25 | + mock_datacite! |
| 26 | + mock_stripe! |
| 27 | + |
| 28 | + # below will create @identifier, @resource, @user and the basic required things for an initial version of a dataset |
| 29 | + create_basic_dataset! |
| 30 | + end |
| 31 | + |
| 32 | + it 'creates basic_dataset that is valid with required metadata with factory bot' do |
| 33 | + expect(@resource.identifier).to eq(@identifier) |
| 34 | + expect(@resource.authors.count.positive?).to eq(true) |
| 35 | + expect(@resource.descriptions).to have(1).items |
| 36 | + expect(@resource.authors.first.affiliations).to have(1).items |
| 37 | + expect(@resource.current_resource_state.resource_state).to eq('submitted') |
| 38 | + expect(@resource.curation_activities.last.status).to eq('submitted') |
| 39 | + expect(@resource.stash_version.version).to eq(1) |
| 40 | + expect(@resource.stash_version.merritt_version).to eq(1) |
| 41 | + expect(@resource.file_uploads).to have(1).item |
| 42 | + end |
| 43 | + |
| 44 | + it 'duplicates the basic dataset for version 2 with metadata' do |
| 45 | + duplicate_resource!(resource: @identifier.resources.last) |
| 46 | + @identifier.reload |
| 47 | + expect(@identifier.resources).to have(2).items |
| 48 | + res = @identifier.resources.last |
| 49 | + @identifier.reload |
| 50 | + expect(res.stash_version.version).to eq(2) |
| 51 | + expect(res.stash_version.merritt_version).to eq(2) |
| 52 | + # this file was copied over from a previous version and isn't a new file |
| 53 | + expect(res.file_uploads.first.file_state).to eq('copied') |
| 54 | + expect(res.file_uploads.first.upload_file_name).to eq(@resource.file_uploads.first.upload_file_name) |
| 55 | + end |
| 56 | + |
| 57 | + it "doesn't show a submitted but not embargoed/published version of the landing page" do |
| 58 | + get "/stash/dataset/#{@identifier}" |
| 59 | + expect(response).to have_http_status(:not_found) |
| 60 | + end |
| 61 | + |
| 62 | + it 'shows version of the dataset marked for metadata view' do |
| 63 | + # make first look embargoed and second isn't yet |
| 64 | + res = @identifier.resources.first |
| 65 | + res.update(meta_view: true, publication_date: Time.new + 1.day) |
| 66 | + @identifier.update(pub_state: 'embargoed') |
| 67 | + create(:curation_activity, status: 'embargoed', user_id: @user.id, resource_id: res.id) |
| 68 | + |
| 69 | + # 2nd resource not seen yet |
| 70 | + duplicate_resource!(resource: @identifier.resources.last) |
| 71 | + res2 = @identifier.resources.last |
| 72 | + res2.update(title: 'Treecats and friends') |
| 73 | + @identifier.reload |
| 74 | + |
| 75 | + get "/stash/dataset/#{@identifier}" |
| 76 | + expect(response.body).to include(res.title) |
| 77 | + expect(response.body).not_to include(res2.title) |
| 78 | + expect(response.body).to include('This dataset is embargoed') |
| 79 | + end |
| 80 | + |
| 81 | + it 'shows version of the dataset marked as published' do |
| 82 | + # make first look embargoed and second isn't yet |
| 83 | + res = @identifier.resources.first |
| 84 | + res.update(meta_view: true, file_view: true, publication_date: Time.new) |
| 85 | + @identifier.update(pub_state: 'published') |
| 86 | + create(:curation_activity, status: 'published', user_id: @user.id, resource_id: res.id) |
| 87 | + |
| 88 | + # 2nd resource not seen yet |
| 89 | + duplicate_resource!(resource: @identifier.resources.last) |
| 90 | + res2 = @identifier.resources.last |
| 91 | + res2.update(title: 'Treecats and friends') |
| 92 | + create(:file_upload, resource_id: res2.id, file_state: 'created') |
| 93 | + @identifier.reload |
| 94 | + |
| 95 | + get "/stash/dataset/#{@identifier}" |
| 96 | + expect(response.body).to include(res.title) |
| 97 | + expect(response.body).not_to include(res2.title) |
| 98 | + expect(response.body).not_to include('This dataset is embargoed') |
| 99 | + expect(response.body).to include(res.file_uploads.first.upload_file_name) |
| 100 | + # shows old file, but not new file that isn't published yet |
| 101 | + expect(response.body).not_to include(res2.file_uploads.where(file_state: 'created').first.upload_file_name) |
| 102 | + end |
| 103 | + |
| 104 | + end |
| 105 | +end |
| 106 | +# rubocop:enable Metrics/BlockLength |
0 commit comments