Skip to content

Commit

Permalink
rspec test added
Browse files Browse the repository at this point in the history
  • Loading branch information
kostik committed Dec 4, 2023
1 parent 982b07b commit 87f2750
Show file tree
Hide file tree
Showing 3 changed files with 428 additions and 39 deletions.
2 changes: 1 addition & 1 deletion app/models/study_json_record/processor_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def brief_summary_data
nct_id = protocol_section.dig('identificationModule', 'nctId')
description = protocol_section.dig('descriptionModule', 'briefSummary')
return unless description
{ nct_id: nctId, description: description }
{ nct_id: nct_id, description: description }
end

def design_data
Expand Down
48 changes: 10 additions & 38 deletions spec/models/study_json_record/processor_v2_spec.rb
Original file line number Diff line number Diff line change
@@ -1,47 +1,19 @@
require 'rails_helper'

RSpec.describe StudyJsonRecord::ProcessorV2, type: :model do
describe '#brief_summary_data' do
let(:json) { { 'protocolSection' => protocol_section } }
let(:processor_v2) { described_class.new(json) }

context 'when protocol section is not present' do
let(:protocol_section) { nil }

it 'returns nil' do
expect(processor_v2.brief_summary_data).to be_nil
end
describe 'brief_summary_data' do

it 'should test brief_summary_data' do
expected_data = {
nct_id: 'NCT03630471',
description: 'We will conduct a two-arm individually randomized controlled trial in six Government-run secondary schools in New Delhi. The targeted sample is 240 adolescents in grades 9-12 with persistent, elevated mental health difficulties and associated impact. Participants will receive either a brief problem-solving intervention delivered by lay counsellors (intervention), or enhanced usual care comprised of problem-solving booklets (control). Self-reported adolescent mental health difficulties and idiographic problems will be assessed at 6 weeks (co-primary outcomes) and again at 12 weeks post-randomization. In addition, adolescent-reported impact of mental health difficulties, perceived stress, mental wellbeing and clinical remission, as well as parent-reported adolescent mental health difficulties and impact scores, will be assessed at 6 and 12 weeks post-randomization. Parallel process evaluation, including estimations of the costs of delivering the interventions, will be conducted.'
}
hash = JSON.parse(File.read('spec/support/json_data/NCT03630471.json'))
processor = StudyJsonRecord::ProcessorV2.new(hash)
expect(processor.brief_summary_data).to eq(expected_data)
end

context 'when description module is not present' do
let(:protocol_section) { {} }

it 'returns nil' do
expect(processor_v2.brief_summary_data).to be_nil
end
end

context 'when brief summary is present' do
let(:protocol_section) do
{"identificationModule"=> {
"nctId": "NCT03630471"
},
'descriptionModule' => {
'briefSummary' => 'This is a brief summary.'
}
}
end

it 'returns the correct data' do
allow(processor_v2).to receive(:nctId).and_return('NCT12345')

expected_data = {
nct_id: 'NCT12345',
description: 'This is a brief summary.'
}

expect(processor_v2.brief_summary_data).to eq(expected_data)
end
end
end
end
Loading

0 comments on commit 87f2750

Please sign in to comment.