spec: refactor assignment specs

closes QA-528

Test Plan:
1. Pass Jenkins

Change-Id: I0d084b9563e603616ebcd0fa2d551232a9f380c3
Reviewed-on: https://gerrit.instructure.com/156082
Tested-by: Jenkins
Reviewed-by: Deepeeca Soundarrajan <dsoundarrajan@instructure.com>
Product-Review: Luke Kingsley <lkingsley@instructure.com>
QA-Review: Luke Kingsley <lkingsley@instructure.com>
This commit is contained in:
Luke Kingsley 2018-07-03 12:05:18 -06:00
parent a91002e0bd
commit 28f2d64b1d
3 changed files with 41 additions and 44 deletions

View File

@ -21,42 +21,40 @@ require_relative '../pact_helper'
describe 'Assignments', :pact do
subject(:assignments_api) { Helper::ApiClient::Assignments.new }
context 'List Assignments' do
it 'should return JSON body' do
it 'List Assignments' do
canvas_lms_api.given('a student in a course with an assignment').
upon_receiving('List Assignments').
with(
method: :get,
headers: {
'Authorization': 'Bearer some_token',
'Auth-User': 'User_Student',
'Auth-User': 'Student1',
'Connection': 'close',
'Host': PactConfig.mock_provider_service_base_uri,
'Version': 'HTTP/1.1'
},
'path' => '/api/v1/users/2/courses/1/assignments',
'path' => '/api/v1/users/5/courses/1/assignments',
query: ''
).
will_respond_with(
status: 200,
body: Pact.each_like('id': 1, 'name': 'Assignment1')
)
assignments_api.authenticate_as_user('User_Student')
response = assignments_api.list_assignments(1, 2)
assignments_api.authenticate_as_user('Student1')
response = assignments_api.list_assignments(1, 5)
expect(response[0]['id']).to eq 1
expect(response[0]['name']).to eq 'Assignment1'
end
end
context 'Post Assignments' do
it 'should return JSON body' do
it 'Post Assignments' do
canvas_lms_api.given('a teacher in a course').
upon_receiving('Post Assignments').
with(
method: :post,
headers: {
'Authorization': 'Bearer some_token',
'Auth-User': 'User_Teacher',
'Auth-User': 'Teacher1',
'Connection': 'close',
'Host': PactConfig.mock_provider_service_base_uri,
'Version': 'HTTP/1.1',
@ -76,10 +74,9 @@ describe 'Assignments', :pact do
status: 201,
body: Pact.like('id': 1, 'name': 'New Assignment')
)
assignments_api.authenticate_as_user('User_Teacher')
assignments_api.authenticate_as_user('Teacher1')
response = assignments_api.post_assignments(1, 'New Assignment')
expect(response['id']).to eq 1
expect(response['name']).to eq 'New Assignment'
end
end
end

View File

@ -20,9 +20,9 @@ require 'spec/factories/course_factory'
require 'spec/factories/user_factory'
PactConfig::Consumers::ALL.each do |consumer|
if consumer == 'Generic Consumer'
next
end
# if consumer == 'Generic Consumer'
# next
# end
Pact.provider_states_for consumer do
set_up do

View File

@ -21,13 +21,13 @@
PactConfig::Consumers::ALL.each do |consumer|
Pact.provider_states_for consumer do
# Creates a course with a student enrolled and creates an assignment in the course.
# Possible API endpoints: get, put and delete
# Used by the spec: 'List Assignments'
# Student ID: 5 || Student Name: Student1
# Course ID: 1
# Assignment ID: 1
provider_state 'a student in a course with an assignment' do
set_up do
course_with_student(active_all: true, name: 'User_Student')
Assignment.create!(context: @course, title: "Assignment1")
course = Pact::Canvas:base_state.course
Assignment.create!(context: course, title: "Assignment1")
end
end
end