Skip to content

Commit

Permalink
Merge pull request #1088 from concord-consortium/178640689-fix-ap-seq…
Browse files Browse the repository at this point in the history
…uence-shows-up-as-activity-in-search

Fix AP sequence shows up as an activity in Portal search
  • Loading branch information
scytacki authored Sep 17, 2021
2 parents 3517d11 + 972d019 commit 024230a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
15 changes: 15 additions & 0 deletions rails/app/controllers/api/v1/external_activities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,24 @@ def create
return error("Invalid url", 422)
end

type = params.require(:type)
case type
when "Activity"
material_type = "Activity"
when "Investigation", "Sequence"
material_type = "Investigation"
else
material_type = nil
end

if !material_type
return error("Invalid material type", 422)
end

external_activity = ExternalActivity.create(
:name => name,
:url => url,
:material_type => material_type,
:publication_status => params[:publication_status] || "published",
:user => user,
:append_auth_token => params[:append_auth_token] || false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
end

it "succeeds with valid parameters" do
post :create, params: { :name => "test", :url => "http://example.com/" }
post :create, params: { :name => "test", :url => "http://example.com/", :type => "Activity" }
expect(response.status).to eql(201)
end
end
Expand All @@ -48,7 +48,7 @@
end

it "succeeds with valid parameters" do
post :create, params: { :name => "test", :url => "http://example.com/" }
post :create, params: { :name => "test", :url => "http://example.com/", :type => "Sequence" }
expect(response.status).to eql(201)
end
end
Expand All @@ -59,7 +59,7 @@
end

it "succeeds with valid minimal parameters" do
post :create, params: {:name => "test", :url => "http://example.com/"}
post :create, params: { :name => "test", :url => "http://example.com/", :type => "Activity" }
expect(response.status).to eql(201)
end
end
Expand All @@ -70,22 +70,32 @@
end

it "fails with a missing name parameter" do
post :create, params: { :url => "http://example.com/" }
post :create, params: { :url => "http://example.com/", :type => "Activity" }
expect(response.status).to eql(400)
end

it "fails with a missing url parameter" do
post :create, params: {:name => "test"}
post :create, params: {:name => "test", :type => "Activity" }
expect(response.status).to eql(400)
end

it "fails with an invalid url parameter" do
post :create, params: { :url => "invalid" }
post :create, params: { :name => "test", :url => "invalid!--http:\\!!@&][", :type => "Activity" }
expect(response.status).to eql(422)
end

it "fails with a missing type parameter" do
post :create, params: { :name => "test", :url => "http://example.com/" }
expect(response.status).to eql(400)
end

it "fails with an invalid type parameter" do
post :create, params: { :name => "test", :url => "http://example.com/", :type => "invalid" }
expect(response.status).to eql(422)
end

it "succeeds with valid minimal parameters" do
post :create, params: { :name => "test", :url => "http://example.com/" }
post :create, params: { :name => "test", :url => "http://example.com/", :type => "Activity" }
expect(response.status).to eql(201)
end
end
Expand Down Expand Up @@ -200,7 +210,7 @@

it "should update an activity they did author" do
my_url = "http://activity.com/activity/2"
post :create, params: {:name => "My Cool Activity", :url => my_url}
post :create, params: { :name => "My Cool Activity", :url => my_url, :type => "Activity" }
my_valid_parameters = {
url: my_url
}
Expand Down

0 comments on commit 024230a

Please sign in to comment.