Skip to content

Commit

Permalink
Merge branch 'US21_manter_nota' of https://github.com/fga-gpp-mds/Fal…
Browse files Browse the repository at this point in the history
…ko-2017.2-BackEnd into US21_manter_nota
  • Loading branch information
MateusO97 committed Dec 13, 2017
2 parents 090da54 + 7e3309c commit c76bbf9
Show file tree
Hide file tree
Showing 4 changed files with 232 additions and 13 deletions.
30 changes: 17 additions & 13 deletions app/helpers/metric_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,31 @@ module MetricHelper

def get_metrics(grade)
last_release = grade.project.releases.last
# if last_release.blank?
# raise HasNoReleases.new(message: "HasNoReleases")
# else
if last_release.blank?
return nil
else
metrics = calculate_metrics(last_release)

sum_of_weights = grade.weight_debts + grade.weight_velocity + grade.weight_burndown
if metrics.blank?
final_metric = 0
else
sum_of_weights = grade.weight_debts + grade.weight_velocity + grade.weight_burndown

final_metric = (Float (grade.weight_debts * metrics[:metric_debts_value]) +
(grade.weight_velocity * metrics[:metric_velocity_value]) +
(grade.weight_burndown * metrics[:metric_burndown_value])) /
sum_of_weights
final_metric = (Float (grade.weight_debts * metrics[:metric_debts_value]) +
(grade.weight_velocity * metrics[:metric_velocity_value]) +
(grade.weight_burndown * metrics[:metric_burndown_value])) /
sum_of_weights
end

return final_metric.round(1)
# end
end
end

def calculate_metrics(release)
sprint = release.sprints.last
# if sprint.blank?
# raise HasNoSprints.new(message: "HasNoSprints")
# else
if sprint.blank? || sprint.stories.blank?
return nil
else
if release.project.is_scoring == true
burned_stories = {}
date_axis = []
Expand Down Expand Up @@ -77,7 +81,7 @@ def calculate_metrics(release)
metric_velocity_value: metric_velocity_value,
metric_burndown_value: metric_burndown_value }
end
# end
end
end

def calculate_velocity_and_debt(metric)
Expand Down
64 changes: 64 additions & 0 deletions test/controllers/issues_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,28 @@ def mock.create_issue(name, body)
end
end

test "should reopen a issue" do
mock = Minitest::Mock.new
def mock.code
200
end

def mock.reopen_issue(name, body)
Sawyer::Resource.new(Sawyer::Agent.new("/issues_test"), title: name, body: body, number: "3")
end

Adapter::GitHubIssue.stub :new, mock do
post "/projects/#{@project.id}/reopen_issue", params: {
issue: {
"name": "Second Issue",
"body": "New Body"
}
}, headers: { Authorization: @token.result }
end
assert_response :success

end

test "should not create issues if user is not logged in" do

mock = Minitest::Mock.new
Expand Down Expand Up @@ -361,4 +383,46 @@ def mock.list_all_issues(name)
end
assert_response :not_found
end

test "should to see issues graphic if issues was created last month" do

mock = Minitest::Mock.new

def mock.get_github_user()
Sawyer::Resource.new(Sawyer::Agent.new("/issues_test"), login: "username_test")
end

def mock.list_all_issues(name)
[ Sawyer::Resource.new(Sawyer::Agent.new("/issues_test"), title: "issue", number: 9, id: 10, body: "This is a template body", created_at: "07/09/2017", closed_at: "12/09/2017") ]
end

Adapter::GitHubIssue.stub :new, mock do
post "/projects/#{@project.id}/issues/graphic", params: {
actual_date: "07/10/2017",
option: "month"
}, headers: { Authorization: @token.result }
end
assert_response :success
end

test "should to see issues graphic if issues was created two months ago" do

mock = Minitest::Mock.new

def mock.get_github_user()
Sawyer::Resource.new(Sawyer::Agent.new("/issues_test"), login: "username_test")
end

def mock.list_all_issues(name)
[ Sawyer::Resource.new(Sawyer::Agent.new("/issues_test"), title: "issue", number: 9, id: 10, body: "This is a template body", created_at: "07/08/2017", closed_at: "12/08/2017") ]
end

