Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ryscher committed Dec 8, 2020
1 parent 5d0cfc1 commit 0452950
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
28 changes: 27 additions & 1 deletion spec/models/stash_engine/author_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ module StashEngine
describe Author do

before(:each) do
@resource = create(:resource)
@ident = create(:identifier)
@resource = create(:resource,
identifier: @ident,
tenant_id: 'dryad')
end

describe :new do
Expand Down Expand Up @@ -35,6 +38,29 @@ module StashEngine
end
end

describe :orcid_invite_path do
it 'generates an orcid_invite_path when needed' do
author = create(:author)
expect(author.orcid_invite_path).to include('invitation')
end

it 'delivers the correct orcid_invite_path' do
author = create(:author,
resource: @resource)
orcid_invite = StashEngine::OrcidInvitation.create(
email: author.author_email,
identifier_id: @resource.identifier_id,
first_name: author.author_first_name,
last_name: author.author_last_name,
secret: SecureRandom.urlsafe_base64,
invited_at: Time.new.utc
)

expect(author.orcid_invite_path).to include("invitation=#{orcid_invite.secret}")
expect(author.orcid_invite_path).to include(@resource.identifier.identifier)
end
end

describe :author_orcid do
it 'is optional' do
author = Author.create(
Expand Down
12 changes: 11 additions & 1 deletion stash/stash_engine/app/models/stash_engine/author.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,17 @@ def init_user_orcid

def orcid_invite_path
orcid_invite = StashEngine::OrcidInvitation.where(email: author_email, identifier_id: resource.identifier_id)&.first
return '' unless orcid_invite

# Ensure an invite exists -- it may not for a legacy dataset that never received invites,
# or if the author_email has changed since the original creation.
orcid_invite ||= StashEngine::OrcidInvitation.create(
email: author_email,
identifier_id: resource.identifier_id,
first_name: author_first_name,
last_name: author_last_name,
secret: SecureRandom.urlsafe_base64,
invited_at: Time.new.utc
)

path = StashEngine::Engine.routes.url_helpers.show_path(orcid_invite.identifier.to_s, invitation: orcid_invite.secret)
orcid_invite.landing(path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class OrcidInvitation < ApplicationRecord
belongs_to :identifier, class_name: 'StashEngine::Identifier'

def resource
@resource ||= identifier.last_submitted_resource
@resource ||= identifier.last_submitted_resource || identifier.latest_resource
end

def tenant
Expand Down

0 comments on commit 0452950

Please sign in to comment.