Commit 70cba03640bccdc1069ea920b490892212e73131
1 parent
0c7e0d36
Exists in
master
and in
29 other branches
orders-plugin: features tests
Showing
6 changed files
with
250 additions
and
13 deletions
Show diff stats
@@ -0,0 +1,113 @@ | @@ -0,0 +1,113 @@ | ||
1 | +Feature: purchases | ||
2 | + As an enterprise's client | ||
3 | + I want to view my purchases | ||
4 | + In order to manage the products I bought | ||
5 | + | ||
6 | + Background: | ||
7 | + Given "ShoppingCart" plugin is enabled | ||
8 | + And "Orders" plugin is enabled | ||
9 | + And the following users | ||
10 | + | login | name | email | | ||
11 | + | moe | Moe | moe@springfield.com | | ||
12 | + | homer | Homer | homer@springfield.com | | ||
13 | + And the following enterprise | ||
14 | + | identifier | name | owner | | ||
15 | + | moes-tavern | Moes Tavern | moe | | ||
16 | + And the shopping basket is enabled on "Moes Tavern" | ||
17 | + And the following product_categories | ||
18 | + | name | | ||
19 | + | Beer | | ||
20 | + | Snacks | | ||
21 | + And the following products | ||
22 | + | owner | category | name | price | | ||
23 | + | moes-tavern | beer | Duff | 3.00 | | ||
24 | + | moes-tavern | snacks | French fries | 7.00 | | ||
25 | + And feature "products_for_enterprises" is enabled on environment | ||
26 | + And I am logged in as "homer" | ||
27 | + And I am on homer's control panel | ||
28 | + | ||
29 | + @selenium | ||
30 | + Scenario: view orders | ||
31 | + Given the following purchase from "homer" on "moes-tavern" that is "ordered" | ||
32 | + | product | quantity | price | | ||
33 | + | Duff | 3 | 3.50 | | ||
34 | + | French fries | 1 | 7.00 | | ||
35 | + When I follow "Purchases made" | ||
36 | + Then I should see "Moes Tavern" within any ".actor-name" | ||
37 | + And I should see "17.50" within any ".total" | ||
38 | + And I should see "Ordered" within any ".situation" | ||
39 | + | ||
40 | + @selenium | ||
41 | + Scenario: view orders with different status | ||
42 | + Given the following purchase from "homer" on "moes-tavern" that is "accepted" | ||
43 | + | product | quantity | price | | ||
44 | + | Duff | 2 | 3.50 | | ||
45 | + And the following purchase from "homer" on "moes-tavern" that is "delivered" | ||
46 | + | product | quantity | price | | ||
47 | + | French fries | 1 | 7.00 | | ||
48 | + When I follow "Purchases made" | ||
49 | + Then I should see "Accepted" within any ".situation" | ||
50 | + And I should see "Delivered" within any ".situation" | ||
51 | + | ||
52 | + @selenium | ||
53 | + Scenario: filter orders by situation | ||
54 | + Given the following purchase from "homer" on "moes-tavern" that is "accepted" | ||
55 | + | product | quantity | price | | ||
56 | + | Duff | 2 | 3.50 | | ||
57 | + And the following purchase from "homer" on "moes-tavern" that is "delivered" | ||
58 | + | product | quantity | price | | ||
59 | + | French fries | 1 | 7.00 | | ||
60 | + And I follow "Purchases made" | ||
61 | + And I should see "Accepted" within any ".situation" | ||
62 | + And I should see "Delivered" within any ".situation" | ||
63 | + And I select "Delivered" from "Status" | ||
64 | + When I press "Filter" | ||
65 | + Then I should not see "Accepted" within any ".situation" | ||
66 | + And I should see "Delivered" within any ".situation" | ||
67 | + | ||
68 | + | ||
69 | + @selenium | ||
70 | + Scenario: filter orders by code | ||
71 | + Given the following purchase from "homer" on "moes-tavern" that is "ordered" | ||
72 | + | product | quantity | price | | ||
73 | + | Duff | 2 | 3.50 | | ||
74 | + And the following purchase from "homer" on "moes-tavern" that is "ordered" | ||
75 | + | product | quantity | price | | ||
76 | + | French fries | 1 | 7.00 | | ||
77 | + And I follow "Purchases made" | ||
78 | + And I should see "1" within any ".code" | ||
79 | + And I should see "2" within any ".code" | ||
80 | + And I fill in "Code" with "2" | ||
81 | + When I press "Filter" | ||
82 | + Then I should not see "1" within any ".code" | ||
83 | + Then I should see "2" within any ".code" | ||
84 | + | ||
85 | + | ||
86 | + @selenium | ||
87 | + Scenario: filter orders by supplier | ||
88 | + Given the following users | ||
89 | + | login | name | email | | ||
90 | + | lovejoy | Reverend Lovejoy | lovejoy@springfield.com | | ||
91 | + And the following enterprise | ||
92 | + | identifier | name | owner | | ||
93 | + | first-church-of-springfield | First Church of Springfield | lovejoy | | ||
94 | + And the shopping basket is enabled on "First Church of Springfield" | ||
95 | + And the following product_categories | ||
96 | + | name | | ||
97 | + | Holy | | ||
98 | + And the following products | ||
99 | + | owner | category | name | price | | ||
100 | + | first-church-of-springfield | holy | Wine | 5.00 | | ||
101 | + And the following purchase from "homer" on "moes-tavern" that is "ordered" | ||
102 | + | product | quantity | price | | ||
103 | + | French fries | 1 | 7.00 | | ||
104 | + And the following purchase from "homer" on "first-church-of-springfield" that is "ordered" | ||
105 | + | product | quantity | price | | ||
106 | + | Wine | 5 | 10.50 | | ||
107 | + And I follow "Purchases made" | ||
108 | + And I should see "Moes Tavern" within any ".actor-name" | ||
109 | + And I should see "First Church of Springfield" within any ".actor-name" | ||
110 | + And I select "Moes Tavern" from "Supplier" | ||
111 | + When I press "Filter" | ||
112 | + Then I should see "Moes Tavern" within any ".actor-name" | ||
113 | + And I should not see "First Church of Springfield" within any ".actor-name" |
@@ -0,0 +1,104 @@ | @@ -0,0 +1,104 @@ | ||
1 | +Feature: sales | ||
2 | + As an enterprise's administrator | ||
3 | + I want to view my sales | ||
4 | + In order to manage the products I sold | ||
5 | + | ||
6 | + Background: | ||
7 | + Given "ShoppingCart" plugin is enabled | ||
8 | + And "Orders" plugin is enabled | ||
9 | + And the following users | ||
10 | + | login | name | email | | ||
11 | + | moe | Moe | moe@springfield.com | | ||
12 | + | homer | Homer | homer@springfield.com | | ||
13 | + And the following enterprise | ||
14 | + | identifier | name | owner | | ||
15 | + | moes-tavern | Moes Tavern | moe | | ||
16 | + And "Moe" is admin of "Moes Tavern" | ||
17 | + And the shopping basket is enabled on "Moes Tavern" | ||
18 | + And the following product_categories | ||
19 | + | name | | ||
20 | + | Beer | | ||
21 | + | Snacks | | ||
22 | + And the following products | ||
23 | + | owner | category | name | price | | ||
24 | + | moes-tavern | beer | Duff | 3.00 | | ||
25 | + | moes-tavern | snacks | French fries | 7.00 | | ||
26 | + And feature "products_for_enterprises" is enabled on environment | ||
27 | + And I am logged in as "moe" | ||
28 | + And I am on moes-tavern's control panel | ||
29 | + | ||
30 | + @selenium | ||
31 | + Scenario: view orders | ||
32 | + Given the following purchase from "homer" on "moes-tavern" that is "ordered" | ||
33 | + | product | quantity | price | | ||
34 | + | Duff | 3 | 3.50 | | ||
35 | + | French fries | 1 | 7.00 | | ||
36 | + When I follow "Purchases and Sales" | ||
37 | + Then I should see "Homer" within any ".actor-name" | ||
38 | + And I should see "17.50" within any ".total" | ||
39 | + And I should see "Ordered" within any ".situation" | ||
40 | + | ||
41 | + @selenium | ||
42 | + Scenario: view orders with different status | ||
43 | + Given the following purchase from "homer" on "moes-tavern" that is "accepted" | ||
44 | + | product | quantity | price | | ||
45 | + | Duff | 2 | 3.50 | | ||
46 | + And the following purchase from "homer" on "moes-tavern" that is "delivered" | ||
47 | + | product | quantity | price | | ||
48 | + | French fries | 1 | 7.00 | | ||
49 | + When I follow "Purchases and Sales" | ||
50 | + Then I should see "Accepted" within any ".situation" | ||
51 | + And I should see "Delivered" within any ".situation" | ||
52 | + | ||
53 | + @selenium | ||
54 | + Scenario: filter orders by situation | ||
55 | + Given the following purchase from "homer" on "moes-tavern" that is "accepted" | ||
56 | + | product | quantity | price | | ||
57 | + | Duff | 2 | 3.50 | | ||
58 | + And the following purchase from "homer" on "moes-tavern" that is "delivered" | ||
59 | + | product | quantity | price | | ||
60 | + | French fries | 1 | 7.00 | | ||
61 | + And I follow "Purchases and Sales" | ||
62 | + And I should see "Accepted" within any ".situation" | ||
63 | + And I should see "Delivered" within any ".situation" | ||
64 | + And I select "Delivered" from "Status" | ||
65 | + When I press "Filter" | ||
66 | + Then I should not see "Accepted" within any ".situation" | ||
67 | + And I should see "Delivered" within any ".situation" | ||
68 | + | ||
69 | + | ||
70 | + @selenium | ||
71 | + Scenario: filter orders by code | ||
72 | + Given the following purchase from "homer" on "moes-tavern" that is "ordered" | ||
73 | + | product | quantity | price | | ||
74 | + | Duff | 2 | 3.50 | | ||
75 | + And the following purchase from "homer" on "moes-tavern" that is "ordered" | ||
76 | + | product | quantity | price | | ||
77 | + | French fries | 1 | 7.00 | | ||
78 | + And I follow "Purchases and Sales" | ||
79 | + And I should see "1" within any ".code" | ||
80 | + And I should see "2" within any ".code" | ||
81 | + And I fill in "Code" with "2" | ||
82 | + When I press "Filter" | ||
83 | + Then I should not see "1" within any ".code" | ||
84 | + Then I should see "2" within any ".code" | ||
85 | + | ||
86 | + | ||
87 | + @selenium | ||
88 | + Scenario: filter orders by consumer | ||
89 | + Given the following users | ||
90 | + | login | name | email | | ||
91 | + | lovejoy | Reverend Lovejoy | lovejoy@springfield.com | | ||
92 | + And the following purchase from "homer" on "moes-tavern" that is "ordered" | ||
93 | + | product | quantity | price | | ||
94 | + | Duff | 5 | 10.50 | | ||
95 | + And the following purchase from "lovejoy" on "moes-tavern" that is "ordered" | ||
96 | + | product | quantity | price | | ||
97 | + | French fries | 1 | 7.00 | | ||
98 | + And I follow "Purchases and Sales" | ||
99 | + And I should see "Homer" within any ".actor-name" | ||
100 | + And I should see "Reverend Lovejoy" within any ".actor-name" | ||
101 | + And I select "Homer" from "Consumer" | ||
102 | + When I press "Filter" | ||
103 | + Then I should see "Homer" within any ".actor-name" | ||
104 | + And I should not see "Reverend Lovejoy" within any ".actor-name" |
plugins/orders/features/step_definitions/orders_steps.rb
0 → 100644
@@ -0,0 +1,20 @@ | @@ -0,0 +1,20 @@ | ||
1 | +Given /^the shopping basket is (enabled|disabled) on "([^""]*)"$/ do |status, name| | ||
2 | + status = status == 'enabled' | ||
3 | + enterprise = Enterprise.find_by_name(name) || Enterprise[name] | ||
4 | + settings = enterprise.shopping_cart_settings({:enabled => status}) | ||
5 | + settings.save! | ||
6 | +end | ||
7 | + | ||
8 | +Given /^the following purchase from "([^""]*)" on "([^""]*)" that is "([^""]*)"$/ do |consumer_identifier, enterprise_identifier, status, table| | ||
9 | + consumer = Person.find_by_name(consumer_identifier) || Person[consumer_identifier] | ||
10 | + enterprise = Enterprise.find_by_name(enterprise_identifier) || Enterprise[enterprise_identifier] | ||
11 | + order = OrdersPlugin::Purchase.new(:profile => enterprise, :consumer => consumer, :status => status) | ||
12 | + | ||
13 | + table.hashes.map{|item| item.dup}.each do |item| | ||
14 | + product = enterprise.products.find_by_name item[:product] | ||
15 | + item = order.items.build({:product => product, :name => item[:product], :quantity_consumer_ordered => item[:quantity], :price => item[:price]}) | ||
16 | + item.order = order | ||
17 | + end | ||
18 | + | ||
19 | + order.save! | ||
20 | +end |
plugins/orders/lib/ext/profile.rb
@@ -20,21 +20,21 @@ class Profile | @@ -20,21 +20,21 @@ class Profile | ||
20 | has_many :ordered_items, through: :orders, source: :items, order: 'name ASC' | 20 | has_many :ordered_items, through: :orders, source: :items, order: 'name ASC' |
21 | 21 | ||
22 | has_many :sales_consumers, through: :sales, source: :consumer | 22 | has_many :sales_consumers, through: :sales, source: :consumer |
23 | - has_many :purchases_consumers, through: :sales, source: :consumer | 23 | + has_many :purchases_consumers, through: :purchases, source: :consumer |
24 | 24 | ||
25 | has_many :sales_profiles, through: :sales, source: :profile | 25 | has_many :sales_profiles, through: :sales, source: :profile |
26 | - has_many :purchases_profiles, through: :sales, source: :profile | 26 | + has_many :purchases_profiles, through: :purchases, source: :profile |
27 | 27 | ||
28 | def sales_all_consumers | 28 | def sales_all_consumers |
29 | consumers = self.sales_consumers.order 'name ASC' | 29 | consumers = self.sales_consumers.order 'name ASC' |
30 | - consumers.concat self.suppliers.except_self.order('name ASC') if self.respond_to? :suppliers | ||
31 | - consumers.uniq | ||
32 | - end | ||
33 | - def purchases_all_consumers | ||
34 | - consumers = self.purchases_consumers.order 'name ASC' | ||
35 | consumers.concat self.consumers.except_self.order('name ASC') if self.respond_to? :consumers | 30 | consumers.concat self.consumers.except_self.order('name ASC') if self.respond_to? :consumers |
36 | consumers.uniq | 31 | consumers.uniq |
37 | end | 32 | end |
33 | + def purchases_all_suppliers | ||
34 | + suppliers = self.purchases_profiles.order 'name ASC' | ||
35 | + suppliers.concat self.suppliers.except_self.order('name ASC') if self.respond_to? :suppliers | ||
36 | + suppliers.uniq | ||
37 | + end | ||
38 | 38 | ||
39 | def self.create_orders_manager_role env_id | 39 | def self.create_orders_manager_role env_id |
40 | env = Environment.find env_id | 40 | env = Environment.find env_id |
plugins/orders/views/orders_plugin_admin/_filter_fields.html.slim
@@ -3,21 +3,21 @@ | @@ -3,21 +3,21 @@ | ||
3 | div= render 'orders_plugin/shared/daterangepicker/init' | 3 | div= render 'orders_plugin/shared/daterangepicker/init' |
4 | 4 | ||
5 | .field.state | 5 | .field.state |
6 | - label= t'views.filter.status' | 6 | + label for="status" = t'views.filter.status' |
7 | div= select_tag :status, | 7 | div= select_tag :status, |
8 | options_for_select([[t('views.filter.all'), ""]] + OrdersPlugin::Order::StatusText.map{ |id, name| [t(name), id] }, params[:status]) | 8 | options_for_select([[t('views.filter.all'), ""]] + OrdersPlugin::Order::StatusText.map{ |id, name| [t(name), id] }, params[:status]) |
9 | 9 | ||
10 | .field.code | 10 | .field.code |
11 | - label= t'views.filter.code' | 11 | + label for="code" = t'views.filter.code' |
12 | div= text_field_tag :code, params[:code] | 12 | div= text_field_tag :code, params[:code] |
13 | 13 | ||
14 | div class="field #{actor_name}" | 14 | div class="field #{actor_name}" |
15 | - label= t"terms.#{actor_name}.singular", transformation: :capitalize | 15 | + label for="#{actor_name}_id" = t"terms.#{actor_name}.singular", transformation: :capitalize |
16 | div= select_tag "#{actor_name}_id", | 16 | div= select_tag "#{actor_name}_id", |
17 | options_for_select([[t('views.filter.all'), ""]] + actors.map{ |a| [a.name, a.id] }, params["#{actor_name}_id"]) | 17 | options_for_select([[t('views.filter.all'), ""]] + actors.map{ |a| [a.name, a.id] }, params["#{actor_name}_id"]) |
18 | 18 | ||
19 | .field.delivery | 19 | .field.delivery |
20 | - label= t'views.filter.delivery' | 20 | + label for="delivery_method_id" = t'views.filter.delivery' |
21 | div= select_tag :delivery_method_id, | 21 | div= select_tag :delivery_method_id, |
22 | options_for_select([[t('views.filter.all'), ""]] + orders_owner.delivery_methods.map{ |dm| [dm.name, dm.id] }, params[:delivery_method_id]) | 22 | options_for_select([[t('views.filter.all'), ""]] + orders_owner.delivery_methods.map{ |dm| [dm.name, dm.id] }, params[:delivery_method_id]) |
23 | 23 |
plugins/orders/views/orders_plugin_admin/_index.html.erb
@@ -12,14 +12,14 @@ | @@ -12,14 +12,14 @@ | ||
12 | 12 | ||
13 | <% if @purchases.present? %> | 13 | <% if @purchases.present? %> |
14 | <div id='purchases' class="tab-pane"> | 14 | <div id='purchases' class="tab-pane"> |
15 | - <%= render 'orders_plugin_admin/purchases', actors: profile.sales_all_consumers, | 15 | + <%= render 'orders_plugin_admin/purchases', actors: profile.purchases_all_suppliers, |
16 | orders_owner: profile, orders: @purchases, month: @purchases_month, year: @purchases_year, wireframe_size: false %> | 16 | orders_owner: profile, orders: @purchases, month: @purchases_month, year: @purchases_year, wireframe_size: false %> |
17 | </div> | 17 | </div> |
18 | <% end %> | 18 | <% end %> |
19 | 19 | ||
20 | <% if @sales.present? %> | 20 | <% if @sales.present? %> |
21 | <div id='sales' class="tab-pane"> | 21 | <div id='sales' class="tab-pane"> |
22 | - <%= render 'orders_plugin_admin/sales', actors: profile.purchases_all_consumers, | 22 | + <%= render 'orders_plugin_admin/sales', actors: profile.sales_all_consumers, |
23 | orders_owner: profile, orders: @sales, month: @sales_month, year: @purchases_year, wireframe_size: false %> | 23 | orders_owner: profile, orders: @sales, month: @sales_month, year: @purchases_year, wireframe_size: false %> |
24 | </div> | 24 | </div> |
25 | <% end %> | 25 | <% end %> |