2 # This file is part of SMR.
4 # SMR is free software: you can redistribute it and/or modify it under the
5 # terms of the GNU General Public License as published by the Free Software
6 # Foundation, either version 3 of the License, or (at your option) any later
9 # SMR is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # SMR. If not, see <http://www.gnu.org/licenses/>.
21 # typical user session doing things except trading positions.
22 class Demo1UserSessionTest < ActionDispatch::IntegrationTest
27 # try to login as demo1 user
28 test "login as demo1" do
29 # see if it takes us to the login page
31 assert_response :redirect, 'accessing / should redirect to /login'
33 assert_response :success
34 assert_equal login_path, path
36 smr_login(LOGIN, PASSWORD)
40 # try to list documents, upload one, download it again, delete it
41 test "work with documents" do
42 smr_login(LOGIN, PASSWORD)
45 assert_response :success
46 assert_not_nil assigns(:portfolios)
47 assert_not_nil assigns(:document)
48 assert_not_nil docs = assigns(:documents)
49 assert docs.is_a?(UploadedFiles)
52 upload_file = fixture_file_upload('quote.yml', 'text/plain')
53 upload_sha1 = Digest::SHA1.hexdigest(upload_file.read)
57 {:action=>'create', :document=>{:comment=>'IntegrationTest', :content=>upload_file}, :id_portfolio=>'' },
58 {:html=>{:multipart=>true}, :referer=>documents_path }
59 assert_response :redirect
61 assert_not_nil docs = assigns(:documents), 'no document shown after upload'
62 assert docs.is_a?(UploadedFiles)
63 assert_not docs.empty?
64 assert d = docs.each.first
65 assert d.is_a?(UploadedFile)
68 get download_path, {}, {'HTTP_REFERER'=>documents_path}
69 assert_redirected_to documents_path
71 # download what we uploaded
72 get download_path, {:id=>d.id}, {'HTTP_REFERER'=>documents_path}
73 assert_equal @response.content_type, 'text/plain'
74 assert_equal Digest::SHA1.hexdigest(@response.body), upload_sha1
76 # delete what we uploaded
77 get delete_document_path, {:id=>d.id}, {'HTTP_REFERER'=>documents_path}
78 assert_redirected_to documents_path
82 # view cashflows from dividends and orders
83 test "view cashflow" do
84 smr_login(LOGIN, PASSWORD)
86 get cashflow_index_path(:timeframe=>:all_time, :portfolio=>0)
87 assert_response :success
88 assert_equal cashflow_index_path, path
89 assert_not_nil log = assigns(:log)
90 assert_not_nil forecast = assigns(:forecast)
92 assert log.is_a?(CashflowLog)
93 assert log.count > 0, 'CashflowLog is empty'
95 assert i.is_a?(CashflowItem)
98 assert forecast.is_a?(CashflowForecast)
99 assert forecast.count > 0, 'CashflowForecast is empty'
101 assert i.is_a?(CashflowItem)
106 # view and add FigureData
107 test "work with figure data" do
108 smr_login(LOGIN, PASSWORD)
111 assert_response :success
112 assert_equal figures_path, path
113 assert assigns(:securities).is_a?(Array)
114 assert assigns(:selected_security).is_a?(Security)
115 assert assigns(:have_data).is_a?(FalseClass)
117 # select a security that has figure data
118 get figures_path, {:id_security=>25, :show=>'this'}
119 assert_response :success
120 assert assigns(:have_data).is_a?(TrueClass)
121 assert assigns(:datatable).render # Raises if no data
124 # - no fixtures on BASF AG, therefore nothing should be shown at first
125 # and then only FigureData we added from here
128 :id_security=>15, # BASF AG
129 :id_figure_var=>4, # Demo1Var1
130 :period=>'year', :time=>1.days.ago.strftime('%Y-%m-%d'),
131 :analyst=>'integration test', :value=>1.23, :is_expected=>1,
132 :is_audited=>1, :comment=>'made by demo1 integration test'
135 get new_figure_path, :id_security=>figure_data[:id_security], :show=>'this'
136 assert_response :success
137 assert assigns(:figuredata).is_a?(FigureData)
138 assert assigns(:have_data).is_a?(FalseClass)
140 {:action=>'create', :figure_data=>figure_data},
141 {:referer=>figures_path}
144 assert_equal figures_path, path
145 assert assigns(:selected_security).is_a?(Security)
146 assert_equal assigns(:selected_security).id, figure_data[:id_security]
147 assert assigns(:have_data).is_a?(TrueClass)
149 # try again, but store FigureData on a FigureVar that belongs to
151 # note: thats something the Gui does not allow to do
152 figure_data[:id_figure_var] = 1 # FirstVar, belongs :id_user=1 (admin)
153 figure_data[:id_security] = 6 # CocaCola Inc.
154 get new_figure_path, :id_security=>figure_data[:id_security], :show=>'this'
155 assert_response :success
156 assert assigns(:have_data).is_a?(FalseClass)
158 {:action=>'create', :figure_data=>figure_data},
159 {:referer=>figures_path}
162 assert assigns(:have_data).is_a?(FalseClass)
166 # use the personal blog
167 test "read and blog articles" do
168 smr_login(LOGIN, PASSWORD)
171 assert_response :success
172 assert_equal blog_index_path, path
173 assert_not_nil blog = assigns(:blogroll)
174 assert blog.is_a?(Blog)
179 assert_response :success
180 assert_equal new_blog_path, path
181 assert_not_nil article = assigns(:article)
182 assert article.is_a?(Comment)
183 post blog_index_path,
184 {:action=>'create', :comment=>{:title=>'IntegrationTest Title', :comment=>'IntegrationTest Text'} },
185 {:referer=>blog_index_path }
187 assert_equal blog_index_path, path
188 assert_not_nil blog = assigns(:blogroll)
189 assert blog.is_a?(Blog)
190 assert_not blog.empty?
191 item = blog.each.first
192 assert item.is_a?(BlogItem)
193 assert_equal 'Comment', item.type
194 assert_equal 'IntegrationTest Title', item.title
195 assert_equal 'IntegrationTest Text', item.body
200 test "work with quoterecords" do
201 smr_login(LOGIN, PASSWORD)
203 get quoterecords_path
204 assert_response :success
206 # get quoterecords on E.On AG (there should not be any) for 2007-08-07
207 post set_session_params_path,
208 {:smr_browse_date=>{:day=>7, :month=>8, :year=>2007}},
209 {:referer=>quoterecords_path}
211 get quoterecords_path, { :id_security=>25, :show=>'this' }
212 assert_response :success
213 assert assigns(:selected_security).is_a?(Security)
214 assert_equal 25, assigns(:selected_security).id
216 assert_not_nil quote = assigns(:intraday_quotes).first
217 assert quote.is_a?(Quote)
219 # post a new quoterecord from :intraday_quotes observations
220 marker_qr=Digest::SHA1.hexdigest(Time.now.to_s)
221 post quoterecords_path,
224 :id=>'', :id_security=>quote.id_security, :id_quote=>quote.id,
225 :column=>'upward', :comment=>marker_qr,
226 :is_pivotal_point=>0, :is_uphit=>0, :is_downhit=>0, :is_signal=>0
228 :commit=>'record this one'
230 {:referer=>quoterecords_path}
231 assert_response :success
232 assert_equal quoterecords_path, path
234 # now we should see that one listed in previous records
235 assert_not_nil qrs = assigns(:quoterecords)
236 assert qrs.is_a?(Smr::Quoterecords)
238 assert_equal qr.comment, marker_qr
239 assert_equal qr.column, 'upward'
242 get quoterecord_path(:id=>qr.id)
243 assert_response :success
244 assert_not_nil qr_edit = assigns(:quoterecord)
245 assert_equal qr_edit.comment, qr.comment
246 marker_qr_edit=Digest::SHA1.hexdigest(marker_qr + Time.now.to_s)
247 post quoterecords_path,
250 :id=>qr_edit.id, :column=>'downward', :comment=>marker_qr_edit,
251 :is_pivotal_point=>0, :is_uphit=>0, :is_downhit=>0, :is_signal=>0
253 :commit=>'record this one'
255 {:referer=>quoterecords_path}
256 assert_response :success
257 assert_not_nil qrs_edited = assigns(:quoterecords)
258 assert_equal qrs_edited.first.comment, marker_qr_edit
262 # record rules on quoterecords
263 test "work with quoterecord rules" do
264 smr_login(LOGIN, PASSWORD)
266 get quoterecord_rules_path
267 assert_response :success
268 assert assigns(:rules).empty?
271 marker_rule1=Digest::SHA1.hexdigest('obey!' + Time.now.to_s)
272 get new_quoterecord_rule_path
273 assert_response :success
274 post quoterecord_rules_path,
276 :quoterecord_rule=>{:id=>'', :order=>1, :name=>'rule1', :rule=>marker_rule1},
277 :related_columns=>['secondary_rally', 'downward'],
280 {:referer=>new_quoterecord_rule_path}
282 assert_response :success
283 rules = assigns(:rules)
284 assert_not rules.empty?, 'we should have a rule by now'
285 assert_equal rules.first.name, 'rule1'
286 assert_equal rules.first.rule, marker_rule1
287 assert rules.first.get_related_columns.include?('downward'), 'column not related to new rule'
290 marker_edited=Digest::SHA1.hexdigest('I said obey!' + Time.now.to_s)
291 get new_quoterecord_rule_path, :id=>rules.first.id
292 assert_not_nil edit_rule = assigns(:rule)
293 assert_equal edit_rule.rule, marker_rule1
294 post quoterecord_rules_path,
296 :quoterecord_rule=>{:id=>edit_rule.id, :order=>1, :name=>edit_rule.name, :rule=>marker_edited},
297 :related_columns=>['secondary_reaction', 'upward'],
300 {:referer=>new_quoterecord_rule_path}
302 assert_response :success
303 assert_not_nil edited_rule = assigns(:rules).first
304 assert_equal edited_rule.name, 'rule1'
305 assert_equal edited_rule.rule, marker_edited
306 assert edited_rule.get_related_columns.include?('upward'), 'edited column relation not present'
310 # add a new portfolio and transfere existing position into it
311 test "add portfolio and transfer position" do
312 smr_login(LOGIN, PASSWORD)
313 get new_objects_portfolio_path
314 assert_response :success
315 assert_not_nil p = assigns(:portfolio)
316 assert p.is_a?(Portfolio)
319 post objects_portfolio_index_path,
321 :portfolio=>{:id=>'', :name=>'demo1_testportfolio', :taxallowance=>100, :comment=>'demo1_testcomment'},
322 :time_created=>'2015-04-08 15:26:58 -0400',
323 :commit=>'Save Portfolio'
325 {:referer=>new_objects_portfolio_path}
327 assert_response :success
328 assert_equal objects_portfolio_index_path, path
330 # find & edit existing and new Portfolio
333 assert_not_nil plist = assigns(:portfolios)
335 if p.name == 'Local Broker' then existing = p else new = p end
337 assert existing.is_a?(Portfolio), 'existing portfolio no located'
338 assert new.is_a?(Portfolio), 'new portfolio not located'
340 get edit_objects_portfolio_path(:id=>existing.id)
341 assert_response :success
342 assert_not_nil editing = assigns(:portfolio)
343 assert_equal existing.name, editing.name
345 # submit the transfer form, targeting the new portfolio
346 post objects_patch_portfolio_path,
348 :id_portfolio_transfer=>new.id,
349 :positions=>['14'], # we just *know* position 14 s;-) (from fixtures)
350 :commit=>'Transfer Positions'
352 {:referer=>edit_objects_portfolio_path(:id=>existing.id)}
354 assert_response :success
355 assert_equal objects_portfolio_index_path, path
356 assert_equal 1, Position.where(:id=>14, :id_portfolio=>new.id).count, 'transfered position #14 not in target portfolio'
360 # view an existing order
362 smr_login(LOGIN, PASSWORD)
364 get order_path(:id=>145)
365 assert_response :success
366 assert_equal order_path(:id=>145), path
367 assert_not_nil order = assigns(:order)
368 assert_not_nil documents = assigns(:documents)
370 assert order.is_a?(Order)
371 assert documents.is_a?(Smr::UploadedFiles)
373 get order_path(:id=>999999)
374 assert_response :redirect, 'viewing nonexisting Order does not redirect'
376 assert_response :success
377 assert_equal root_path, path, 'expected redirect to /'
381 # view report on closed positions and asset statistics
382 test "view report" do
383 smr_login(LOGIN, PASSWORD)
385 get report_index_path(:timeframe=>:all_time, :portfolio=>0)
386 assert_response :success
387 assert_equal report_index_path, path
388 assert_not_nil asset_totals = assigns(:asset_totals)
389 assert_not_nil closed_positions = assigns(:closed_positions)
390 assert_not_nil realized_gain = assigns(:realized_gain)
391 assert_not_nil revenue = assigns(:revenue)
392 #assert_not_nil charges_paid = assigns(:charges_paid) # disabled, see report controller
393 #assert_not_nil dividend_received = assigns(:dividend_received)
395 assert closed_positions.count > 0, 'No :closed_positions found'
396 closed_positions.each do |p|
397 assert p.is_a?(Smr::AssetPosition)
400 assert asset_totals.count > 0, 'No reporting on :asset_totals'
401 asset_totals.each do |t|
402 assert t.is_a?(Smr::Asset)
407 # portrait a Security and a Organization
408 test "view portraits" do
409 smr_login(LOGIN, PASSWORD)
411 get portrait_security_path(:id=>106) # of Country A 5.0% 2000(00)
412 assert_response :success
413 assert_not_nil last_trade = assigns(:last_trade)
414 assert_not_nil security = assigns(:security)
415 assert_not_nil positions = assigns(:positions)
416 assert_not_nil cashflow = assigns(:cashflow)
417 assert last_trade.is_a? Quote
418 assert security.is_a? Security
419 assert_equal 106, security.id, 'portrait on wrong Security'
420 assert positions.first.is_a? Smr::AssetPosition
421 assert cashflow.total > 0
423 get portrait_organization_path(:id=>5) # of Country A
424 assert_response :success
425 assert_not_nil organization = assigns(:organization)
426 assert_not_nil positions = assigns(:positions)
427 assert_not_nil cashflow = assigns(:cashflow)
428 assert organization.is_a? Organization
429 assert_equal 5, organization.id, 'portrait on wrong Organization'
430 assert positions.first.is_a? Smr::AssetPosition
431 assert cashflow.total > 0