Skip to content

Commit 95438b9

Browse files
craigtonlianadi-herwana-nus
authored andcommitted
fix(LearnPage): add learn_settings endpoint for Learn title
1 parent 6af4f3a commit 95438b9

File tree

7 files changed

+76
-3
lines changed

7 files changed

+76
-3
lines changed

app/controllers/course/stories/stories_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ def learn
1515
render json: { redirectUrl: url }
1616
end
1717

18+
def learn_settings
19+
title = current_course.settings(:course_stories_component).title
20+
21+
render json: { title: title }
22+
end
23+
1824
def mission_control
1925
target_course_user = current_course.course_users.find_by(id: params[:course_user_id]) || current_course_user
2026
url, @pending_threads_count = get_mission_control_url(target_course_user)

client/app/api/course/Stories.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { LearnSettingsData } from 'types/course/learn';
2+
13
import { APIResponse, JustRedirect } from 'api/types';
24

35
import BaseCourseAPI from './Base';
@@ -7,6 +9,10 @@ export default class StoriesAPI extends BaseCourseAPI {
79
return this.client.get(`/courses/${this.courseId}/learn`);
810
}
911

12+
learnSettings(): APIResponse<LearnSettingsData> {
13+
return this.client.get(`/courses/${this.courseId}/learn_settings`);
14+
}
15+
1016
missionControl(courseUserId?: string): APIResponse<JustRedirect> {
1117
return this.client.get(`/courses/${this.courseId}/mission_control`, {
1218
params: { course_user_id: courseUserId },

client/app/bundles/course/stories/pages/LearnPage.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { defineMessage } from 'react-intl';
2-
31
import CourseAPI from 'api/course';
42
import LoadingIndicator from 'lib/components/core/LoadingIndicator';
53
import { useSetFooter } from 'lib/components/wrappers/FooterProvider';
@@ -29,7 +27,7 @@ export const learnHandle: DataHandle = (match) => {
2927
const courseId = match.params.courseId;
3028
return {
3129
getData: async (): Promise<CrumbPath> => {
32-
const { data } = await CourseAPI.admin.stories.index();
30+
const { data } = await CourseAPI.stories.learnSettings();
3331
return {
3432
activePath: `/courses/${courseId}/learn`,
3533
content: { title: data.title || 'Learn' },

client/app/types/course/learn.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface LearnSettingsData {
2+
title: string;
3+
}

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@
518518

519519
scope module: :stories do
520520
get 'learn', to: 'stories#learn'
521+
get 'learn_settings', to: 'stories#learn_settings'
521522
get 'mission_control', to: 'stories#mission_control'
522523
end
523524
end
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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

spec/factories/courses.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,12 @@
5555
course.set_component_enabled_boolean(:course_rag_wise_component, true)
5656
end
5757
end
58+
59+
trait :with_stories_component_enabled do
60+
after(:build) do |course|
61+
course.instance.set_component_enabled_boolean!(:course_stories_component, true)
62+
course.set_component_enabled_boolean(:course_stories_component, true)
63+
end
64+
end
5865
end
5966
end

0 commit comments

Comments
 (0)