Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1259] Expose provider in courses #245

Merged
merged 3 commits into from Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/api/v2/courses_controller.rb
Expand Up @@ -12,7 +12,7 @@ def index
end

def show
render jsonapi: @course, include: [site_statuses: [:site]]
render jsonapi: @course, include: params[:include]
end

def sync_with_search_and_compare
Expand Down
4 changes: 4 additions & 0 deletions spec/factories/courses.rb
Expand Up @@ -84,5 +84,9 @@
trait :resulting_in_pgde do
qualification { :pgde }
end

trait :with_accrediting_provider do
association(:accrediting_provider, factory: :provider)
end
end
end
2 changes: 1 addition & 1 deletion spec/requests/api/v2/providers/courses_spec.rb
Expand Up @@ -73,7 +73,7 @@
before do
get "/api/v2/providers/#{provider.provider_code.downcase}/courses/#{findable_open_course.course_code.downcase}",
headers: { 'HTTP_AUTHORIZATION' => credentials },
params: { includes: "site_statuses" }
params: { include: 'site_statuses.site' }
end

it { should have_http_status(:success) }
Expand Down
64 changes: 55 additions & 9 deletions spec/serializers/api/v2/serializable_course_spec.rb
@@ -1,17 +1,63 @@
require "rails_helper"

describe API::V2::SerializableCourse do
let(:course) { create(:course, start_date: Time.now.utc) }
let(:resource) { API::V2::SerializableCourse.new object: course }
let(:jsonapi_renderer) { JSONAPI::Serializable::Renderer.new }
let(:course) { create(:course, start_date: Time.now.utc) }
let(:course_json) do
jsonapi_renderer.render(
course,
class: {
Course: API::V2::SerializableCourse
}
).to_json
end
let(:parsed_json) { JSON.parse(course_json) }

subject { parsed_json['data'] }

it { should have_type('courses') }
it { should have_attributes(:start_date, :content_status, :ucas_status) }

it 'sets type to courses' do
expect(resource.jsonapi_type).to eq :courses
context 'with a provider' do
let(:provider) { course.provider }
let(:course_json) do
jsonapi_renderer.render(
course,
class: {
Course: API::V2::SerializableCourse,
Provider: API::V2::SerializableProvider
},
include: [
:provider
]
).to_json
end

it { should have_relationship(:provider) }

it 'includes the provider' do
expect(parsed_json['included'])
.to(include(have_type('providers')
.and(have_id(provider.id.to_s))))
end
end

subject { resource.as_jsonapi.to_json }
context 'with an accrediting_provider' do
let(:course) { create(:course, :with_accrediting_provider) }
let(:accrediting_provider) { course.accrediting_provider }
let(:course_json) do
jsonapi_renderer.render(
course,
class: {
Course: API::V2::SerializableCourse,
Provider: API::V2::SerializableProvider
},
include: [
:accrediting_provider
]
).to_json
end

it { should be_json.with_content(type: 'courses') }
it { should be_json.with_content(course.start_date.iso8601).at_path("attributes.start_date") }
it { should be_json.with_content(course.content_status.to_s).at_path("attributes.content_status") }
it { should be_json.with_content(course.ucas_status.to_s).at_path("attributes.ucas_status") }
it { should have_relationship(:accrediting_provider) }
end
end