mirror of
https://github.com/chenasraf/snpr.git
synced 2026-05-18 01:39:01 +00:00
Added tests (#388)
* work on tests * snp API test * making hound happier * Give the scenarios some space
This commit is contained in:
@@ -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
|
||||
43
spec/features/login_spec.rb
Normal file
43
spec/features/login_spec.rb
Normal file
@@ -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
|
||||
22
spec/requests/snps_spec.rb
Normal file
22
spec/requests/snps_spec.rb
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user