spec: wiki page spec
Change-Id: I6c0fb7fe65a04a74ac630b4f4cdac555399aee13 Reviewed-on: https://gerrit.instructure.com/157722 Tested-by: Jenkins Reviewed-by: Anju Reddy <areddy@instructure.com> Product-Review: Luke Kingsley <lkingsley@instructure.com> QA-Review: Luke Kingsley <lkingsley@instructure.com>
This commit is contained in:
parent
a22113c6c3
commit
9515e732fa
|
@ -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: {
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue