Skip to content

Commit 34a5c63

Browse files
authored
Add properties to existing responses (#395)
## What's changed? - `code` has been added to the school show response for the dashboard - `project` has been added to the lesson index so we can direct students to the project from the class page
2 parents a7f49d2 + 63898e1 commit 34a5c63

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

app/views/api/lessons/index.json.jbuilder

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,13 @@ json.array!(@lessons_with_users) do |lesson, user|
1717
:updated_at
1818
)
1919

20+
if lesson.project
21+
json.project(
22+
lesson.project,
23+
:identifier,
24+
:project_type
25+
)
26+
end
27+
2028
json.user_name(user&.name)
2129
end

app/views/api/my_school/show.json.jbuilder

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ json.call(
1212
:administrative_area,
1313
:postal_code,
1414
:country_code,
15+
:code,
1516
:verified_at,
1617
:created_at,
1718
:updated_at

spec/features/lesson/listing_lessons_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@
4040
expect(data.first[:user_name]).to eq('School Teacher')
4141
end
4242

43+
it 'responds with the project JSON' do
44+
get('/api/lessons', headers:)
45+
data = JSON.parse(response.body, symbolize_names: true)
46+
expected_project = JSON.parse(lesson.project.to_json(only: %i[identifier project_type]), symbolize_names: true)
47+
48+
expect(data.first[:project]).to eq(expected_project)
49+
end
50+
4351
# rubocop:disable RSpec/ExampleLength
4452
it "responds with nil attributes for the user if their user profile doesn't exist" do
4553
user_id = SecureRandom.uuid

spec/features/my_school/showing_my_school_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
end
1818

1919
it "includes the school details and user's roles in the JSON" do
20-
school_json = school.to_json(only: %i[id name website reference address_line_1 address_line_2 municipality administrative_area postal_code country_code verified_at created_at updated_at])
20+
school_json = school.to_json(only: %i[id name website reference address_line_1 address_line_2 municipality administrative_area postal_code country_code code verified_at created_at updated_at])
2121
expected_data = JSON.parse(school_json, symbolize_names: true).merge(roles: ['owner'])
2222

2323
get('/api/school', headers:)

0 commit comments

Comments
 (0)