diff --git a/pact/spec/courses_spec.rb b/pact/spec/courses_spec.rb index 3ad8d9344bc..5a7f44ee87d 100644 --- a/pact/spec/courses_spec.rb +++ b/pact/spec/courses_spec.rb @@ -448,7 +448,7 @@ describe 'Courses', :pact do context 'Teacher not in a course' do it 'should Give a 401 response' do canvas_lms_api.given('a teacher not in a course'). - upon_receiving('Give a 401 response'). + upon_receiving('List Students'). with( method: :get, headers: { diff --git a/pact/spec/helper/api_client/wiki_pages.rb b/pact/spec/helper/api_client/wiki_pages.rb index 2702a882b88..4b249b0f9eb 100644 --- a/pact/spec/helper/api_client/wiki_pages.rb +++ b/pact/spec/helper/api_client/wiki_pages.rb @@ -33,6 +33,30 @@ module Helper nil end + def update_wiki_page(course_id, url) + JSON.parse( + self.class.put( + "/api/v1/courses/#{course_id}/pages/#{url}", + :body => + { + :wiki_page => + { + :title => "New Title", + } + }.to_json, + :headers => {'Content-Type' => 'application/json'} + ).body + ) + rescue + nil + end + + def delete_wiki(course_id) + JSON.parse(self.class.delete("/api/v1/courses/#{course_id}/pages/wiki-page", query: "event=delete").body) + rescue + nil + end + def post_wiki_pages(course_id) JSON.parse( self.class.post( diff --git a/pact/spec/wiki_pages_spec.rb b/pact/spec/wiki_pages_spec.rb index ca5d66a001d..82822da4476 100644 --- a/pact/spec/wiki_pages_spec.rb +++ b/pact/spec/wiki_pages_spec.rb @@ -60,25 +60,25 @@ describe 'Wiki Pages', :pact do it 'should Post Wiki Pages' do canvas_lms_api.given('a teacher enrolled in a course'). upon_receiving('Post Wiki Pages'). - with( - method: :post, - headers: { - 'Authorization': 'Bearer some_token', - 'Auth-User': 'Teacher1', - 'Connection': 'close', - 'Host': PactConfig.mock_provider_service_base_uri, - 'Version': 'HTTP/1.1', - 'Content-Type': 'application/json' - }, - 'path' => '/api/v1/courses/1/pages', - 'body' => + with( + method: :post, + headers: { + 'Authorization': 'Bearer some_token', + 'Auth-User': 'Teacher1', + 'Connection': 'close', + 'Host': PactConfig.mock_provider_service_base_uri, + 'Version': 'HTTP/1.1', + 'Content-Type': 'application/json' + }, + 'path' => '/api/v1/courses/1/pages', + 'body' => + { + 'wiki_page': { - 'wiki_page': - { - 'title': 'WikiPage', - } - }, - query: '' + 'title': 'WikiPage', + } + }, + query: '' ). will_respond_with( status: 200, @@ -89,4 +89,76 @@ describe 'Wiki Pages', :pact do expect(response['page_id']).to eq 1 expect(response['title']).to eq 'WikiPage' end + + it 'should update a Wiki Page' do + canvas_lms_api.given('a wiki page in a course'). + upon_receiving('update a Wiki Page'). + with( + method: :put, + headers: { + 'Authorization': 'Bearer some_token', + 'Auth-User': 'Teacher1', + 'Connection': 'close', + 'Host': PactConfig.mock_provider_service_base_uri, + 'Version': 'HTTP/1.1', + 'Content-Type': 'application/json' + }, + 'path' => '/api/v1/courses/1/pages/wiki-page', + 'body' => + { + 'wiki_page': + { + 'title': 'New Title', + } + }, + query: '' + ). + will_respond_with( + status: 200, + body: Pact.like('page_id': 1, 'title': 'New Title') + ) + wiki_page_api.authenticate_as_user('Teacher1') + response = wiki_page_api.update_wiki_page(1, 'wiki-page') + expect(response['page_id']).to eq 1 + expect(response['title']).to eq 'New Title' + end + + it 'should Delete a Wiki Page' do + canvas_lms_api.given('a wiki page in a course'). + upon_receiving('Delete a Wiki Page'). + with( + method: :delete, + headers: { + 'Authorization': 'Bearer some_token', + 'Auth-User': 'Teacher1', + 'Connection': 'close', + 'Host': PactConfig.mock_provider_service_base_uri, + 'Version': 'HTTP/1.1' + }, + 'path' => '/api/v1/courses/1/pages/wiki-page', + query: 'event=delete' + ). + will_respond_with( + status: 200, + body: Pact.like( + { + "url": "wiki-page", + "title": "Test Page", + "created_at": "2018-07-12T15:49:05Z", + "editing_roles": "teachers", + "page_id": 8, + "published": false, + "hide_from_students": true, + "front_page": false, + "html_url": "http://localhost:3000/courses/3/pages/test-page", + "updated_at": "2018-07-12T15:49:05Z", + "locked_for_user": false, + "body": "message" + } + ) + ) + wiki_page_api.authenticate_as_user('Teacher1') + response = wiki_page_api.delete_wiki(1) + expect(response['url']).to eq 'wiki-page' + end end diff --git a/spec/contracts/service_consumers/api/provider_states_for_consumer.rb b/spec/contracts/service_consumers/api/provider_states_for_consumer.rb index b97e8c67e80..50727daf1ae 100644 --- a/spec/contracts/service_consumers/api/provider_states_for_consumer.rb +++ b/spec/contracts/service_consumers/api/provider_states_for_consumer.rb @@ -57,7 +57,7 @@ end module Pact::Canvas def self.base_state=(base_state) - @base_state ||= base_state + @base_state = base_state end def self.base_state diff --git a/spec/contracts/service_consumers/api/provider_states_for_consumer/wiki_pages_provider_states.rb b/spec/contracts/service_consumers/api/provider_states_for_consumer/wiki_pages_provider_states.rb index c6f813828f6..bd39487c83e 100644 --- a/spec/contracts/service_consumers/api/provider_states_for_consumer/wiki_pages_provider_states.rb +++ b/spec/contracts/service_consumers/api/provider_states_for_consumer/wiki_pages_provider_states.rb @@ -23,7 +23,7 @@ PactConfig::Consumers::ALL.each do |consumer| provider_state 'a wiki page in a course' do set_up do @course = Pact::Canvas.base_state.course - @course.wiki_pages.create!(title: "wiki_page") + @course.wiki_pages.create!(title: "wiki_page", body: "Here is the body") end end end