Created
April 15, 2017 06:38
-
-
Save sabril/bce9bd197e24d453f2986e635c54a52f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mobile/mobile_helper' | |
describe 'TaskOperations', type: :request, focus: false do | |
before(:each) do | |
@account = FactoryGirl.create(:account_with_admin) | |
@location = @account.locations.first | |
@admin = FactoryGirl.create(:admin, loc_id: @location.id, account_id: @account.id) | |
param = FactoryGirl.attributes_for(:patient, loc_id: @location.id, account: @account, email: '[email protected]') | |
@patient = create_user(param, @account, @admin, 'Patient') | |
@task = FactoryGirl.create(:exercise, account: @account) | |
assign_task(@patient, @admin, @task) | |
# sign in | |
host! "#{@account.subdomain}.example.com" | |
sign_in @patient | |
end | |
describe 'query#get_tasks_for_date' do | |
it 'should return 1 task' do | |
query = <<-String | |
query { | |
getTasksForDate{ | |
id | |
name | |
completedAt | |
videoUrl | |
imageUrl | |
notes | |
equipment | |
description | |
quantityType | |
times | |
sets | |
reps | |
durationType | |
duration | |
} | |
} | |
String | |
post graphql_rails_path, query: query | |
result = JSON.parse(response.body) | |
exercise = OpenStruct.new(result['data']['getTasksForDate'][0]) | |
# compare GraphQL vs create_session_for_date | |
expect(exercise.id).not_to eq(@task.id.to_s) | |
expect(exercise.name).to eq(@task.name) | |
expect(result['errors']).to eq(nil) | |
end | |
it 'should return error' do | |
query = <<-String | |
query { | |
getTasksForDate("2017-01-01"){ | |
name | |
} | |
} | |
String | |
post graphql_rails_path, query: query | |
result = JSON.parse(response.body) | |
expect(result['errors']).to eq([{'message' => 'Unable to parse query'}]) | |
end | |
end | |
describe 'mutation#complete_task' do | |
it 'should mark session as complete' do | |
create_session(@patient) | |
@session = ExerciseSession.first | |
mutation = <<-String | |
mutation { | |
completeTask(input: {id: "#{@session.id}", completed: true}){ | |
clientMutationId | |
} | |
} | |
String | |
post graphql_rails_path, query: mutation | |
@session.reload | |
expect(@session.completed).to eq(true) | |
end | |
end | |
describe 'unauthorize user' do | |
before do | |
sign_in @admin | |
end | |
it 'can not call get tasks for date' do | |
query = <<-String | |
query { | |
getTasksForDate{ | |
name | |
} | |
} | |
String | |
post graphql_rails_path, query: query | |
result = JSON.parse(response.body) | |
expect(result['errors'][0]['message']).to eq('You must be logged into a patient account to perform patient operations') | |
end | |
it 'can not mutate tasks for date' do | |
create_session(@patient) | |
@session = ExerciseSession.first | |
mutation = <<-String | |
mutation { | |
completeTask(input: {id: "#{@session.id}", completed: true}){ | |
clientMutationId | |
} | |
} | |
String | |
post graphql_rails_path, query: mutation | |
result = JSON.parse(response.body) | |
expect(result['errors'][0]['message']).to eq('You must be logged into a patient account to perform patient operations') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment