wordjelly-auth 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,168 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe "bar_code request spec",:bar_code => true,:shopping => true, :type => :request do
4
+
5
+ before(:all) do
6
+ ActionController::Base.allow_forgery_protection = false
7
+ User.delete_all
8
+ Auth::Client.delete_all
9
+ Shopping::CartItem.delete_all
10
+ Shopping::Product.delete_all
11
+ Auth::Shopping::BarCode.delete_all
12
+
13
+ ## THIS PRODUCT IS USED IN THE CART_ITEM FACTORY, TO PROVIDE AND ID.
14
+
15
+ #@product = Shopping::Product.new(:name => "test product", :price => 400.00)
16
+
17
+ #@product.save
18
+
19
+ @u = User.new(attributes_for(:user_confirmed))
20
+ @u.save
21
+
22
+ @c = Auth::Client.new(:resource_id => @u.id, :api_key => "test", :app_ids => ["testappid"])
23
+ @c.redirect_urls = ["http://www.google.com"]
24
+ @c.versioned_create
25
+ @u.client_authentication["testappid"] = "testestoken"
26
+ @u.save
27
+ @ap_key = @c.api_key
28
+ @headers = { "CONTENT_TYPE" => "application/json" , "ACCEPT" => "application/json", "X-User-Token" => @u.authentication_token, "X-User-Es" => @u.client_authentication["testappid"], "X-User-Aid" => "testappid"}
29
+
30
+
31
+
32
+ ### CREATE ONE ADMIN USER
33
+
34
+ ### It will use the same client as the user.
35
+ @admin = User.new(attributes_for(:admin_confirmed))
36
+ @admin.admin = true
37
+
38
+ @admin.client_authentication["testappid"] = "testestoken2"
39
+ @admin.save
40
+
41
+ @admin_headers = { "CONTENT_TYPE" => "application/json" , "ACCEPT" => "application/json", "X-User-Token" => @admin.authentication_token, "X-User-Es" => @admin.client_authentication["testappid"], "X-User-Aid" => "testappid"}
42
+
43
+ end
44
+
45
+
46
+
47
+ context " -- json requests -- " do
48
+
49
+ before(:each) do
50
+ Shopping::CartItem.delete_all
51
+ Shopping::Product.delete_all
52
+ Auth::Shopping::BarCode.delete_all
53
+ end
54
+
55
+
56
+ it " -- assings a barcode to a product -- ", :assigns_bar_code => true do
57
+
58
+ product = Auth.configuration.product_class.constantize.new
59
+ product.resource_id = @admin.id.to_s
60
+ product.resource_class = @admin.class.name
61
+ product.price = 10
62
+ product.name = "test product"
63
+ product.bar_code_tag = "hello world"
64
+ product.signed_in_resource = @admin
65
+
66
+ post shopping_products_path,{product: product.attributes.merge({:bar_code_tag => product.bar_code_tag}) , :api_key => @ap_key, :current_app_id => "testappid"}.to_json, @admin_headers
67
+
68
+
69
+ expect(response.code).to eq("201")
70
+
71
+ #puts (Auth::Shopping::BarCode.all.size)
72
+
73
+ #product = Shopping::Product.find(product.id)
74
+
75
+ bar_code = Auth::Shopping::BarCode.where(:bar_code_tag => "hello world")
76
+
77
+ expect(bar_code.first).not_to be_nil
78
+
79
+ end
80
+
81
+
82
+ it " -- removes barcode from product -- ", :remove_bar_code => true do
83
+
84
+ product = Auth.configuration.product_class.constantize.new
85
+ product.resource_id = @admin.id.to_s
86
+ product.resource_class = @admin.class.name
87
+ product.price = 10
88
+ product.name = "test product"
89
+ product.bar_code_tag = "hello world"
90
+ product.signed_in_resource = @admin
91
+ expect(product.save).to be_truthy
92
+
93
+ product_to_update = {:product => {:remove_bar_code => "1"}, api_key: @ap_key, :current_app_id => "testappid"}
94
+
95
+ put shopping_product_path(:id => product.id.to_s),product_to_update.to_json,@admin_headers
96
+
97
+ expect(response.code).to eq("204")
98
+
99
+ bar_code = Auth::Shopping::BarCode.where(:assigned_to_object_id => product.id.to_s)
100
+ expect(bar_code.first).to be_nil
101
+
102
+ end
103
+
104
+ it " -- remove barcode from product returns true, if that barcode was already removed from that product -- ", :remove_bar_code_twice => true do
105
+
106
+ product = Auth.configuration.product_class.constantize.new
107
+ product.resource_id = @admin.id.to_s
108
+ product.resource_class = @admin.class.name
109
+ product.price = 10
110
+ product.name = "test product"
111
+ product.bar_code_tag = "hello world"
112
+ product.signed_in_resource = @admin
113
+ expect(product.save).to be_truthy
114
+
115
+ product_to_update = {:product => {:remove_bar_code => "1"}, api_key: @ap_key, :current_app_id => "testappid"}
116
+
117
+ put shopping_product_path(:id => product.id.to_s),product_to_update.to_json,@admin_headers
118
+
119
+ expect(response.code).to eq("204")
120
+
121
+ bar_code = Auth::Shopping::BarCode.where(:assigned_to_object_id => product.id.to_s)
122
+ expect(bar_code.first).to be_nil
123
+
124
+ expect(Auth::Shopping::BarCode.clear_object(product.id.to_s)).to be_truthy
125
+
126
+ end
127
+
128
+
129
+ it " -- will not assing the same barcode to another object , saves the object, but will still return a 422, but will not assign the barcode. -- ", :bar_code_unique => true do
130
+
131
+ product = Auth.configuration.product_class.constantize.new
132
+ product.resource_id = @admin.id.to_s
133
+ product.resource_class = @admin.class.name
134
+ product.price = 10
135
+ product.name = "test product"
136
+ product.bar_code_tag = "hello world"
137
+ product.signed_in_resource = @admin
138
+ expect(product.save).to be_truthy
139
+
140
+ product_two = Shopping::Product.new
141
+ product_two.resource_id = @admin.id.to_s
142
+ product_two.resource_class = @admin.class.name
143
+ product_two.price = 10
144
+ product_two.name = "test product"
145
+ product_two.bar_code_tag = "hello world"
146
+ product_two.signed_in_resource = @admin
147
+ #expect(product_two.save).to be_truthy
148
+ #expect(product_two.errors).not_to be_empty
149
+
150
+ post shopping_products_path,{product: product_two.attributes.merge({:bar_code_tag => product_two.bar_code_tag}) , :api_key => @ap_key, :current_app_id => "testappid"}.to_json, @admin_headers
151
+ expect(response.code).to eq("422")
152
+ ## product still gets saved.
153
+
154
+ bar_code = Auth::Shopping::BarCode.all
155
+ expect(bar_code.size).to eq(1)
156
+ expect(bar_code.first.assigned_to_object_id).to eq(product.id.to_s)
157
+
158
+ end
159
+
160
+ it " - reassings the barcode to another object, if it has been removed from one object -- " do
161
+
162
+
163
+
164
+ end
165
+
166
+ end
167
+
168
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wordjelly-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - bhargav
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-11 00:00:00.000000000 Z
11
+ date: 2018-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xpath
@@ -1535,6 +1535,7 @@ files:
1535
1535
  - spec/models/auth/shopping/product.json
1536
1536
  - spec/rails_helper.rb
1537
1537
  - spec/requests/search/search_request_spec.rb
1538
+ - spec/requests/shopping/bar_code_request_spec.rb
1538
1539
  - spec/requests/shopping/cart_item_request_spec.rb
1539
1540
  - spec/requests/shopping/cart_request_spec.rb
1540
1541
  - spec/requests/shopping/discount_request_spec.rb
@@ -1646,6 +1647,7 @@ test_files:
1646
1647
  - spec/requests/shopping/cart_request_spec.rb
1647
1648
  - spec/requests/shopping/discount_request_spec.rb
1648
1649
  - spec/requests/shopping/payment_request_spec.rb
1650
+ - spec/requests/shopping/bar_code_request_spec.rb
1649
1651
  - spec/requests/shopping/cart_item_request_spec.rb
1650
1652
  - spec/requests/user/otp_basic_flow_request_spec.rb
1651
1653
  - spec/requests/user/password_request_spec.rb