diff --git a/spec/features/arriving_as_user.rb b/spec/features/arriving_as_user.rb deleted file mode 100644 index 8078a83..0000000 --- a/spec/features/arriving_as_user.rb +++ /dev/null @@ -1,28 +0,0 @@ -RSpec.describe 'Arriving as user' do - let(:snp) { double('snp', name: 'rs1234', snpedia_papers: [snpedia_paper]) } - let!(:user) { create(:user, name: 'Potato Bill', snps: [snp]) } - - let(:snpedia_paper) do - double(:snpedia_paper, url: 'http://www.snpedia.com/index.php/Rs1234(A;C)', - summary: 'Green hair', - snp_variation: 'AC', - created_at: '1969-07-20 20:17:40', - id: 1) - end - - context 'as a signed-in user' do - before do - sign_in(user) - end - - scenario 'the user arrives on landing page' do - visit root_path - - expect(page).to have_content('Hello Potato!') - expect(page).to have_content('rs1234') - - # Test Your last 30 updated SNPs feed - expect(page).to have_content('Received new data from SNPedia') - end - end -end diff --git a/spec/features/login_spec.rb b/spec/features/login_spec.rb new file mode 100644 index 0000000..1d08067 --- /dev/null +++ b/spec/features/login_spec.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +RSpec.describe 'Arriving at openSNP' do + let!(:user) { create(:user, name: 'Potato Bill', email: 'potato@example.com') } + let!(:phenotype) { create(:phenotype, characteristic: 'Eye color') } + + context 'as a signed-in user' do + before do + sign_in(user) + end + + scenario 'the user arrives on landing page' do + visit root_path + + expect(page).to have_content('Hello, Potato') + expect(page).to have_content('Eye color') + end + end + + context 'as a signed-out user' do + scenario 'user arrives on main page' do + visit root_path + expect(page).to have_content('Sign up') + expect(page).to have_content('Download data') + expect(page).to have_content('Sign In') + end + + scenario 'user forgot their password' do + visit root_path + click_on('Sign In') + click_on('Forgot password?') + fill_in('Email', with: 'potato@example.com') + click_on('Reset my password') + expect(page).to have_content('Instructions to reset your password') + mail = ActionMailer::Base.deliveries.last + expect(mail.subject).to include('openSNP.org Password Reset Instructions') + mail.parts.each do |p| + expect(p.body.raw_source).to include(user.name) + expect(p.body.raw_source).to include('password_resets') + end + end + end +end diff --git a/spec/requests/snps_spec.rb b/spec/requests/snps_spec.rb new file mode 100644 index 0000000..8a5e2c1 --- /dev/null +++ b/spec/requests/snps_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'SNP API', focus: true do + it 'GET /snps/:id.json' do + create(:snp, name: 'rs1234') + create(:user) { create(:user, name: 'API-Hacker') } + create(:user_snp) { create(:user_snp, user: User.first, snp: Snp.first) } + get '/snps/rs1234.json' + assert_response :success + data = JSON.parse(response.body) + expect(data).to_not be_empty + data = data[0] + %w(name chromosome position).each do |property| + expect(data['snp'].keys).to include(property) + end + %w(name id genotypes).each do |property| + expect(data['user'].keys).to include(property) + end + end +end