• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / pdc_discovery / 529bb1cf-d0bf-4901-97c6-12679aea8117

17 Aug 2023 01:30PM UTC coverage: 90.265% (-6.3%) from 96.544%
529bb1cf-d0bf-4901-97c6-12679aea8117

Pull #478

circleci

carolyncole
Updates to css to fix tests after bundle update
Also ran rubocop -A && Prettier
Pull Request #478: Switching to selenium to fix CI

2 of 2 new or added lines in 2 files covered. (100.0%)

2142 of 2373 relevant lines covered (90.27%)

93.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.41
/spec/lib/dspace_research_data_harvester_spec.rb
1
# frozen_string_literal: true
2

3
RSpec.describe DspaceResearchDataHarvester do
1✔
4
  let(:rdh) { described_class.new }
2✔
5

6
  it "has a list of collections to index" do
1✔
7
    expect(rdh.collections_to_index.count).to eq 34
1✔
8
  end
9

10
  it "has a convenience method for indexing all collections" do
1✔
11
    expect_any_instance_of(described_class).to receive(:harvest).exactly(34).times
1✔
12
    described_class.harvest(true)
1✔
13
  end
14

15
  context "harvesting a collection" do
1✔
16
    let(:csv_data) do
1✔
17
      {
×
18
        "ParentCommunity" => "Princeton Plasma Physics Laboratory",
19
        "Community" => "Spherical Torus",
20
        "CollectionName" => "NSTX",
21
        "Handle" => "88435/dsp018p58pg29j",
22
        "CollectionID" => "1282",
23
        "ItemCount" => "33",
24
        nil => nil
25
      }
26
    end
27
    let(:csv_row) { CSV::Row.new(csv_data.keys, csv_data.values) }
1✔
28
    let(:rdc) { ResearchDataCollection.new(csv_row) }
1✔
29
    let(:collection_1282_xml) { File.read(File.join(fixture_path, 'spherical_torus.xml')) }
6✔
30
    let(:dspace_1308_items) { File.read(File.join(fixture_path, "migration", "1308_items.xml")) }
1✔
31
    let(:dspace_3386_items) { File.read(File.join(fixture_path, "migration", "3386_items.xml")) }
1✔
32

33
    before do
1✔
34
      Blacklight.default_index.connection.delete_by_query("*:*")
5✔
35
      Blacklight.default_index.connection.commit
5✔
36

37
      stub_request(:get, "https://dataspace-dev.princeton.edu/rest/collections/1282/items?expand=all&limit=100&offset=0")
5✔
38
        .with(
39
          headers: {
40
            'Accept' => 'application/xml'
41
          }
42
        )
43
        .to_return(status: 200, body: collection_1282_xml, headers: {})
44

45
      stub_request(:get, "https://dataspace.princeton.edu/rest/collections/1308/items")
×
46
        .with(
47
          headers: {
48
            'Accept' => 'application/xml'
49
          }
50
        )
51
        .to_return(status: 200, body: dspace_1308_items, headers: {})
52

53
      stub_request(:get, "https://dataspace.princeton.edu/rest/collections/3386/items")
×
54
        .with(
55
        headers: {
56
          'Accept' => 'application/xml'
57
        }
58
      )
59
        .to_return(status: 200, body: dspace_3386_items, headers: {})
60
    end
61

62
    it "retrieves data from dspace and indexes it to solr" do
1✔
63
      response = Blacklight.default_index.connection.get 'select', params: { q: '*:*' }
×
64
      expect(response["response"]["numFound"]).to eq 0
×
65

66
      rdh.harvest(rdc)
×
67

68
      response = Blacklight.default_index.connection.get 'select', params: { q: '*:*' }
×
69
      expect(response["response"]["numFound"]).to eq 32
×
70
    end
71

72
    context "migration tracking" do
1✔
73
      let(:shortened_collections_csv) { File.join(fixture_path, 'migration', 'collections.csv') }
1✔
74
      let(:tracking_csv) { File.join(fixture_path, "migration", 'dspace_migration.csv') }
1✔
75

76
      require 'csv'
1✔
77

78
      before do
1✔
79
        File.delete(tracking_csv) if File.exist? tracking_csv
×
80
        # Run migration queries against production, which is the only place all of this data exists
81
        allow(rdh).to receive(:server) { "https://dataspace.princeton.edu/rest" }
×
82
      end
83

84
      # The data for this comes from here: https://dataspace.princeton.edu/rest/collections/1308/items
85
      it "takes a dspace collection_id and produces a CSV file" do
1✔
86
        CSV.open(tracking_csv, "a") do |csv|
×
87
          csv << rdh.migration_csv_headers
×
88
        end
89
        collection = rdh.collections_to_index[2]
×
90
        rdh.produce_migration_spreadsheet(
×
91
                                          collection.parent_community,
92
                                          collection.community,
93
                                          collection.collection_name,
94
                                          collection.collection_id,
95
                                          tracking_csv
96
                                        )
97
        csv = CSV.parse(File.read(tracking_csv), headers: true)
×
98
        expect(csv[0]["title"]).to eq "Geometric concepts for stellarator permanent magnet arrays"
×
99
        expect(csv[0]["handle"]).to eq "88435/dsp01db78tg01d"
×
100
      end
101

102
      context "parent_community in a migration CSV" do
1✔
103
        let(:three_levels) { ["Princeton Plasma Physics Laboratory", "Advanced Projects", "Stellerators"] }
1✔
104
        let(:two_levels) { ["NA", "Princeton Plasma Physics Laboratory", "Plasma Science & Technology"] }
1✔
105
        it "is correct when there are three levels of hierarchy" do
1✔
106
          expect(rdh.csv_communities(three_levels)).to eq three_levels
×
107
        end
108
        it "is correct when there are two levels of hierarchy" do
1✔
109
          expect(rdh.csv_communities(two_levels)).to eq ["Princeton Plasma Physics Laboratory", "Plasma Science & Technology", ""]
×
110
        end
111
      end
112

113
      it "produces a CSV file for all items that need migration" do
1✔
114
        rdh.produce_full_migration_spreadsheet(tracking_csv, shortened_collections_csv)
×
115
        csv = CSV.parse(File.read(tracking_csv), headers: true)
×
116
        expect(csv[0]["title"]).to eq "Hyperdiffusion of dust particles in a turbulent tokamak plasma"
×
117
        expect(csv[7]["title"]).to eq "A novel scheme for error field correction in permanent magnet stellarators"
×
118
      end
119
    end
120
  end
121
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc