Skip to content

Commit

Permalink
THREESCALE-7987: Update product metrics (#2857)
Browse files Browse the repository at this point in the history
* fixes n+1 query in metrics index presenter
* 🥒 updates cucumbers and ParamTypes
  • Loading branch information
josemigallas committed Dec 24, 2021
1 parent 09e8b6c commit 98faf03
Show file tree
Hide file tree
Showing 18 changed files with 234 additions and 187 deletions.
2 changes: 1 addition & 1 deletion app/presenters/api/metrics_index_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def create_path
protected

def raw_collection
@raw_collection ||= metrics? ? top_level_metrics : method_metrics
@raw_collection ||= (metrics? ? top_level_metrics : method_metrics).includes(:proxy_rules)
end

def metrics?
Expand Down
79 changes: 79 additions & 0 deletions features/api/metrics/create.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
@javascript
Feature: Product > Integration > Metrics > New
In order to track various metrics of my API
As a provider
I want to create them

Background:
Given a provider is logged in
And I go to the metrics and methods page

Rule: Tab methods
Background:
Given I change to tab "Methods"
And I follow "Add a method"

Scenario: Create a method with an existing system name
Given a method "Cotoletta" of the provider
When I fill in "Friendly name" with "Cotoletta 2"
And I fill in "System name" with "cotoletta"
And I press "Create Method"
Then I should see "Has already been taken"
And the provider should not have a method "Cotoletta 2"

Scenario: Create a method with an existing friendly name
Given a method "Cotoletta" of the provider
When I fill in "Friendly name" with "Cotoletta"
And I fill in "System name" with "cotoletta_2"
And I press "Create Method"
Then I should see "Has already been taken"
And the provider should not have a method with system name "cotoletta_2"

Scenario: Create a method from the index page
When I fill in "Friendly name" with "Cotto e Funghi"
And I fill in "System name" with "cotto_funghi"
And I fill in "Description" with "The number of times this dish has been served"
And I press "Create Method"
Then I should see "Cotto e Funghi"
And the provider should have a method "Cotto e Funghi"
And method "Cotto e Funghi" should have the following attributes:
| Friendly name | Cotto e Funghi |
| System name | cotto_funghi |
| Description | The number of times this dish has been served |

Rule: Tab metrics
Background:
Given I change to tab "Metrics"
And I follow "Add a metric"

Scenario: Create a metrics with an existing system name
Given a metric "Carni" of the provider
When I fill in "Friendly name" with "Carni 2"
And I fill in "System name" with "Carni"
And I fill in "Unit" with "servings"
And I press "Create Metric"
Then I should see "Has already been taken"
And the provider should not have a metric "Carni 2"

Scenario: Create a metric with an existing friendly name
Given a metric "Carni" of the provider
When I fill in "Friendly name" with "Carni"
When I fill in "System name" with "carni_2"
And I fill in "Unit" with "servings"
And I press "Create Metric"
Then I should see "Has already been taken"
Then the provider should not have a metric with system name "carni_2"

Scenario: Create a metric from the index page
When I fill in "Friendly name" with "Antipasti"
And I fill in "System name" with "antipasti"
And I fill in "Unit" with "order"
And I fill in "Description" with "The number of antipasti dishes ordered"
And I press "Create Metric"
Then I should see "Antipasti"
And the provider should have a metric "Antipasti"
And metric "Antipasti" should have the following attributes:
| Friendly name | Antipasti |
| System name | antipasti |
| Unit | order |
| Description | The number of antipasti dishes ordered |
32 changes: 32 additions & 0 deletions features/api/metrics/delete.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@javascript
Feature: Product > Integration > Metrics > Edit
In Order to change a plan
As a provider
I should be able to delete a metric

Background:
Given a provider is logged in
And the following metrics:
| Pasta |
And the following methods:
| Carbonara |
And I go to the metrics and methods page

Scenario: Delete a method from the index page
Given I change to tab "Methods"
When I follow "Carbonara"
And I press "Delete" and I confirm dialog box
Then I should not see metric "Carbonara"
And the provider should not have metric "Carbonara"

Scenario: Delete a metric from the index page
Given I change to tab "Metrics"
When I follow "Pasta"
And I press "Delete" and I confirm dialog box
Then I should not see metric "Pasta"
And the provider should not have metric "Pasta"

Scenario: Default metric can't be deleted
Given I change to tab "Metrics"
When I follow "Hits"
Then I should not see "Delete"
71 changes: 37 additions & 34 deletions features/api/metrics/index.feature
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@javascript
Feature: Product > Metrics index
Feature: Product > Integration > Metrics
In order to control the way my buyers are using my API
As a provider
I want to see their methods and metrics
Expand All @@ -16,37 +16,40 @@ Feature: Product > Metrics index
| Amatriciana |
And I go to the metrics and methods page

Scenario: Default tab is methods
Then I should see the following methods:
| Margherita |
| Diavola |
| Carbonara |
| Amatriciana |
Rule: Tab methods
Scenario: Default tab is methods
Then I should see the following methods:
| Margherita |
| Diavola |
| Carbonara |
| Amatriciana |

Scenario: New method button
Then I should see "Add a method"

Scenario: Methods and mapping rules
Given method "Diavola" is not mapped
And method "Carbonara" is mapped
When I change to tab "Methods"
Then I should be able to add a mapping rule to "Diavola"
But I should see "Carbonara" already mapped

Rule: Tab metrics
Background:
Given I change to tab "Metrics"

Scenario: Metrics table
Then I should see the following metrics:
| Hits |
| Pizza |
| Pasta |

Scenario: New metrics button
Then I should see "Add a metric"

Scenario: Change tab to metrics
When I change to tab "Metrics"
Then I should see the following metrics:
| Hits |
| Pizza |
| Pasta |

Scenario: New method button
Then I should see "Add a method"

Scenario: New metrics button
When I change to tab "Metrics"
Then I should see "Add a metric"

Scenario: Methods and mapping rules
Given method "Diavola" is not mapped
And method "Carbonara" is mapped
When I change to tab "Methods"
Then I should be able to add a mapping rule to "Diavola"
But I should not be able to add a mapping rule to "Carbonara"

Scenario: Metrics and mapping rules
Given metric "Pizza" is not mapped
And metric "Pasta" is mapped
When I change to tab "Metrics"
Then I should be able to add a mapping rule to "Pizza"
But I should not be able to add a mapping rule to "Pasta"
Scenario: Metrics and mapping rules
Given metric "Pizza" is not mapped
And metric "Pasta" is mapped
When I change to tab "Metrics"
Then I should be able to add a mapping rule to "Pizza"
But I should see "Pasta" already mapped
39 changes: 39 additions & 0 deletions features/api/metrics/update.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@javascript
Feature: Product > Integration > Metrics > Edit
In order to change my metrics for whatever reason
As a provider
I want to be able to modify them

Background:
Given a provider is logged in
And the following metrics:
| Antipasti |
And the following methods:
| Burrata |
And I go to the metrics and methods page

Scenario: Edit a method from the index page
Given I change to tab "Methods"
When I follow "Burrata"
And I fill in "Friendly name" with "Burrata Panzanella"
And I press "Update Method"
Then I should see "Burrata Panzanella"
And method "Burrata Panzanella" should have the following attributes:
| Friendly name | Burrata Panzanella |
| Unit | hit |

Scenario: Can't change system name of default metric
Given I change to tab "Metrics"
When I follow "Hits"
Then I should see field "System name" disabled

Scenario: Edit a metric from the index page
Given I change to tab "Metrics"
When I follow "Antipasti"
And I fill in "Friendly name" with "Carni"
And I fill in "Unit" with "Orders"
And I press "Update Metric"
Then I should see "Carni"
And metric "Carni" should have the following attributes:
| Friendly name | Carni |
| Unit | Orders |
32 changes: 0 additions & 32 deletions features/old/api/metrics/creation.feature

This file was deleted.

24 changes: 0 additions & 24 deletions features/old/api/metrics/deletion.feature

This file was deleted.

20 changes: 0 additions & 20 deletions features/old/api/metrics/methods.feature

This file was deleted.

29 changes: 0 additions & 29 deletions features/old/api/metrics/update.feature

This file was deleted.

21 changes: 14 additions & 7 deletions features/step_definitions/api/metrics_steps.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# frozen_string_literal: true

Given('the following metrics:') do |table|
Given('the following metric(s):') do |table|
table.raw.flatten.each do |name|
FactoryBot.create(:metric, service: @provider.default_service, system_name: name, friendly_name: name)
end
end

Given('the following methods:') do |table|
Given('the following method(s):') do |table|
table.raw.flatten.each do |name|
FactoryBot.create(:method, owner: @provider.default_service, friendly_name: name)
end
Expand Down Expand Up @@ -38,9 +38,16 @@ def map_or_unmap_metric(metric, mapped)
end
end

Then('I {should} be able to add a mapping rule to {string}') do |not_mapped, name|
td = find('table tbody tr', text: name).find('[data-label="Mapped"]')
assert_equal not_mapped ? 'Add a mapping rule' : '', td.text
Then('I should be able to add a mapping rule to {string}') do |name|
assert_equal 'Add a mapping rule', find_mapped_cell_in_table(name).text
end

Then('I should see {string} (already )mapped') do |name|
assert_equal '', find_mapped_cell_in_table(name).text
end

def find_mapped_cell_in_table(text)
find('.pf-c-table tbody tr', text: text).find('[data-label="Mapped"]')
end

def find_rows(metrics, within:)
Expand All @@ -52,9 +59,9 @@ def find_rows(metrics, within:)
end

def methods_table
find 'table[aria-label="Methods table"]'
find '.pf-c-table[aria-label="Methods table"]'
end

def metrics_table
find 'table[aria-label="Metrics table"]'
find '.pf-c-table[aria-label="Metrics table"]'
end

0 comments on commit 98faf03

Please sign in to comment.