Adapter::GitHubIssue.stub :new, mock do
post "/projects/#{@project.id}/issues/graphic", params: {
actual_date: "07/10/2017",
option: "month"
}, headers: { Authorization: @token.result }
end
assert_response :success
end
end
13 changes: 13 additions & 0 deletions test/controllers/projects_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ def setup
"password_confirmation": "123456789"
)

@second_user = User.create(
"name": "Fernando",
"email": "[email protected]",
"password": "123456",
"password_confirmation": "123456"
)

@project = Project.create(
"name": "Falko",
"description": "Some project description 1.",
Expand All @@ -28,6 +35,7 @@ def setup
)

@token = AuthenticateUser.call(@user.email, @user.password)
@second_token = AuthenticateUser.call(@second_user.email, @second_user.password)
end

test "should create project" do
Expand Down Expand Up @@ -65,6 +73,11 @@ def setup
assert_response :success
end

test "should not to show another user projects" do
get "/projects/#{@project.id}", headers: { Authorization: @second_token.result }
assert_response :unauthorized
end

test "should update project" do
@old_name = @project.name
@old_description = @project.description
Expand Down
138 changes: 138 additions & 0 deletions test/helpers/metric_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
require "test_helper"

class VelocityHelperTest < ActiveSupport::TestCase
include VelocityHelper
include MetricHelper

def setup
@user = User.create(
name: "Ronaldo",
email: "[email protected]",
password: "123456789",
password_confirmation: "123456789"
)

@project = Project.create(
name: "Falko",
description: "Some project description.",
user_id: @user.id,
is_project_from_github: true,
is_scoring: true
)

@release = Release.create(
name: "R1",
description: "Description",
initial_date: "01/01/2018",
final_date: "01/01/2019",
amount_of_sprints: "20",
project_id: @project.id
)

@first_sprint = Sprint.create(
name: "Sprint 1",
description: "Sprint 1 us10",
initial_date: "06/10/2016",
final_date: "13/10/2018",
release_id: @release.id,
)

@second_sprint = Sprint.create(
name: "Sprint 2",
description: "Sprint 2 us10",
initial_date: "06/10/2016",
final_date: "13/10/2018",
release_id: @release.id,
)

@first_story = Story.create(
name: "Story 1",
description: "Story 1 us14",
assign: "Lucas",
pipeline: "In Progress",
initial_date: "01/01/2017",
issue_number: "8",
sprint_id: @first_sprint.id,
story_points: "5"
)

@second_story = Story.create(
name: "Story 2",
description: "Story 2 us14",
assign: "Lucas",
pipeline: "Done",
initial_date: "01/01/2017",
final_date: "01/02/2017",
issue_number: "9",
sprint_id: @first_sprint.id,
story_points: "8"
)

@third_story = Story.create(
name: "Story 3",
description: "Story 3 us14",
assign: "Lucas",
pipeline: "Done",
initial_date: "01/01/2017",
final_date: "01/02/2017",
issue_number: "10",
sprint_id: @first_sprint.id,
story_points: "3"
)

@another_first_story = Story.create(
name: "Story 1",
description: "Story 1 us13",
assign: "Lucas",
pipeline: "Done",
initial_date: "01/02/2017",
final_date: "01/03/2017",
issue_number: "1",
sprint_id: @second_sprint.id,
story_points: "13"
)

@another_second_story = Story.create(
name: "Story 1",
description: "Story 1 us13",
assign: "Lucas",
pipeline: "Done",
initial_date: "01/02/2017",
final_date: "01/03/2017",
issue_number: "2",
sprint_id: @second_sprint.id,
story_points: "5"
)

@token = AuthenticateUser.call(@user.email, @user.password)
end

test "Should calculate debts metric" do
grade_value_test = 0
grades = {}

planned_points = @another_first_story.story_points +
@another_second_story.story_points
burned_points = @another_first_story.story_points +
@another_second_story.story_points

metric_value_test = Float(planned_points - burned_points) / planned_points

if metric_value_test <= 0.2
grade_value_test += 4
elsif metric_value_test <= 0.4
grade_value_test += 3
elsif metric_value_test <= 0.6
grade_value_test += 2
elsif metric_value_test <= 0.9
grade_value_test += 1
elsif metric_value_test <= 1
grade_value_test += 0
end

grades = calculate_metrics(@release)
grade_value = grades[:metric_debts_value]

assert_equal grade_value_test, grade_value
end
end

0 comments on commit c76bbf9

Please sign in to comment.