Skip to content

Commit

Permalink
Add fields to paper lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanxu committed Jul 28, 2023
1 parent b609fca commit 1ff5be3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/controllers/papers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,13 @@ def show
def lookup
paper = Paper.where('review_issue_id = ? OR meta_review_issue_id = ?', params[:id], params[:id]).first!
accepted_at = paper.accepted_at ? paper.accepted_at.strftime('%d %B %Y') : nil
response = { submitted: paper.created_at.strftime('%d %B %Y'),
response = { title: paper.title,
doi: paper.doi,
state: paper.state,
review_issue_id: paper.review_issue_id,
software_version: paper.software_version,
repository_url: paper.repository_url,
submitted: paper.created_at.strftime('%d %B %Y'),
accepted: accepted_at,
track: paper.track&.short_name }
render json: response.to_json
Expand Down
15 changes: 15 additions & 0 deletions spec/controllers/papers_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@
parsed_response = JSON.parse(response.body)
expect(parsed_response['submitted']).to eq(3.days.ago.strftime('%d %B %Y'))
expect(parsed_response['accepted']).to eq(nil)
expect(parsed_response['doi']).to eq(nil)
end

it "should return the created_at and accepted_at dates for a published paper" do
Expand All @@ -265,6 +266,7 @@
parsed_response = JSON.parse(response.body)
expect(parsed_response['submitted']).to eq(3.days.ago.strftime('%d %B %Y'))
expect(parsed_response['accepted']).to eq(2.days.ago.strftime('%d %B %Y'))
expect(parsed_response['doi']).to eq('10.21105/joss.00000')
end

it "should return paper's track short name" do
Expand All @@ -275,6 +277,19 @@
expect(JSON.parse(response.body)['track']).to eq("Testtr")
end

it "should return paper's info" do
track = create(:track, name: "Test track", short_name: "Testtr")
paper = create(:under_review_paper, title: "Testing paper lookup", software_version: "3.3", track: track, meta_review_issue_id: 123)

get :lookup, params: {id: 123}
expect(JSON.parse(response.body)['title']).to eq("Testing paper lookup")
expect(JSON.parse(response.body)['doi']).to eq(nil)
expect(JSON.parse(response.body)['state']).to eq("under_review")
expect(JSON.parse(response.body)['review_issue_id']).to eq(101)
expect(JSON.parse(response.body)['software_version']).to eq("3.3")
expect(JSON.parse(response.body)['repository_url']).to eq("http://github.com/arfon/fidgit")
end

it "should 404 when passed an invalid id" do
get :lookup, params: {id: 12345}

Expand Down

0 comments on commit 1ff5be3

Please sign in to comment.