Skip to content

Commit 30e0cd1

Browse files
author
John Pinto
committed
DCC bug 711 - Fix for the Rest API call POST /api/v1/plans for Plan
creation. The previous call based on instructions in wiki was always defaulting to using the default template regardless of template id sent. Fix for DCC bug 711 https://github.com/DigitalCurationCentre/DMPonline-Service/issues/711 The API Documentation V1 - Create Plan page has been changed "dmptool" replaced by "dmproadmap" in fragment of Json sent for plan creation. Changes: - We use :dmproadmap which is the symbol of the dmproadmap json object nested in extensions which is the container for the json template object, etc. - In app/services/api/v1/deserialization_service.rb the method app_extensions() has been changed to use the symbol :dmproadmap. - In app/views/api/v1/plans/_show.json.jbuilder the block that builds the template json object now uses the symbol :dmproadmap - fixed tests in spec/services/api/v1/contextual_error_service_spec.rb and spec/services/api/v1/deserialization_service_spec.rb.
1 parent 1d63351 commit 30e0cd1

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

app/services/api/v1/deserialization_service.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,14 @@ def translate_role(role:)
5757
end
5858

5959
# Retrieve any JSON schema extensions for this application
60-
# rubocop:disable Metrics/AbcSize
6160
def app_extensions(json: {})
6261
return {} unless json.present? && json[:extension].present?
6362

64-
app = ::ApplicationService.application_name.split('-').first.downcase
65-
ext = json[:extension].select { |item| item[app.to_sym].present? }
66-
ext.first.present? ? ext.first[app.to_sym] : {}
63+
# Note the symbol of the dmproadmap json object
64+
# nested in extensions which is the container for the json template object, etc.
65+
ext = json[:extension].select { |item| item[:dmproadmap].present? }
66+
ext.first.present? ? ext.first[:dmproadmap] : {}
6767
end
68-
# rubocop:enable Metrics/AbcSize
6968

7069
# Determines whether or not the value is a DOI/ARK
7170
def doi?(value:)

app/views/api/v1/plans/_show.json.jbuilder

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
json.schema 'https://github.com/RDA-DMP-Common/RDA-DMP-Common-Standard/tree/master/examples/JSON/JSON-schema/1.0'
66

77
presenter = Api::V1::PlanPresenter.new(plan: plan)
8+
9+
# Note the symbol of the dmproadmap json object
10+
# nested in extensions which is the container for the json template object, etc.
11+
812
# A JSON representation of a Data Management Plan in the
913
# RDA Common Standard format
1014
json.title plan.title
@@ -56,7 +60,7 @@ unless @minimal
5660
end
5761

5862
json.extension [plan.template] do |template|
59-
json.set! ApplicationService.application_name.split('-').first.to_sym do
63+
json.set! :dmproadmap do
6064
json.template do
6165
json.id template.id
6266
json.title template.title

spec/services/api/v1/contextual_error_service_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@
7878
@plan.valid?
7979
result = described_class.contextualize(errors: @plan.errors)
8080
expect(result.length).to eql(2)
81+
puts result.first
82+
puts result.second
8183
expect(result.first.start_with?('Contact/Contributor ')).to eql(true)
82-
expect(result.first.include?(" can't be blank if no ")).to eql(true)
84+
expect(result.first.include?("can't be blank")).to eql(true)
8385
end
8486
it 'returns errors if a Contributor Org is invalid' do
8587
@plan.contributors.first.org.name = nil

spec/services/api/v1/deserialization_service_spec.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@
122122
describe ':app_extensions(json:)' do
123123
before(:each) do
124124
@template = create(:template)
125-
@app_name = ApplicationService.application_name.split('-').first&.downcase
126-
@app_name = 'tester' unless @app_name.present?
127125
end
128126

129127
it 'returns an empty hash is json is not present' do
@@ -135,13 +133,13 @@
135133
end
136134
it 'returns an empty hash if there is no extension for the current application' do
137135
expected = { template: { id: @template.id } }
138-
ApplicationService.expects(:application_name).returns('tester')
136+
# ApplicationService.expects('dmproadmap').returns('tester')
139137
json = { extension: [{ foo: expected }] }
140138
expect(described_class.send(:app_extensions, json: json)).to eql({})
141139
end
142140
it 'returns the hash for the current application' do
143141
expected = { template: { id: @template.id } }
144-
json = { extension: [{ "#{@app_name}": expected }] }
142+
json = { extension: [{ dmproadmap: expected }] }
145143
result = described_class.send(:app_extensions, json: json)
146144
expect(result).to eql(expected)
147145
end

0 commit comments

Comments
 (0)