Commit f639971b authored by Peter Leitzen's avatar Peter Leitzen

Merge branch '207935-status-page-json-changes' into 'master'

Resolve "Status Page MVC: JSON format and endpoints"

Closes #207935

See merge request gitlab-org/gitlab!26979
parents 6f976b81 1a2d9231
......@@ -9,9 +9,14 @@ module StatusPage
expose :updated_at
expose :created_at
expose :user_notes, as: :comments, using: IncidentCommentEntity
expose :links
private
def links
{ details: StatusPage::Storage.details_path(object.iid) }
end
def user_notes
Array(options[:user_notes])
end
......
......@@ -5,7 +5,7 @@ module StatusPage
entity IncidentEntity
def represent_list(resource)
represent(resource, except: [:comments])
{ incidents: represent(resource, except: [:comments]) }
end
def represent_details(resource, user_notes)
......
......@@ -8,11 +8,11 @@ module StatusPage
MAX_COMMENTS = 100
def self.details_path(id)
"incident/#{id}.json"
"data/incident/#{id}.json"
end
def self.list_path
'list.json'
'data/list.json'
end
class Error < StandardError
......
......@@ -5,6 +5,7 @@
"state",
"title",
"description",
"links",
"updated_at",
"created_at"
],
......@@ -16,6 +17,13 @@
},
"title": { "type": "string" },
"description": { "type": "string" },
"links": {
"type": "object",
"properties": {
"details": { "type": "string" }
},
"additionalProperties": false
},
"updated_at": { "type": "date" },
"created_at": { "type": "date" }
}
......
{
"type": "array",
"items": { "$ref": "basic_incident.json" },
"type": "object",
"required": ["incidents"],
"properties": {
"incidents": {
"type": "array",
"items": { "$ref": "basic_incident.json" }
}
},
"additionalProperties": false
}
......@@ -6,12 +6,12 @@ describe StatusPage::Storage do
describe '.details_path' do
subject { described_class.details_path(123) }
it { is_expected.to eq('incident/123.json') }
it { is_expected.to eq('data/incident/123.json') }
end
describe '.list_path' do
subject { described_class.list_path }
it { is_expected.to eq('list.json') }
it { is_expected.to eq('data/list.json') }
end
end
......@@ -19,7 +19,8 @@ describe StatusPage::IncidentEntity do
description: issue.description_html,
updated_at: issue.updated_at,
created_at: issue.created_at,
comments: []
comments: [],
links: { details: "data/incident/#{issue.iid}.json" }
)
end
......
......@@ -14,7 +14,7 @@ describe StatusPage::IncidentSerializer do
describe '.represent_list' do
let(:resource) { [issue] }
let(:json_entity) do
subject.represent_list(resource).map(&:with_indifferent_access)
subject.represent_list(resource).with_indifferent_access
end
it_behaves_like 'valid JSON schema', schema: 'status_page/incident_list'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment