Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update product metrics #2857

Merged
merged 14 commits into from
Dec 24, 2021
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
70 changes: 70 additions & 0 deletions features/api/metrics/create.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
@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 the provider should not have a metric "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 the provider should have a metric with system name "cotoletta_2"

Scenario: Create a method from the index page
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 metric "Cotto e Funghi"
And method "Cotto e Funghi" should have the following attributes:
| Friendly name | Cotto e Funghi |
| Unit | hit |
| 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 press "Create Metric"
Then 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"
And I fill in "System name" with "carni_2"
And I press "Create Metric"
Then the provider should 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 |
| 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:
| Carbonnara |
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 "Carbonnara"
And I press "Delete" and I confirm dialog box
Then I should not see metric "Carbonnara"
And the provider should not have metric "Cabonnara"
josemigallas marked this conversation as resolved.
Show resolved Hide resolved

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