|
| 1 | +# frozen_string_literal: true |
| 2 | +require 'rails_helper' |
| 3 | + |
| 4 | +RSpec.describe Course::Stories::StoriesController, type: :controller do |
| 5 | + let!(:instance) { create(:instance) } |
| 6 | + |
| 7 | + with_tenant(:instance) do |
| 8 | + let(:json_response) { JSON.parse(response.body) } |
| 9 | + let(:course) { create(:course, :with_stories_component_enabled) } |
| 10 | + |
| 11 | + before do |
| 12 | + course.settings(:course_stories_component).push_key = 'test_push_key' |
| 13 | + course.save! |
| 14 | + end |
| 15 | + |
| 16 | + describe '#learn_settings' do |
| 17 | + context 'As a Course Manager' do |
| 18 | + let(:user) { create(:course_manager, course: course).user } |
| 19 | + |
| 20 | + before do |
| 21 | + course.settings(:course_stories_component).title = 'Course Manager Story Title' |
| 22 | + course.save! |
| 23 | + controller_sign_in(controller, user) |
| 24 | + end |
| 25 | + |
| 26 | + it 'returns the correct story title in JSON' do |
| 27 | + get :learn_settings, params: { course_id: course.id }, format: :json |
| 28 | + expect(response).to have_http_status(:ok) |
| 29 | + json = JSON.parse(response.body) |
| 30 | + expect(json['title']).to eq('Course Manager Story Title') |
| 31 | + end |
| 32 | + end |
| 33 | + |
| 34 | + context 'As a Course Student' do |
| 35 | + let(:user) { create(:course_student, course: course).user } |
| 36 | + |
| 37 | + before do |
| 38 | + course.settings(:course_stories_component).title = 'Course Student Story Title' |
| 39 | + course.save! |
| 40 | + controller_sign_in(controller, user) |
| 41 | + end |
| 42 | + |
| 43 | + it 'returns the correct story title in JSON' do |
| 44 | + get :learn_settings, params: { course_id: course.id }, format: :json |
| 45 | + expect(response).to have_http_status(:ok) |
| 46 | + json = JSON.parse(response.body) |
| 47 | + expect(json['title']).to eq('Course Student Story Title') |
| 48 | + end |
| 49 | + end |
| 50 | + end |
| 51 | + end |
| 52 | +end |
0 commit comments