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
38 changes: 38 additions & 0 deletions features/api/metrics/create.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@javascript
Feature: Product > Integration > Metrics index > Metric
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

Scenario: Create a method from the index page
Given I change to tab "Methods"
And I follow "Add a method"
When I fill in "Friendly name" with "Cotto e Funghi"
And I fill in "System name" with "cotto-e-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 metric "Cotto e Funghi"
And method "Cotto e Funghi" should have the following:
| Friendly name | Cotto e Funghi |
| Unit | hit |
| Description | The number of times this dish has been served |

Scenario: Create a metric from the index page
Given I change to tab "Metrics"
And I follow "Add a metric"
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 metric "Antipasti"
And metric "Antipasti" should have the following:
| Friendly name | Antipasti |
| Unit | order |
| Description | The number of antipasti dishes ordered |
josemigallas marked this conversation as resolved.
Show resolved Hide resolved
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 index > Metric
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 index
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 not be able to add a mapping rule to "Carbonara"
josemigallas marked this conversation as resolved.
Show resolved Hide resolved

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 not be able to add a mapping rule to "Pasta"
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 index > Metric
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:
| 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 not see field "metric[system_name]"
josemigallas marked this conversation as resolved.
Show resolved Hide resolved

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:
| 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.

4 changes: 0 additions & 4 deletions features/step_definitions/cms/provider_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
SimpleLayout.new(provider).import!
end

Given(/^the provider (has all the templates setup)$/) do |sentence|
step %(provider "#{@provider.domain}" #{sentence})
end

Given('provider has opt-out for credit card workflow on plan changes') do
search = '{% plan_widget application, wizard: true %}'
replacement = '{% plan_widget application, wizard: false %}'
Expand Down
4 changes: 0 additions & 4 deletions features/step_definitions/config_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
end
end

Given /^the provider has multiple applications (enabled|disabled)$/ do |value|
step %(provider "#{provider_or_master_name}" has multiple applications #{value})
end

Given /^provider "([^"]*)" has Browser CMS (activated|deactivated)$/ do |provider, value|
if value == 'deactivated'
raise 'BCMS cannot be deactivated!'
Expand Down
3 changes: 0 additions & 3 deletions features/step_definitions/credit_card_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@
provider.save!
end

Given(/^the provider has testing credentials for braintree$/) do
step %(provider "#{@provider.domain}" has testing credentials for braintree)
end
Given /^Braintree is stubbed for wizard$/ do
PaymentGateways::BrainTreeBlueCrypt.any_instance.stubs(:form_url).returns(hosted_success_provider_admin_account_braintree_blue_path(next_step: 'upgrade_plan'))
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
provider.save!
end

Given(/^the provider is (not )?charging$/) do |not_charging|
step %(provider "#{@provider.domain}" is #{not_charging}charging)
end

Given "{provider} is fake charging" do |provider|
provider.settings.allow_finance! unless provider.settings.finance.allowed?

Expand Down Expand Up @@ -65,12 +61,6 @@
end
end

# FIXME: "the provider" should be inside ParameterType 'provider' but @provider is not accesible from there
Given /^the provider has (prepaid|postpaid) billing enabled/ do |mode|
step %(provider "#{@provider.name}" has #{mode} billing enabled)
end


Given "{provider} doesn't have billing address" do |provider|
%w[zip name city state country phone address1].each do |attr|
provider.send("billing_address_#{attr}=", nil)
Expand Down
14 changes: 9 additions & 5 deletions features/step_definitions/metric_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,19 @@
assert find(:xpath, "//span[@id='metric_#{metric.id}_visible']")[:class] == visible
end

Then "{provider} should have metric {string}" do |provider, metric_name|
assert_not_nil provider.default_service.metrics.find_by_system_name(metric_name)
Then "{provider} {should} have metric {string}" do |provider, should, metric_name|
assert_equal should, provider.metrics.find_by(friendly_name: metric_name).present?
end

Then "{provider} should not have metric {string}" do |provider, metric_name|
assert_nil provider.default_service.metrics.find_by_system_name(metric_name)
Then "{metric} should have the following:" do |metric, table|
josemigallas marked this conversation as resolved.
Show resolved Hide resolved
check_metric_attributes(metric, table)
end

Then "{metric} should have the following:" do |metric, table|
Then "{method} should have the following:" do |method, table|
josemigallas marked this conversation as resolved.
Show resolved Hide resolved
check_metric_attributes(method, table)
end

def check_metric_attributes(metric, table)
table.raw.each do |row|
attribute = row[0].downcase.gsub(/\s+/, '_').to_sym
assert_equal row[1], metric.send(attribute)
Expand Down