SHOW:
|
|
- or go back to the newest paste.
1 | package end2end.broker.rankings | |
2 | ||
3 | import org.joda.time.DateTime | |
4 | import helper.UserStepHelpers | |
5 | import helper.base.BaseAcceptanceSpec | |
6 | import core.models.RankingUser | |
7 | import core.models.User | |
8 | ||
9 | import com.timgroup.test.narrative._ | |
10 | import RespondTo.respond_to | |
11 | import RankingRequestBuilder.the_ranking_request | |
12 | import RankingResultsRequestBuilder.the_ranking_results_request | |
13 | import RankingIdeasRequestBuilder.the_ranking_ideas_request | |
14 | import IdeaHistoryRequestBuilder.the_idea_history_request | |
15 | import ViewingUser.viewing | |
16 | import ViewTheRankingPage.view_the_rankings_page | |
17 | import TheRankingNames.the_ranking_names | |
18 | import ChooseTheRankingNamed.choose_the_ranking_named | |
19 | import ChooseTheBrokerWithId.choose_the_broker_with_id | |
20 | import ChooseTheIdeaWithId.choose_the_idea_with_id | |
21 | import TheSelectedRankings.the_selected_rankings | |
22 | import TheRankingsBrokerIds.the_rankings_broker_ids | |
23 | import TheSelectedBrokerIdeaIds.the_selected_broker_idea_ids | |
24 | import TheSelectedIdeaHistoryId.the_selected_idea_history_id | |
25 | import RankingsXmlBuilder.a_ranking_xml | |
26 | import ARankingBuilder.a_ranking_named | |
27 | import ARankingBuilder.a_ranking | |
28 | import RankingResultsXmlBuilder.a_ranking_results_xml | |
29 | import ARankingResultBuilder.a_ranking_result | |
30 | import IdeasXmlBuilder.an_ideas_xml | |
31 | import AnIdeaBuilder.an_idea_with_id | |
32 | import AnIdeaBuilder.an_idea | |
33 | import AnIdeaHistoryBuilder.an_idea_history_with_id | |
34 | ||
35 | ||
36 | class RankingsSpec extends BaseAcceptanceSpec with UserStepHelpers { | |
37 | ||
38 | val equities_service = new StubEquitiesServiceActor | |
39 | ||
40 | describe("Can see the users' rankings") { | |
41 | ||
42 | val firstDate = new DateTime(2013, 3, 5, 12, 55) | |
43 | val secondDate = new DateTime(2013, 3, 5, 17, 55) | |
44 | ||
45 | def randomUser() = usersRepo.insert(randomUsername, RankingUser).get | |
46 | ||
47 | ||
48 | it("First rankings have the expected brokers") { | |
49 | val user = randomUser() | |
50 | val viewer = viewing(user) | |
51 | ||
52 | Given.the(equities_service) | |
53 | .was_able_to(respond_to(the_ranking_request.for_user(user)) | |
54 | .with_response(a_ranking_xml.containing(a_ranking_named("MTD").with_id("mtd")) | |
55 | .containing(a_ranking_named("YTD").with_id("ytd")).get())) | |
56 | ||
57 | .was_able_to(respond_to(the_ranking_results_request.for_user(user) | |
58 | .and_ranking("mtd")) | |
59 | .with_response(a_ranking_results_xml.containing(a_ranking_result.for_broker_id("broker-1") | |
60 | .with_rank(13)) | |
61 | .containing(a_ranking_result.for_broker_id("broker-2") | |
62 | .with_rank(25)).get())) | |
63 | ||
64 | When.the(viewer).attempts_to(view_the_rankings_page) | |
65 | ||
66 | Then.the(viewer).expects_that(the_ranking_names)(_ should equal(List("MTD", "YTD"))) | |
67 | .and_that(the_rankings_broker_ids)(_ should equal(List("broker-1", "broker-2"))) | |
68 | } | |
69 | ||
70 | it("Selected Rankings' Brokers are Present") { | |
71 | val user = randomUser() | |
72 | val viewer = viewing(user) | |
73 | ||
74 | Given.the(equities_service) | |
75 | .was_able_to(respond_to(the_ranking_request.for_user(user)) | |
76 | .with_response(a_ranking_xml.containing(a_ranking_named("MTD").with_id("mtd")) | |
77 | .containing(a_ranking_named("YTD").with_id("ytd")).get())) | |
78 | ||
79 | .was_able_to(respond_to(the_ranking_results_request.for_user(user) | |
80 | .and_ranking("mtd")) | |
81 | .with_response(a_ranking_results_xml.get())) | |
82 | .was_able_to(respond_to(the_ranking_results_request.for_user(user) | |
83 | .and_ranking("ytd")) | |
84 | .with_response(a_ranking_results_xml.containing(a_ranking_result.for_broker_id("broker-3") | |
85 | .with_rank(5)) | |
86 | .containing(a_ranking_result.for_broker_id("broker-4") | |
87 | .with_rank(11)).get())) | |
88 | ||
89 | When.the(viewer).attempts_to(view_the_rankings_page) | |
90 | .and_to(choose_the_ranking_named("YTD")) | |
91 | ||
92 | Then.the(viewer).expects_that(the_selected_rankings)(_ should be(List("YTD"))) | |
93 | .and_that(the_rankings_broker_ids)(_ should equal(List("broker-3", "broker-4"))) | |
94 | } | |
95 | ||
96 | it("Second Broker's Ideas are Present after selecting the Second Broker") { | |
97 | val user = randomUser() | |
98 | val viewer = viewing(user) | |
99 | ||
100 | Given.the(equities_service) | |
101 | .was_able_to(respond_to(the_ranking_request.for_user(user)) | |
102 | .with_response(a_ranking_xml.containing(a_ranking(name = "MTD", id = "mtd")).get())) | |
103 | ||
104 | .was_able_to(respond_to(the_ranking_results_request.for_user(user) | |
105 | .and_ranking("mtd")) | |
106 | .with_response(a_ranking_results_xml.containing(a_ranking_result(brokerId = "broker-1", | |
107 | rank = 13)) | |
108 | .containing(a_ranking_result(brokerId = "broker-2", | |
109 | rank = 25)).get())) | |
110 | ||
111 | .was_able_to(respond_to(the_ranking_ideas_request.for_user(user) | |
112 | .and_criteria("mtd") | |
113 | .and_contributor("broker-2")) | |
114 | .with_response(an_ideas_xml.containing(an_idea(id = "idea-c", lastAction = secondDate)) | |
115 | - | .containing(an_idea(id = "idea-d", lastAction = firstDate)).get())) |
115 | + | .containing(an_idea(id = "idea-d", lastAction = firstDate)) |
116 | .get())) | |
117 | ||
118 | When.the(viewer).attempts_to(view_the_rankings_page) | |
119 | .and_to(choose_the_broker_with_id("broker-2")) | |
120 | ||
121 | Then.the(viewer).expects_that(the_selected_broker_idea_ids)(_ should be(List("idea-c", "idea-d"))) | |
122 | ||
123 | } | |
124 | ||
125 | it("Idea details are present when selecting an Idea") { | |
126 | val user = randomUser() | |
127 | val ideaHistory = an_idea_history_with_id("idea-c-history").get() | |
128 | val viewer = viewing(user) | |
129 | ||
130 | Given.the(equities_service) | |
131 | .was_able_to(respond_to(the_ranking_request.for_user(user)) | |
132 | .with_response(a_ranking_xml.containing(a_ranking_named("MTD").with_id("mtd")).get())) | |
133 | ||
134 | .was_able_to(respond_to(the_ranking_results_request.for_user(user) | |
135 | .and_ranking("mtd")) | |
136 | .with_response(a_ranking_results_xml.containing(a_ranking_result.for_broker_id("broker-1") | |
137 | .with_rank(13)) | |
138 | .containing(a_ranking_result.for_broker_id("broker-2") | |
139 | .with_rank(25)).get())) | |
140 | ||
141 | .was_able_to(respond_to(the_ranking_ideas_request.for_user(user) | |
142 | .and_criteria("mtd") | |
143 | - | .with_response(an_ideas_xml.containing(an_idea_with_id("idea-c").with_last_action_on(secondDate)) |
143 | + | |
144 | - | .containing(an_idea_with_id("idea-d").with_last_action_on(firstDate)).get())) |
144 | + | .with_response(an_ideas_xml.containing(an_idea_with_id("idea-c") |
145 | .with_last_action_on(secondDate)) | |
146 | .containing(an_idea_with_id("idea-d") | |
147 | .with_last_action_on(firstDate)).get())) | |
148 | ||
149 | .was_able_to(respond_to(the_idea_history_request.for_user(user) | |
150 | .and_idea("idea-c")) | |
151 | .with_response(ideaHistory)) | |
152 | ||
153 | When.the(viewer).attempts_to(view_the_rankings_page) | |
154 | .and_to(choose_the_broker_with_id("broker-2")) | |
155 | .and_to(choose_the_idea_with_id("idea-c")) | |
156 | - | }}} |
156 | + | |
157 | Then.the(viewer).expects_that(the_selected_idea_history_id)(_ should be("idea-c-history")) | |
158 | } | |
159 | } | |
160 | } |