Skip to content

Commit

Permalink
Merge pull request #125 from datacite/add-specs-for-funder-identifier
Browse files Browse the repository at this point in the history
add specs for funder identifier
  • Loading branch information
wendelfabianchinsamy authored Nov 16, 2023
2 parents d44ede6 + af78bc9 commit 652959f
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 2 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

114 changes: 114 additions & 0 deletions spec/lib/tasks/funder_identifier_rake_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,117 @@
expect(enqueued_jobs.last[:job]).to be(FunderIdentifierImportJob)
end
end

describe "push_item" do
it "returns nil when the doi is blank" do
expect(FunderIdentifier.push_item({attributes: {doi: nil}})).to(eq(nil))
end

describe "when STAFF_ADMIN_TOKEN" do
before(:each) do
allow(ENV).to(receive(:[]).with("STAFF_ADMIN_TOKEN").and_return("STAFF_ADMIN_TOKEN"))
allow(ENV).to(receive(:[]).with("LAGOTTINO_URL").and_return("https://fake.lagattino.com"))
allow(ENV).to(receive(:[]).with("DATACITE_FUNDER_SOURCE_TOKEN").and_return("DATACITE_FUNDER_SOURCE_TOKEN"))
allow(Base).to(receive(:cached_datacite_response).and_return({"foo" => "bar"}))
allow(Base).to(receive(:cached_funder_response).and_return({"bar" => "foo"}))
allow(Maremma).to(receive(:post).and_return(OpenStruct.new(status: 200)))
allow(Time).to(receive_message_chain(:zone, :now, :iso8601).and_return("2023-11-15T12:17:47Z"))
end

describe "is valid" do
it "makes request to lagottino for those funder identifiers with funder identifier type 'Crossref Funder Id'" do
item = {
"attributes" => {
"doi" => "https://doi.org/10.0001/foo.bar",
"updated" => "2023-11-15",
"fundingReferences" => [
{
"funderIdentifier" => "https://doi.org/10.0001/example.one",
"funderIdentifierType" => "Crossref Funder ID"
},
{
"funderIdentifier" => "https://doi.org/10.0001/example.two",
"funderIdentifierType" => "Foo"
},
{
"funderIdentifier" => "https://doi.org/10.0001/example.three",
"funderIdentifierType" => "Crossref Funder ID"
},
]
}
}

expect(FunderIdentifier.push_item(item)).to(eq(2))

expect(Maremma).to(have_received(:post).twice)
end

it "passes the expected values to lagottino" do
item = {
"attributes" => {
"doi" => "https://doi.org/10.0001/foo.bar",
"updated" => "2023-11-15",
"fundingReferences" => [
{
"funderIdentifier" => "https://doi.org/10.0001/example.one",
"funderIdentifierType" => "Crossref Funder ID"
},
],
},
}

json_data = ({
"data" => {
"type" => "events",
"attributes" => {
"messageAction" => "create",
"subjId" => "https://doi.org/10.0001/foo.bar",
"objId" => "https://doi.org/10.0001/example.one",
"relationTypeId" => "is-funded-by",
"sourceId" => "datacite-funder",
"sourceToken" => "DATACITE_FUNDER_SOURCE_TOKEN",
"occurredAt" => "2023-11-15",
"timestamp" => "2023-11-15T12:17:47Z",
"license" => "https://creativecommons.org/publicdomain/zero/1.0/",
"subj" => {"foo" => "bar"},
"obj" => {"bar" => "foo"},
}
}
}).to_json

expect(FunderIdentifier.push_item(item)).to(eq(1))

expect(Maremma).to(have_received(:post).with(
"https://fake.lagattino.com/events",
data: json_data,
bearer: "STAFF_ADMIN_TOKEN",
content_type: "application/vnd.api+json",
accept: "application/vnd.api+json; version=2"
))
end
end

describe "is invalid" do
it "will not make request to lagottino" do
allow(ENV).to(receive(:[]).with("STAFF_ADMIN_TOKEN").and_return(nil))

item = {
"attributes" => {
"doi" => "https://doi.org/10.0001/foo.bar",
"updated" => "2023-11-15",
"fundingReferences" => [
{
"funderIdentifier" => "https://doi.org/10.0001/example.one",
"funderIdentifierType" => "Crossref Funder ID"
},
],
},
}

expect(FunderIdentifier.push_item(item)).to(eq(1))

expect(Maremma).not_to(have_received(:post))
end
end
end
end
4 changes: 2 additions & 2 deletions spec/models/related_url_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
allow(Time).to(receive_message_chain(:zone, :now, :iso8601).and_return("2023-11-15T12:17:47Z"))
end

it "make request to lagottino for those related identifiers with type 'URL'" do
it "makes request to lagottino for those related identifiers with type 'URL'" do
item = {
"attributes" => {
"doi" => "https://doi.org/10.0001/foo.bar",
Expand Down Expand Up @@ -128,7 +128,7 @@
end

describe "is invalid" do
it "is not set will only request logottino for those related identifiers with type 'URL'" do
it "will not make request to lagottino" do
allow(Maremma).to(receive(:post))

item = {
Expand Down

0 comments on commit 652959f

Please sign in to comment.