Commit 83982b92 authored by Kushal Pandya's avatar Kushal Pandya

Restructure Epic data map structure for refactored Epic app

parent b5527d26
module EpicsHelper
def epic_show_app_data(epic, opts)
author = epic.author
group = epic.group
todo = issuable_todo(epic)
epic_meta = {
epic_id: epic.id,
created: epic.created_at,
author: {
name: author.name,
url: user_path(author),
username: "@#{author.username}",
src: opts[:author_icon]
},
author: epic_author(epic, opts),
todo_exists: todo.present?,
todo_path: group_todos_path(group),
start_date: epic.start_date,
......@@ -34,7 +28,12 @@ module EpicsHelper
due_date: epic.due_date_sourcing_milestone&.due_date
},
end_date: epic.end_date,
state: epic.state
state: epic.state,
namespace: group.path,
labels_path: group_labels_path(group, format: :json, only_group_labels: true, include_ancestor_groups: true),
toggle_subscription_path: toggle_subscription_group_epic_path(group, epic),
labels_web_url: group_labels_path(group),
epics_web_url: group_epics_path(group)
}
epic_meta[:todo_delete_path] = dashboard_todo_path(todo) if todo.present?
......@@ -44,6 +43,8 @@ module EpicsHelper
participants: participants,
subscribed: epic.subscribed?(current_user))
# TODO: Remove from `namespace` to epics_web_url
# from below as it is already included in `epic_meta`
{
initial: initial.to_json,
meta: epic_meta.to_json,
......@@ -55,6 +56,15 @@ module EpicsHelper
}
end
def epic_author(epic, opts)
{
name: epic.author.name,
url: user_path(epic.author),
username: "@#{epic.author.username}",
src: opts[:author_icon]
}
end
def epic_endpoint_query_params(opts)
opts[:data] ||= {}
opts[:data][:endpoint_query_params] = {
......
......@@ -30,10 +30,12 @@ describe EpicsHelper do
expected_keys = %i(initial meta namespace labels_path toggle_subscription_path labels_web_url epics_web_url)
expect(data.keys).to match_array(expected_keys)
expect(meta_data.keys).to match_array(%w[
created author epic_id todo_exists todo_path state
start_date start_date_fixed start_date_is_fixed start_date_from_milestones start_date_sourcing_milestone_title
end_date due_date due_date_fixed due_date_is_fixed due_date_from_milestones due_date_sourcing_milestone_title
start_date_sourcing_milestone_dates due_date_sourcing_milestone_dates
epic_id created author todo_exists todo_path start_date
start_date_is_fixed start_date_fixed start_date_from_milestones
start_date_sourcing_milestone_title start_date_sourcing_milestone_dates
due_date due_date_is_fixed due_date_fixed due_date_from_milestones due_date_sourcing_milestone_title
due_date_sourcing_milestone_dates end_date state namespace labels_path toggle_subscription_path
labels_web_url epics_web_url
])
expect(meta_data['author']).to eq({
'name' => user.name,
......@@ -74,15 +76,21 @@ describe EpicsHelper do
meta_data = JSON.parse(data[:meta])
expect(meta_data.keys).to match_array(%w[
created author epic_id todo_exists todo_path state
start_date start_date_fixed start_date_is_fixed start_date_from_milestones start_date_sourcing_milestone_title
end_date due_date due_date_fixed due_date_is_fixed due_date_from_milestones due_date_sourcing_milestone_title
start_date_sourcing_milestone_dates due_date_sourcing_milestone_dates
epic_id created author todo_exists todo_path start_date
start_date_is_fixed start_date_fixed start_date_from_milestones
start_date_sourcing_milestone_title start_date_sourcing_milestone_dates
due_date due_date_is_fixed due_date_fixed due_date_from_milestones due_date_sourcing_milestone_title
due_date_sourcing_milestone_dates end_date state namespace labels_path toggle_subscription_path
labels_web_url epics_web_url
])
expect(meta_data['start_date']).to eq('2000-01-01')
expect(meta_data['start_date_sourcing_milestone_title']).to eq(milestone1.title)
expect(meta_data['start_date_sourcing_milestone_dates']['start_date']).to eq(milestone1.start_date.to_s)
expect(meta_data['start_date_sourcing_milestone_dates']['due_date']).to eq(milestone1.due_date.to_s)
expect(meta_data['due_date']).to eq('2000-01-02')
expect(meta_data['due_date_sourcing_milestone_title']).to eq(milestone2.title)
expect(meta_data['due_date_sourcing_milestone_dates']['start_date']).to eq(milestone2.start_date.to_s)
expect(meta_data['due_date_sourcing_milestone_dates']['due_date']).to eq(milestone2.due_date.to_s)
end
end
end
......
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