Skip to content

Commit

Permalink
Merge pull request #1727 from seek4science/workflow-classes-json
Browse files Browse the repository at this point in the history
Endpoint to get workflow classes as JSON-LD
  • Loading branch information
fbacall authored Jan 29, 2024
2 parents 9038c9e + eb94a7a commit 32bbc22
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/controllers/workflow_classes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def edit

def index
@workflow_classes = WorkflowClass.order(extractor: :desc).all
respond_to do |format|
format.html
format.jsonld { render json: @workflow_classes.map(&:ro_crate_metadata), adapter: :attributes }
end
end

private
Expand Down
34 changes: 34 additions & 0 deletions test/functional/workflow_classes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,40 @@ class WorkflowClassesControllerTest < ActionController::TestCase
workflow_class_avatar_path(user_added_3, user_added_3.avatar, size: '32x32'), count: 1
end

test 'get index as json-ld' do
person = FactoryBot.create(:person)
disable_authorization_checks do
FactoryBot.create(:cwl_workflow_class)
FactoryBot.create(:galaxy_workflow_class)
FactoryBot.create(:nextflow_workflow_class)
WorkflowClass.create!(title: 'My Class', key: 'mine', contributor: person)
end

login_as(person)

get :index, format: :jsonld

assert_response :success
classes = JSON.parse(response.body)
assert_equal 4, classes.length

cwl = classes.detect { |c| c['@id'] == '#cwl' }
assert cwl
assert_equal 'Common Workflow Language', cwl['name']
assert_equal 'ComputerLanguage', cwl['@type']
assert_equal 'CWL', cwl['alternateName']
assert_equal({ '@id' => 'https://w3id.org/cwl/v1.0/' }, cwl['identifier'])
assert_equal({ '@id' =>'https://www.commonwl.org/' }, cwl['url'])

assert classes.detect { |c| c['@id'] == '#galaxy' }
assert classes.detect { |c| c['@id'] == '#nextflow' }

user_added = classes.detect { |c| c['@id'] == '#mine' }
assert_equal 'My Class', user_added['name']
refute user_added.key?('identifier')
refute user_added.key?('url')
end

test 'admin can edit any workflow class' do
person = FactoryBot.create(:person)
core_type, c1, c2 = nil
Expand Down

0 comments on commit 32bbc22

Please sign in to comment.