/
summoners_controller_spec.rb
1985 lines (1697 loc) · 74 KB
/
summoners_controller_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
require 'rails_helper'
require 'spec_contexts.rb'
describe SummonersController, type: :controller do
include_context 'spec setup'
include_context 'determinate speech'
before :each do
allow(controller).to receive(:summoner_params).and_return(summoner_params)
Timecop.freeze(Time.new(2018, 2, 7))
@today = "#{Time.now.strftime("%Y-%m-%d")}/#{(Time.now + 1.day).strftime("%Y-%m-%d")}"
end
describe 'POST teammates' do
let(:action) { :teammates }
let(:summoner_params) do
{
name: 'Hero man',
champion: 'Shyvana',
region: 'NA1',
role: '',
list_order: 'highest',
metric: '',
position_details: '',
time: ''
}
end
before :each do
@matches = create_list(:match, 5)
summoner = create(:summoner, name: 'Hero man')
teammate_summoner = create(:summoner, name: 'Teammate man')
other_summoner = create(:summoner, name: 'Other man')
match_data = [
{ match: { win: true }, summoner_performance: { champion_id: 102, role: 'JUNGLE' }, teammate: { summoner_id: teammate_summoner.id } },
{ match: { win: true }, summoner_performance: { champion_id: 102, role: 'JUNGLE' }, teammate: { summoner_id: teammate_summoner.id } },
{ match: { win: true }, summoner_performance: { champion_id: 102, role: 'JUNGLE' }, teammate: { summoner_id: teammate_summoner.id } },
{ match: { win: true }, summoner_performance: { champion_id: 102, role: 'JUNGLE' }, teammate: { summoner_id: other_summoner.id } },
{ match: { win: true }, summoner_performance: { champion_id: 102, role: 'JUNGLE' }, teammate: { summoner_id: other_summoner.id } },
]
@matches.each_with_index do |match, i|
summoner_performance = match.team1.summoner_performances.first
teammate_performance = match.team1.summoner_performances.last
opposing_team = summoner_performance.team == match.team1 ? match.team2 : match.team1
if match_data[i][:match][:win]
match.update!(winning_team: summoner_performance.team)
else
match.update!(winning_team: opposing_team)
end
summoner_performance.update!(
match_data[i][:summoner_performance].merge({ summoner_id: summoner.id })
)
teammate_performance.update!(match_data[i][:teammate])
end
end
context 'with a time specified' do
before :each do
summoner_params[:time] = @today
end
it 'should indicate that the teammates are from games in the time interval' do
post action, params: params
expect(speech).to eq 'The teammate who has helped Hero man get the highest win rate from Wed Feb 7 at 12am to Thu Feb 8 at 12am playing Shyvana Jungle is Teammate man.'
end
end
context 'with no champion specified' do
before :each do
summoner_params[:champion] = ''
end
it 'should specify the highest win rate teammates for the summoner across champions' do
post action, params: params
expect(speech).to eq 'The teammate who has helped Hero man get the highest win rate Jungle is Teammate man.'
end
context 'with no role specified' do
before :each do
summoner_params[:role] = ''
end
context 'with one role' do
it 'should specify the highest win rate teammates for the summoner independent of role or champion' do
post action, params: params
expect(speech).to eq 'The teammate who has helped Hero man get the highest win rate Jungle is Teammate man.'
end
end
context 'with multiple roles' do
before :each do
@matches.first.summoner_performances.first.update(role: 'DUO_SUPPORT')
end
it 'should not include the roles' do
post action, params: params
expect(speech).to eq 'The teammate who has helped Hero man get the highest win rate across Jungle and Support is Teammate man.'
end
end
end
end
context 'with no summoners returned' do
context 'with no position offset' do
before :each do
summoner_params[:name] = 'Inactive player'
end
it 'should indicate the summoner has not played any games' do
post action, params: params
expect(speech).to eq 'Inactive player is not an active player in ranked.'
end
end
context 'with a position offset' do
before :each do
summoner_params[:list_position] = 10000
end
it 'should indicate that the summoner has not played enough games' do
post action, params: params
expect(speech).to eq 'Hero man has played with seventeen summoners as Shyvana Jungle.'
end
context 'with a role' do
before :each do
summoner_params[:role] = 'JUNGLE'
end
it 'should indicate that the summoner has not played enough games in that role' do
post action, params: params
expect(speech).to eq 'Hero man has played with seventeen summoners as Shyvana Jungle.'
end
end
end
end
context 'with a single summoner returned' do
before :each do
summoner_params[:list_size] = 1
end
context 'with complete results' do
it 'should return the single teammate' do
post action, params: params
expect(speech).to eq 'The teammate who has helped Hero man get the highest win rate playing Shyvana Jungle is Teammate man.'
end
context 'with a position offset' do
before :each do
summoner_params[:list_position] = 2
end
it 'should return the offset single teammate' do
post action, params: params
expect(speech).to eq 'The teammate who has helped Hero man get the second highest win rate playing Shyvana Jungle is Other man.'
end
end
context 'with a role specified' do
before :each do
summoner_params[:role] = 'JUNGLE'
end
it 'should return the single teammate' do
post action, params: params
expect(speech).to eq 'The teammate who has helped Hero man get the highest win rate playing Shyvana Jungle is Teammate man.'
end
end
end
context 'with incomplete results' do
before :each do
summoner_params[:list_position] = 17
summoner_params[:list_size] = 2
end
it 'should return the single teammate' do
post action, params: params
expect(speech).to start_with 'Hero man has only played with seventeen summoners as Shyvana Jungle. The summoner who has helped Hero man get the seventeenth highest win rate is '
end
context 'with a role' do
before :each do
summoner_params[:role] = 'JUNGLE'
end
it 'should return the single teammate' do
post action, params: params
expect(speech).to start_with 'Hero man has only played with seventeen summoners as Shyvana Jungle. The summoner who has helped Hero man get the seventeenth highest win rate is '
end
end
end
end
context 'with multiple summoners returned' do
before :each do
summoner_params[:list_size] = 2
end
context 'with no position offset' do
context 'with complete results' do
it 'should determine the best teammates' do
post action, params: params
expect(speech).to eq 'The teammates who have helped Hero man get the highest win rate playing Shyvana Jungle are Teammate man and Other man.'
end
context 'with a role' do
before :each do
summoner_params[:role] = 'JUNGLE'
end
it 'should filter teammates by champion role' do
post action, params: params
expect(speech).to eq 'The teammates who have helped Hero man get the highest win rate playing Shyvana Jungle are Teammate man and Other man.'
end
end
end
context 'with incomplete results' do
before :each do
summoner_params[:list_size] = 100
end
it 'should return the teammates, indicating that the list is incomplete' do
post action, params: params
expect(speech).to start_with 'Hero man has only played with seventeen summoners as Shyvana Jungle. The summoners who have helped Hero man get the highest win rate are '
end
context 'with a role' do
before :each do
summoner_params[:role] = 'JUNGLE'
end
it 'should filter teammates by champion role' do
post action, params: params
expect(speech).to start_with 'Hero man has only played with seventeen summoners as Shyvana Jungle. '
end
end
end
end
context 'with a position offset' do
before :each do
summoner_params[:list_position] = 2
end
context 'with complete results' do
it 'should return the summoners at the offset' do
post action, params: params
expect(speech).to start_with 'The teammates who have helped Hero man get the second through third highest win rate playing Shyvana Jungle are Other man'
end
context 'with a role' do
before :each do
summoner_params[:role] = 'JUNGLE'
end
it 'should filter teammates by champion role' do
post action, params: params
expect(speech).to start_with 'The teammates who have helped Hero man get the second through third highest win rate playing Shyvana Jungle are '
end
end
end
context 'with incomplete results' do
before :each do
summoner_params[:list_size] = 100
end
it 'should return the summoners, indicating this is not the full list' do
post action, params: params
expect(speech).to start_with 'Hero man has only played with seventeen summoners as Shyvana Jungle. The summoners who have helped Hero man get the second through seventeenth'
end
context 'with a role' do
before :each do
summoner_params[:role] = 'JUNGLE'
end
it 'should filter teammates by champion role' do
post action, params: params
expect(speech).to start_with 'Hero man has only played with seventeen summoners as Shyvana Jungle. '
end
end
end
end
end
end
describe 'POST champion_matchups' do
let(:action) { :champion_matchups }
let(:summoner_params) do
{
name: 'Hero man',
champion: 'Shyvana',
champion2: 'Udyr',
region: 'NA1',
role: 'JUNGLE',
list_order: 'highest',
metric: '',
position_details: '',
time: ''
}
end
before :each do
@matches = create_list(:match, 2)
match_data = [
{ match: { win: true }, summoner_performance: { champion_id: 102, role: 'JUNGLE' }, opponent: { champion_id: 77 } },
{ match: { win: false }, summoner_performance: { champion_id: 102, role: 'JUNGLE' }, opponent: { champion_id: 50 } },
]
summoner = create(:summoner, name: 'Hero man')
@matches.each_with_index do |match, i|
summoner_performance = match.summoner_performances.first
opposing_team = summoner_performance.team == match.team1 ? match.team2 : match.team1
if match_data[i][:match][:win]
match.update!(winning_team: summoner_performance.team)
else
match.update!(winning_team: opposing_team)
end
summoner_performance.update!(
match_data[i][:summoner_performance].merge({ summoner_id: summoner.id })
)
opposing_team.summoner_performances.first
.update!(match_data[i][:opponent].merge({ role: match_data[i][:summoner_performance][:role] }))
end
end
context 'with a time specified' do
before :each do
summoner_params[:time] = @today
end
it 'should indicate that the teammates are from games in the time interval' do
post action, params: params
expect(speech).to eq 'Hero man has played Shyvana Jungle one time against Udyr from Wed Feb 7 at 12am to Thu Feb 8 at 12am with a 100.0% win rate.'
end
end
context 'with no own champion specified' do
before :each do
summoner_params[:champion] = ''
end
it 'should determine the matchup for the summoner against that champion in general' do
post action, params: params
expect(speech).to eq 'Hero man has played Jungle one time against Udyr with a 100.0% win rate.'
end
end
context 'with no games against that champion' do
before :each do
summoner_params[:champion2] = 'Bard'
end
it 'should indicate that the summoner has not played against that champion' do
post action, params: params
expect(speech).to eq 'I could not find any matches for Hero man playing Shyvana Jungle against Bard. It would be interesting to see though.'
end
end
context 'with no position or metric' do
it 'should indicte the win rate the summoner gets playing that matchup' do
post action, params: params
expect(speech).to eq 'Hero man has played Shyvana Jungle one time against Udyr with a 100.0% win rate.'
end
end
context 'with a position' do
before :each do
summoner_params[:position_details] = :kills
end
it 'should indicate the kills the summoner gets playing that matchup' do
post action, params: params
expect(speech).to eq 'Hero man has played Shyvana Jungle one time against Udyr and averages 2.0 kills.'
end
end
context 'with a metric' do
context 'with a KDA metric' do
before :each do
summoner_params[:metric] = :KDA
end
it 'should indicate the KDA the summoner gets playing that matchup' do
post action, params: params
expect(speech).to eq 'Hero man has played Shyvana Jungle one time against Udyr with an overall 2.0/3.0/7.0 KDA.'
end
end
context 'with a count metric' do
before :each do
summoner_params[:metric] = :count
end
it 'should indicate the count the summoner gets playing that matchup' do
post action, params: params
expect(speech).to eq 'Hero man has played Shyvana Jungle one time against Udyr.'
end
end
context 'with a winrate metric' do
before :each do
summoner_params[:metric] = :winrate
end
it 'should indicate the win rate the summoner gets playing that matchup' do
post action, params: params
expect(speech).to eq 'Hero man has played Shyvana Jungle one time against Udyr with a 100.0% win rate.'
end
end
end
end
describe 'POST champion_spells' do
let(:action) { :champion_spells }
let(:summoner_params) do
{
name: 'Hero man',
champion: 'Shyvana',
region: 'NA1',
role: 'DUO_CARRY',
list_order: 'highest',
metric: '',
position_details: '',
time: ''
}
end
before :each do
match_data = [
{ match: { win: true }, summoner_performance: { spell1_id: 3, spell2_id: 4, champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: true }, summoner_performance: { spell1_id: 3, spell2_id: 4, champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: true }, summoner_performance: { spell1_id: 3, spell2_id: 4, champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: true }, summoner_performance: { spell1_id: 3, spell2_id: 4, champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: true }, summoner_performance: { spell1_id: 3, spell2_id: 4, champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: false }, summoner_performance: { spell1_id: 4, spell2_id: 6, champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: false }, summoner_performance: { spell1_id: 4, spell2_id: 6, champion_id: 102, role: 'DUO_CARRY' } },
]
@matches = create_list(:match, match_data.length)
summoner = create(:summoner, name: 'Hero man')
@matches.each_with_index do |match, i|
summoner_performance = match.summoner_performances.first
opposing_team = summoner_performance.team == match.team1 ? match.team2 : match.team1
winning_team = match_data[i][:match][:win] ? summoner_performance.team : opposing_team
match.update!(winning_team: winning_team)
summoner_performance.update!(match_data[i][:summoner_performance].merge({ summoner_id: summoner.id }))
end
end
context 'with a time specified' do
before :each do
summoner_params[:time] = @today
end
it 'should indicate that the teammates are from games in the time interval' do
post action, params: params
expect(speech).to eq 'The spell combination used by Hero man from Wed Feb 7 at 12am to Thu Feb 8 at 12am that gives the summoner playing Shyvana Adc the highest win rate is Exhaust and Flash.'
end
end
context 'with no champion specified' do
before :each do
summoner_params[:champion] = ''
end
it 'should determine the spells for the summoner in general' do
post action, params: params
expect(speech).to eq 'The spell combination used by Hero man that gives the summoner playing Adc the highest win rate is Exhaust and Flash.'
end
end
context 'with no spell combinations' do
context 'with no position offset' do
before :each do
summoner_params[:name] = 'inactive player'
end
it 'should indicate the summoner never plays that champion' do
post action, params: params
expect(speech).to eq 'inactive player is not an active player in ranked.'
end
end
context 'with a position offset' do
before :each do
summoner_params[:list_position] = 100
end
it 'should indicate that no spell combinations were requested' do
post action, params: params
expect(speech).to eq 'Hero man only has used two spell combinations playing as Shyvana Adc this season.'
end
end
end
context 'with a single spell combination' do
context 'with no position offset' do
it 'should determine the single spell combination' do
post action, params: params
expect(speech).to eq 'The spell combination used by Hero man that gives the summoner playing Shyvana Adc the highest win rate is Exhaust and Flash.'
end
end
context 'with a position offset' do
before :each do
summoner_params[:list_position] = 2
end
it 'should determine the single spell combination at that offset' do
post action, params: params
expect(speech).to eq 'The spell combination used by Hero man that gives the summoner playing as Shyvana Adc the second highest win rate is Flash and Ghost.'
end
end
end
end
describe 'POST champion_bans' do
let(:action) { :champion_bans }
let(:summoner_params) do
{
name: 'Hero man',
champion: 'Shyvana',
region: 'NA1',
role: 'DUO_CARRY',
list_order: 'highest',
list_size: 1,
metric: '',
position_details: '',
time: ''
}
end
before :each do
match_data = [
{ match: { win: true }, ban: { champion_id: 42 }, summoner_performance: { champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: true }, ban: { champion_id: 42 }, summoner_performance: { champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: true }, ban: { champion_id: 42 }, summoner_performance: { champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: true }, ban: { champion_id: 42 }, summoner_performance: { champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: true }, ban: { champion_id: 42 }, summoner_performance: { champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: true }, ban: { champion_id: 45 }, summoner_performance: { champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: true }, ban: { champion_id: 45 }, summoner_performance: { champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: false }, ban: { champion_id: 41 }, summoner_performance: { champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: false }, ban: { champion_id: 41 }, summoner_performance: { champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: false }, ban: { champion_id: 41 }, summoner_performance: { champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: false }, ban: { champion_id: 41 }, summoner_performance: { champion_id: 102, role: 'DUO_CARRY' } },
]
@matches = create_list(:match, match_data.length)
summoner = create(:summoner, name: 'Hero man')
@matches.each_with_index do |match, i|
summoner_performance = match.summoner_performances.first
opposing_team = summoner_performance.team == match.team1 ? match.team2 : match.team1
winning_team = match_data[i][:match][:win] ? summoner_performance.team : opposing_team
match.update!(winning_team: winning_team)
summoner_performance.update!(match_data[i][:summoner_performance].merge({ summoner_id: summoner.id }))
summoner_performance.ban.update!(match_data[i][:ban])
end
end
context 'with a time specified' do
before :each do
summoner_params[:time] = @today
end
it 'should indicate that the teammates are from games in the time interval' do
post action, params: params
expect(speech).to eq 'The ban by Hero man playing Shyvana Adc that gives the summoner the highest win rate from Wed Feb 7 at 12am to Thu Feb 8 at 12am is Corki.'
end
end
context 'with no champion specified' do
before :each do
summoner_params[:champion] = ''
end
it 'should determine the best ban for the summoner in the given role for any champion' do
post action, params: params
expect(speech).to eq 'The ban by Hero man Adc that gives the summoner the highest win rate is Corki.'
end
context 'with no role specified' do
before :each do
summoner_params[:role] = ''
end
context 'with a single role played' do
it 'should determine the best ban for the summoner in their only played role' do
post action, params: params
expect(speech).to eq 'The ban by Hero man Adc that gives the summoner the highest win rate is Corki.'
end
end
context 'with multiple roles played' do
before :each do
@matches.first.summoner_performances.first.update(role: 'DUO_SUPPORT')
end
it 'should determine the best ban for the summoner regardless of role' do
post action, params: params
expect(speech).to eq 'The ban by Hero man across Adc and Support that gives the summoner the highest win rate is Corki.'
end
end
end
end
context 'with no champions returned' do
context 'with no position offset' do
before :each do
summoner_params[:name] = 'inactive player'
end
it 'should indicate the summoner has not played any games as that champion this season' do
post action, params: params
expect(speech).to eq 'inactive player is not an active player in ranked.'
end
end
context 'with a position offset' do
before :each do
summoner_params[:list_position] = 100
end
context 'with complete results' do
before :each do
summoner_params[:list_size] = 0
end
it 'should indicate that they did not ask for any bans' do
post action, params: params
expect(speech).to eq 'No bans were requested.'
end
end
context 'with incomplete results' do
it 'should indicate that the summoner has not banned enough champions' do
post action, params: params
expect(speech).to eq 'Hero man has only banned three champions playing as Shyvana Adc.'
end
end
end
end
context 'with a single champion returned' do
context 'with no position offset' do
context 'with complete results' do
it 'should specify the a ban' do
post action, params: params
expect(speech).to eq 'The ban by Hero man playing Shyvana Adc that gives the summoner the highest win rate is Corki.'
end
end
context 'with incomplete results' do
before :each do
summoner_params[:name] = 'inactive player'
end
it 'should indicate that the summoner has not played that champion this season' do
post action, params: params
expect(speech).to eq 'inactive player is not an active player in ranked.'
end
end
end
context 'with a position offset' do
before :each do
summoner_params[:list_position] = 2
end
context 'with complete results' do
it 'should return the offset ban' do
post action, params: params
expect(speech).to eq 'The ban by Hero man that gives the summoner playing Shyvana Adc the second highest win rate is Veigar.'
end
end
context 'with incomplete results' do
before :each do
summoner_params[:list_position] = 100
end
it 'should indicate the summoner has not banned enough champions' do
post action, params: params
expect(speech).to eq 'Hero man has only banned three champions playing as Shyvana Adc.'
end
end
end
end
context 'with multiple champions returned' do
before :each do
summoner_params[:list_size] = 2
end
context 'without a position offset' do
context 'with complete results' do
it 'should specify the bans' do
post action, params: params
expect(speech).to eq 'The bans by Hero man playing Shyvana Adc that give the summoner the highest win rate are Corki and Veigar.'
end
end
context 'with incomplete results' do
before :each do
summoner_params[:list_size] = 5
end
it 'should return the bans indicating it is incomplete' do
post action, params: params
expect(speech).to eq 'Hero man has only played against three different champions as Shyvana Adc. The bans that give the summoner the highest win rate are Corki, Veigar, and Gangplank.'
end
end
end
context 'with a position offset' do
before :each do
summoner_params[:list_position] = 2
end
context 'with complete results' do
it 'should specify all the bans' do
post action, params: params
expect(speech).to eq 'The second through third bans that give Hero man playing Shyvana Adc the highest win rate are Veigar and Gangplank.'
end
end
context 'with incomplete results' do
before :each do
summoner_params[:list_size] = 5
end
it 'should return the bans indicating that it is incomplete' do
post action, params: params
expect(speech).to eq 'Hero man has only played against three different champions as Shyvana Adc. The second through third bans that give the highest win rate are Veigar and Gangplank.'
end
end
end
end
end
describe 'POST champion_build' do
let(:action) { :champion_build }
let(:summoner_params) do
{
name: 'Hero man',
champion: 'Shyvana',
region: 'NA1',
role: 'DUO_CARRY',
list_order: 'highest',
list_size: 2,
metric: '',
position_details: '',
time: ''
}
end
before :each do
@complete_build = [3089, 3087, 3085, 3083, 2303, 3512]
@complete_build2 = [3089, 3089, 3085, 3083, 2303, 3512]
@incomplete_build = [3089, 3086, 3085, 3083, 2303, 3512]
@partial_build = [3083, 2303, 3512]
match_data = [
{ match: { win: true }, build: @complete_build2, summoner_performance: { champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: true }, build: @complete_build2, summoner_performance: { champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: true }, build: @complete_build, summoner_performance: { champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: true }, build: @complete_build, summoner_performance: { champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: true }, build: @complete_build.reverse, summoner_performance: { champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: false }, build: @incomplete_build, summoner_performance: { champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: false }, build: @incomplete_build, summoner_performance: { champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: true }, build: @partial_build, summoner_performance: { champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: true }, build: @partial_build, summoner_performance: { champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: true }, build: @partial_build, summoner_performance: { champion_id: 102, role: 'DUO_CARRY' } },
{ match: { win: true }, build: @partial_build, summoner_performance: { champion_id: 102, role: 'DUO_CARRY' } },
]
@matches = create_list(:match, match_data.length)
summoner = create(:summoner, name: 'Hero man')
@matches.each_with_index do |match, i|
summoner_performance = match.summoner_performances.first
opposing_team = summoner_performance.team == match.team1 ? match.team2 : match.team1
winning_team = match_data[i][:match][:win] ? summoner_performance.team : opposing_team
match.update!(winning_team: winning_team)
summoner_performance.update!(match_data[i][:summoner_performance].merge({ summoner_id: summoner.id }))
match_data[i][:build].each_with_index do |item_id, index|
summoner_performance.update_attribute("item#{index}_id", item_id)
end
end
end
context 'with a time specified' do
before :each do
summoner_params[:time] = @today
end
it 'should indicate that the teammates are from games in the time interval' do
post action, params: params
expect(speech).to eq "Hero man has played Shyvana Adc eleven times from Wed Feb 7 at 12am to Thu Feb 8 at 12am and the summoner's highest win rate build is Rabadon's Deathcap, Statikk Shiv, Runaan's Hurricane, Warmog$
s Armor, Eye of the Equinox, and Zz'Rot Portal."
end
end
context 'with no role specified' do
before :each do
summoner_params[:role] = ''
end
context 'with a single role played' do
it 'should determine builds for the single role' do
post action, params: params
expect(speech).to eq "Hero man has played Shyvana Adc eleven times and the summoner's highest win rate build is Rabadon's Deathcap, Statikk Shiv, Runaan's Hurricane, Warmog's Armor, Eye of the Equinox, and Zz'Rot Portal."
end
end
context 'with multiple roles played' do
before :each do
@matches.first.summoner_performances.first.update_attribute(:role, 'JUNGLE')
end
it 'should indicate that the summoner has played the champion in multiple roles' do
post action, params: params
expect(speech).to eq "Hero man has played Shyvana across Adc and Jungle eleven times and the summoner's highest win rate build is Rabadon's Deathcap, Statikk Shiv, Runaan's Hurricane, Warmog's Armor, Eye of the Equinox, and Zz'Rot Portal."
end
end
end
context 'when the champion has not been played' do
before :each do
@matches.each do |match|
match.summoner_performances.first.update_attribute(:champion_id, 101)
end
end
it 'should indicate that the summoner has not played the champion' do
post action, params: params
expect(speech).to eq "Hero man has not played any games as Shyvana Adc."
end
end
context 'without a metric or position details specified' do
it 'should use winrate as the default metric' do
post action, params: params
expect(speech).to eq "Hero man has played Shyvana Adc eleven times and the summoner's highest win rate build is Rabadon's Deathcap, Statikk Shiv, Runaan's Hurricane, Warmog's Armor, Eye of the Equinox, and Zz'Rot Portal."
end
end
context 'with a position details specified' do
before :each do
summoner_params[:position_details] = :penta_kills
@matches.first.summoner_performances.first.update!(penta_kills: 100000000)
end
it 'should use the position details to determine the build' do
post action, params: params
expect(speech).to eq "Hero man has played Shyvana Adc eleven times and the summoner's highest penta kills build is two Rabadon's Deathcaps, Runaan's Hurricane, Warmog's Armor, Eye of the Equinox, and Zz'Rot Portal."
end
end
context 'with a reverse list order' do
before :each do
summoner_params[:list_order] = 'lowest'
end
it 'should return the worst build' do
post action, params: params
expect(speech).to eq "Hero man has played Shyvana Adc eleven times and the summoner's lowest win rate build is two Rabadon's Deathcaps, Runaan's Hurricane, Warmog's Armor, Eye of the Equinox, and Zz'Rot Portal."
end
end
context 'with a winrate metric specified' do
before :each do
summoner_params[:metric] = :winrate
end
it 'should use winrate as the build metric' do
post action, params: params
expect(speech).to eq "Hero man has played Shyvana Adc eleven times and the summoner's highest win rate build is Rabadon's Deathcap, Statikk Shiv, Runaan's Hurricane, Warmog's Armor, Eye of the Equinox, and Zz'Rot Portal."
end
end
context 'with a KDA metric specified' do
before :each do
summoner_params[:metric] = :KDA
@matches.first.summoner_performances.first.update!(kills: 100000000)
end
context 'with all valid KDA performances' do
it 'should use KDA as the build metric' do
post action, params: params
expect(speech).to eq "Hero man has played Shyvana Adc eleven times and the summoner's highest KDA build is two Rabadon's Deathcaps, Runaan's Hurricane, Warmog's Armor, Eye of the Equinox, and Zz'Rot Portal."
end
end
context 'with infinite KDA performances' do
before :each do
@matches.first.summoner_performances.first.update!(deaths: 0, kills: 10, assists: 0)
end
it 'should filter out zero performances' do
post action, params: params
expect(speech).to eq "Hero man has played Shyvana Adc eleven times and the summoner's highest KDA build is Rabadon's Deathcap, Statikk Shiv, Runaan's Hurricane, Warmog's Armor, Eye of the Equinox, and Zz'Rot Portal."
end
end
context 'with NAN KDA performances' do
before :each do
@matches.first.summoner_performances.first.update!(deaths: 0, kills: 0, assists: 0)
end
it 'should filter out zero performances' do
post action, params: params
expect(speech).to eq "Hero man has played Shyvana Adc eleven times and the summoner's highest KDA build is Rabadon's Deathcap, Statikk Shiv, Runaan's Hurricane, Warmog's Armor, Eye of the Equinox, and Zz'Rot Portal."
end
end
end
context 'with a count metric specified' do
before :each do
summoner_params[:metric] = :count
end
it 'should use the frequency of the build as the metric' do
post action, params: params
expect(speech).to eq "Hero man has played Shyvana Adc eleven times and the summoner's highest games played build is Rabadon's Deathcap, Statikk Shiv, Runaan's Hurricane, Warmog's Armor, Eye of the Equinox, and Zz'Rot Portal."
end
end
context 'with only partial builds' do
before :each do
@matches.each do |match|
match.summoner_performances.first.update_attribute(:item0_id, nil)
end
end
it 'should indicate the summoner has never completed a build' do
post action, params: params
expect(speech).to eq 'Hero man does not have any complete builds playing Shyvana Adc this season.'
end
end
context 'with builds with the same winrate' do
before :each do
build = @complete_build2
summoner_performance = @matches[2].summoner_performances.first
build.each_with_index do |item_id, index|
summoner_performance.update_attribute("item#{index}_id", item_id)
end
end
it 'should use the build that is done most frequently' do
post action, params: params
expect(speech).to eq "Hero man has played Shyvana Adc eleven times and the summoner's highest win rate build is two Rabadon's Deathcaps, Runaan's Hurricane, Warmog's Armor, Eye of the Equinox, and Zz'Rot Portal."
end
end
context 'with multiple orders of the same build' do
before :each do
build = @complete_build.reverse
summoner_performance = @matches[2].summoner_performances.first
build.each_with_index do |item_id, index|
summoner_performance.update_attribute("item#{index}_id", item_id)
end
end
it 'should use the order that appears most frequently' do
post action, params: params
expect(speech).to eq "Hero man has played Shyvana Adc eleven times and the summoner's highest win rate build is Zz'Rot Portal, Eye of the Equinox, Warmog's Armor, Runaan's Hurricane, Statikk Shiv, and Rabadon's Deathcap."
end
end
end
describe 'POST performance_summary' do
let(:action) { :performance_summary }
let(:external_response) do
JSON.parse(File.read('external_response.json'))
.with_indifferent_access[:summoners][action]
end
let(:summoner_params) do
{ name: 'Wingilote', region: 'NA1', queue: 'RANKED_SOLO_5x5' }
end
before :each do
summoner = create(:summoner, name: 'Wingilote')
allow(RiotApi::RiotApi).to receive(:fetch_response).and_return(
external_response
)
Cache.set_summoner_rank(summoner.summoner_id, nil)
end
context 'with no queue data' do
before :each do
allow_any_instance_of(Summoner).to receive(:queue).and_return(RankedQueue.new(nil))
end
it 'should inform the user their queue data could not be found' do
post action, params: params