Skip to content

Commit 5afccb8

Browse files
committed
API exposes the latest submission for a task
To be able to show the user the status of their task, we need to be able to get the most recent submission. This makes it available as part of the API.
1 parent 92178cd commit 5afccb8

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

app/serializable/serializable_task.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
class SerializableTask < JSONAPI::Serializable::Resource
22
type 'tasks'
33

4+
has_one :latest_submission
45
has_many :submissions
56
belongs_to :framework
67

spec/requests/v1/tasks_spec.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
expect(json['data'][2]).to have_attribute(:status).with_value('in_progress')
6262
end
6363

64-
it 'can optionally return included models' do
64+
it 'can optionally include submissions' do
6565
task = FactoryBot.create(:task)
6666
submission = FactoryBot.create(:submission, task: task, aasm_state: 'pending')
6767

@@ -75,6 +75,22 @@
7575
expect(json['included'][0])
7676
.to have_attribute(:status).with_value('pending')
7777
end
78+
79+
it 'can optionally include the latest_submission' do
80+
task = FactoryBot.create(:task)
81+
submission = FactoryBot.create(:submission, task: task, aasm_state: 'pending')
82+
83+
get '/v1/tasks?include=latest_submission'
84+
85+
expect(response).to be_successful
86+
expect(json['data'][0]).to have_id(task.id)
87+
expect(json['data'][0])
88+
.to have_relationship(:latest_submission)
89+
.with_data('id' => submission.id, 'type' => 'submissions')
90+
91+
expect(json['included'][0])
92+
.to have_attribute(:status).with_value('pending')
93+
end
7894
end
7995

8096
describe 'GET /tasks?filter[status]=' do

0 commit comments

Comments
 (0)