PageRenderTime 238ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/ucengine/src/tests/event_tests.erl

http://github.com/AF83/ucengine
Erlang | 886 lines | 795 code | 72 blank | 19 comment | 0 complexity | 01cb0b31a4b83d15ca34ae43c3858697 MD5 | raw file
  1. %%
  2. %% U.C.Engine - Unified Collaboration Engine
  3. %% Copyright (C) 2011 af83
  4. %%
  5. %% This program is free software: you can redistribute it and/or modify
  6. %% it under the terms of the GNU Affero General Public License as published by
  7. %% the Free Software Foundation, either version 3 of the License, or
  8. %% (at your option) any later version.
  9. %%
  10. %% This program is distributed in the hope that it will be useful,
  11. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. %% GNU Affero General Public License for more details.
  14. %%
  15. %% You should have received a copy of the GNU Affero General Public License
  16. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. %%
  18. -module(event_tests).
  19. -include("uce.hrl").
  20. -include_lib("eunit/include/eunit.hrl").
  21. -export([send_long_polling_event/2, send_long_polling_event/3]).
  22. setup_events(Domain) ->
  23. {ok, Participant} = uce_user:get_by_name(Domain, "participant.user@af83.com"),
  24. {ok, User2} = uce_user:get_by_name(Domain, "user_2"),
  25. {ok, User3} = uce_user:get_by_name(Domain, "user_3"),
  26. uce_event:add(Domain,
  27. #uce_event{ id=none,
  28. type="test_event_1",
  29. location="testmeeting",
  30. from=Participant#uce_user.id}),
  31. timer:sleep(10),
  32. uce_event:add(Domain,
  33. #uce_event{ id=none,
  34. type="test_event_2",
  35. location="testmeeting",
  36. from=User2#uce_user.id}),
  37. timer:sleep(10),
  38. uce_event:add(Domain,
  39. #uce_event{ id=none,
  40. type="test_event_3",
  41. location="testmeeting",
  42. from=User3#uce_user.id,
  43. metadata=json_helpers:to_struct([{"description", "test"}])}),
  44. ok.
  45. event_test_() ->
  46. { setup
  47. , fun() ->
  48. [Domain, BaseUrl, Testers] = fixtures:setup(),
  49. setup_events(Domain),
  50. [Domain, BaseUrl, Testers]
  51. end
  52. , fun fixtures:teardown/1
  53. , fun([_, BaseUrl, [Root, Participant, Ugly|_]]) ->
  54. [?_test(test_push(BaseUrl, Root)),
  55. ?_test(test_push_big(BaseUrl, Root)),
  56. ?_test(test_push_internal_event(BaseUrl, Root)),
  57. ?_test(test_push_without_meeting(BaseUrl, Root)),
  58. ?_test(test_push_with_parent(BaseUrl, Root)),
  59. ?_test(test_push_to_me(BaseUrl, Root)),
  60. ?_test(test_push_to_unauthorized(BaseUrl, Root, Participant, Ugly)),
  61. ?_test(test_push_to_other(BaseUrl, Root, Participant)),
  62. ?_test(test_push_json(BaseUrl, Root)),
  63. ?_test(test_push_missing_type(BaseUrl, Root)),
  64. ?_test(test_push_not_found_meeting(BaseUrl, Root)),
  65. ?_test(test_push_not_found_parent(BaseUrl, Root)),
  66. ?_test(test_push_not_found_to(BaseUrl, Root)),
  67. ?_test(test_get(BaseUrl, Root)),
  68. ?_test(test_get_without_meeting(BaseUrl, Root)),
  69. ?_test(test_get_with_keywords(BaseUrl, Root)),
  70. ?_test(test_get_with_keywords_without_meeting(BaseUrl, Root)),
  71. ?_test(test_get_with_keywords_with_from(BaseUrl, Root, Participant)),
  72. ?_test(test_get_with_keywords_in_metadata(BaseUrl, Root)),
  73. ?_test(test_get_with_keywords_and_timestart_and_timeend(BaseUrl, Root)),
  74. ?_test(test_get_with_type(BaseUrl, Root)),
  75. ?_test(test_get_with_types(BaseUrl, Root)),
  76. ?_test(test_get_with_type_and_timestart(BaseUrl, Root)),
  77. ?_test(test_get_with_type_and_timestart_and_timeend(BaseUrl, Root)),
  78. ?_test(test_get_with_type_and_timeend(BaseUrl, Root)),
  79. ?_test(test_last(BaseUrl, Root)),
  80. ?_test(test_long_polling(BaseUrl, Root)),
  81. ?_test(test_long_polling_with_types(BaseUrl, Root)),
  82. ?_test(test_long_polling_with_to(BaseUrl, Root, Participant)),
  83. ?_test(test_long_polling_with_to_and_participant(BaseUrl, Root, Participant))
  84. ]
  85. end}.
  86. event_timeout_test_() ->
  87. { setup
  88. , fun() ->
  89. [Domain, BaseUrl, Testers] = fixtures:setup(),
  90. setup_events(Domain),
  91. % Set the timeout to a low value to avoid waiting too long.
  92. PreviousTimeout = config:get(connection_timeout),
  93. config:set(connection_timeout, 10),
  94. [Domain, BaseUrl, Testers, PreviousTimeout]
  95. end
  96. , fun ([Domain, BaseUrl, Testers, PreviousTimeout]) ->
  97. %% Restore the previous long polling timeout
  98. config:set(connection_timeout, PreviousTimeout),
  99. fixtures:teardown([Domain, BaseUrl, Testers])
  100. end
  101. , fun([Domain, BaseUrl, [Root, Participant, Ugly|_], _]) ->
  102. [
  103. {timeout, 40, ?_test(test_long_polling_with_from(BaseUrl, Root))},
  104. {timeout, 40, ?_test(test_long_polling_with_other_from(BaseUrl, Root))},
  105. {timeout, 40, ?_test(test_long_polling_with_parent(Domain, BaseUrl, Root))},
  106. {timeout, 40, ?_test(test_long_polling_with_other_parent(BaseUrl, Root))},
  107. {timeout, 40, ?_test(test_long_polling_with_search(BaseUrl, Root))},
  108. {timeout, 40, ?_test(test_long_polling_with_other_search(BaseUrl, Root))},
  109. {timeout, 40, ?_test(test_long_polling_with_to_and_other_participant(BaseUrl, Root, Participant, Ugly))}
  110. ]
  111. end}.
  112. auth_params({Uid, Sid}) ->
  113. [{"uid", Uid},
  114. {"sid", Sid}].
  115. post_event(BaseUrl, Meeting, AuthParams, Params) ->
  116. {struct, [{"result", Id}]} = tests_utils:post(BaseUrl, "/event/"++ Meeting, Params ++ auth_params(AuthParams)),
  117. Id.
  118. test_push(BaseUrl, {RootUid, _RootSid} = AuthParams) ->
  119. Params = [{"type", "test_push_1"},
  120. {"metadata[description]", "pushed_event"}],
  121. Id = post_event(BaseUrl, "testmeeting", AuthParams, Params),
  122. ?assertMatch({struct, [{"result",
  123. {struct, [{"type", "test_push_1"},
  124. {"domain", _},
  125. {"datetime", _},
  126. {"id", Id},
  127. {"location", "testmeeting"},
  128. {"from", RootUid},
  129. {"metadata", {struct, [{"description", "pushed_event"}]}}]}}]},
  130. tests_utils:get(BaseUrl, "/event/testmeeting/" ++ Id, auth_params(AuthParams))).
  131. test_push_big(BaseUrl, {RootUid, _RootSid} = AuthParams) ->
  132. Text = string:copies("pushed_event", 5000),
  133. Params = [{"type", "test_push_1"},
  134. {"metadata[description]", Text}],
  135. Id = post_event(BaseUrl, "testmeeting", AuthParams, Params),
  136. ?assertMatch({struct, [{"result",
  137. {struct, [{"type", "test_push_1"},
  138. {"domain", _},
  139. {"datetime", _},
  140. {"id", Id},
  141. {"location", "testmeeting"},
  142. {"from", RootUid},
  143. {"metadata", {struct, [{"description", Text}]}}]}}]},
  144. tests_utils:get(BaseUrl, "/event/testmeeting/" ++ Id, auth_params(AuthParams))).
  145. test_push_internal_event(BaseUrl, AuthParams) ->
  146. Params = [{"type", "internal.roster.add"},
  147. {"metadata[description]", "pushed_event"}] ++ auth_params(AuthParams),
  148. {struct, [{"error", "unauthorized"}]} = tests_utils:post(BaseUrl, "/event/testmeeting", Params).
  149. test_push_without_meeting(BaseUrl, {RootUid, _RootSid} = AuthParams) ->
  150. Params = [{"type", "test_push_1"},
  151. {"metadata[description]", "pushed_event"}],
  152. Id = post_event(BaseUrl, "", AuthParams, Params),
  153. {struct, [{"result",
  154. {struct, [{"type", "test_push_1"},
  155. {"domain", _},
  156. {"datetime", _},
  157. {"id", Id},
  158. {"from", RootUid},
  159. {"metadata", {struct, [{"description", "pushed_event"}]}}]}}]} =
  160. tests_utils:get(BaseUrl, "/event/all/" ++ Id, auth_params(AuthParams)).
  161. test_push_with_parent(BaseUrl, {RootUid, _RootSid} = AuthParams) ->
  162. Params = [{"type", "test_push_1"},
  163. {"metadata[description]", "pushed_event"}],
  164. ParentId = post_event(BaseUrl, "testmeeting", AuthParams, Params),
  165. ParamsChild = [{"type", "test_push_1"},
  166. {"parent", ParentId},
  167. {"metadata[description]", "pushed_event"}],
  168. ChildId = post_event(BaseUrl,"testmeeting", AuthParams, ParamsChild),
  169. {struct, [{"result",
  170. {struct, [{"type", "test_push_1"},
  171. {"domain", _},
  172. {"datetime", _},
  173. {"id", ChildId},
  174. {"location", "testmeeting"},
  175. {"from", RootUid},
  176. {"parent", ParentId},
  177. {"metadata", {struct, [{"description", "pushed_event"}]}}]}}]} =
  178. tests_utils:get(BaseUrl, "/event/testmeeting/" ++ ChildId, auth_params(AuthParams)).
  179. test_push_to_me(BaseUrl, {RootUid, _RootSid} = AuthParams) ->
  180. Params = [{"type", "test_push_1"},
  181. {"to", RootUid},
  182. {"metadata[description]", "pushed_event"}],
  183. Id = post_event(BaseUrl, "testmeeting", AuthParams, Params),
  184. {struct, [{"result",
  185. {struct, [{"type", "test_push_1"},
  186. {"domain", _},
  187. {"datetime", _},
  188. {"id", Id},
  189. {"location", "testmeeting"},
  190. {"to", RootUid},
  191. {"from", RootUid},
  192. {"metadata", {struct, [{"description", "pushed_event"}]}}]}}]} =
  193. tests_utils:get(BaseUrl, "/event/testmeeting/" ++ Id, auth_params(AuthParams)).
  194. test_push_to_unauthorized(BaseUrl,
  195. RootAuthParams,
  196. ParticipantParams,
  197. {UglyUid, _UglySid}) ->
  198. Params = auth_params(ParticipantParams) ++ [{"type", "test_push_1"},
  199. {"to", UglyUid},
  200. {"metadata[description]", "pushed_event"}],
  201. {struct, [{"result", _Id}]} =
  202. tests_utils:post(BaseUrl, "/event/testmeeting", Params),
  203. ParamsRoot = auth_params(RootAuthParams) ++ [{"type", "test_push_to_other"}],
  204. {struct, [{"result", {array, []}}]} =
  205. tests_utils:get(BaseUrl, "/event/testmeeting/", ParamsRoot).
  206. test_push_to_other(BaseUrl, {RootUid, RootSid}, {ParticipantUid, ParticipantSid}) ->
  207. Params = [{"uid", RootUid},
  208. {"sid", RootSid},
  209. {"type", "test_push_to_other"},
  210. {"to", ParticipantUid},
  211. {"metadata[description]", "pushed_event"}],
  212. {struct, [{"result", Id}]} =
  213. tests_utils:post(BaseUrl, "/event/testmeeting", Params),
  214. {struct, [{"error", "unauthorized"}]} =
  215. tests_utils:get(BaseUrl, "/event/testmeeting/" ++ Id, Params),
  216. ParamsParticipant = [{"uid", ParticipantUid},
  217. {"sid", ParticipantSid},
  218. {"type", "test_push_to_other"}],
  219. {struct, [{"result", {array, [
  220. {struct, [{"type", "test_push_to_other"},
  221. {"domain", _},
  222. {"datetime", _},
  223. {"id", Id},
  224. {"location", "testmeeting"},
  225. {"to", "participant.user@af83.com"},
  226. {"from", RootUid},
  227. {"metadata", {struct, [{"description", "pushed_event"}]}}]}]}}]} =
  228. tests_utils:get(BaseUrl, "/event/testmeeting/", ParamsParticipant),
  229. ParamsRootGet = [{"uid", RootUid},
  230. {"sid", RootSid},
  231. {"type", "test_push_to_other"}],
  232. {struct, [{"result", {array, [
  233. {struct, [{"type", "test_push_to_other"},
  234. {"domain", _},
  235. {"datetime", _},
  236. {"id", Id},
  237. {"location", "testmeeting"},
  238. {"to", "participant.user@af83.com"},
  239. {"from", RootUid},
  240. {"metadata", {struct, [{"description", "pushed_event"}]}}]}]}}]} =
  241. tests_utils:get(BaseUrl, "/event/testmeeting/", ParamsRootGet).
  242. test_push_json(BaseUrl, AuthParams) ->
  243. RequestBody = {struct, [{"type", "test_json"},
  244. {"metadata", {struct, [{"complex", {array, [10, {struct, [{"name", "plip"},
  245. {"hop", null},
  246. {"hop2", true},
  247. {"hop3", false}]}]}}]}}]
  248. ++ auth_params(AuthParams)},
  249. {ok, "201", _, Body} =
  250. tests_utils:post_raw(BaseUrl, "/event/testmeeting", [], "application/json", mochijson:encode(RequestBody)),
  251. {struct, [{"result", Id}]} = mochijson:decode(Body),
  252. {struct, [{"result",
  253. {struct, [{"type", "test_json"},
  254. {"domain", _},
  255. {"datetime", _},
  256. {"id", Id},
  257. {"location", "testmeeting"},
  258. {"from", _},
  259. {"metadata", {struct, [{"complex", {array, [10, {struct, [{"name", "plip"},
  260. {"hop", null},
  261. {"hop2", true},
  262. {"hop3", false}
  263. ]}]}}]}}]}}]} =
  264. tests_utils:get(BaseUrl, "/event/testmeeting/" ++ Id, auth_params(AuthParams)).
  265. test_push_missing_type(BaseUrl, AuthParams) ->
  266. Params = auth_params(AuthParams) ++ [{"metadata[description]", "pushed_event"}],
  267. {struct, [{"error", "missing_parameters"}, {"infos", _}]} =
  268. tests_utils:post(BaseUrl, "/event/testmeeting", Params).
  269. test_push_not_found_meeting(BaseUrl, AuthParams) ->
  270. Params = auth_params(AuthParams) ++ [{"type", "test_push_1"},
  271. {"metadata[description]", "pushed_event"}],
  272. {struct, [{"error", "not_found"}]} =
  273. tests_utils:post(BaseUrl, "/event/unexistentmeeting", Params).
  274. test_push_not_found_parent(BaseUrl, AuthParams) ->
  275. ParamsChild = auth_params(AuthParams) ++ [{"type", "test_push_1"},
  276. {"parent", "unexistent_id"},
  277. {"metadata[description]", "pushed_event"}],
  278. {struct, [{"error", "not_found"}]} =
  279. tests_utils:post(BaseUrl, "/event/testmeeting", ParamsChild).
  280. test_push_not_found_to(BaseUrl, AuthParams) ->
  281. Params = auth_params(AuthParams) ++ [{"type", "test_push_1"},
  282. {"to", "unexistent_user"},
  283. {"metadata[description]", "pushed_event"}],
  284. {struct, [{"error", "not_found"}]} =
  285. tests_utils:post(BaseUrl, "/event/testmeeting", Params).
  286. test_get(BaseUrl, AuthParams) ->
  287. ?assertMatch({struct, [{"result", {array,
  288. [ {struct, [{"type", "test_event_1"}
  289. , {"domain", _}
  290. , {"datetime", _}
  291. , {"id", _}
  292. , {"location", "testmeeting"}
  293. , {"from", _}
  294. , {"metadata", {struct, []}}
  295. ]},
  296. {struct, [{"type", "test_event_2"}
  297. , {"domain", _}
  298. , {"datetime", _}
  299. , {"id", _}
  300. , {"location", "testmeeting"}
  301. , {"from", _}
  302. , {"metadata", {struct, []}}
  303. ]},
  304. {struct, [{"type", "test_event_3"}
  305. , {"domain", _}
  306. , {"datetime", _}
  307. , {"id", _}
  308. , {"location", "testmeeting"}
  309. , {"from", _}
  310. , {"metadata", {struct, [{"description", "test"}]}}
  311. ]}|_]
  312. }}]}, tests_utils:get(BaseUrl, "/event/testmeeting", auth_params(AuthParams))).
  313. test_get_without_meeting(BaseUrl, AuthParams) ->
  314. Params = [{"type", "non_global_event"},
  315. {"metadata[description]", "plop2"}],
  316. post_event(BaseUrl, "testmeeting", AuthParams, Params),
  317. timer:sleep(1000),
  318. ParamsGet = auth_params(AuthParams) ++ [{"order", "desc"},
  319. {"count", "1"}],
  320. Result = tests_utils:get(BaseUrl, "/event/", ParamsGet),
  321. ?assertMatch({struct, [{"result", {array,
  322. [{struct, [{"type", "non_global_event"}
  323. , {"domain", _}
  324. , {"datetime", _}
  325. , {"id", _}
  326. , {"location", "testmeeting"}
  327. , {"from", _}
  328. , {"metadata", {struct, [{"description", "plop2"}]}}
  329. ]}]}}]},
  330. Result).
  331. test_get_with_keywords(BaseUrl, AuthParams) ->
  332. Params = [{"type", "search_event"},
  333. {"metadata[description]", "lonely event"}],
  334. post_event(BaseUrl, "testmeeting", AuthParams, Params),
  335. timer:sleep(1000),
  336. ParamsGet = auth_params(AuthParams) ++ [{"search", "lonely"},
  337. {"count", "1"}],
  338. ?assertMatch({struct, [{"result", {array,
  339. [{struct, [{"type", "search_event"}
  340. , {"domain", _}
  341. , {"datetime", _}
  342. , {"id", _}
  343. , {"location", "testmeeting"}
  344. , {"from", _}
  345. , {"metadata", {struct, [{"description", "lonely event"}]}}
  346. ]}]}}]},
  347. tests_utils:get(BaseUrl, "/event/testmeeting", ParamsGet)).
  348. test_get_with_keywords_without_meeting(BaseUrl, {RootUid, RootSid}) ->
  349. Params = [{"uid", RootUid},
  350. {"sid", RootSid},
  351. {"type", "search_event"},
  352. {"metadata[description]", "lonely hungry event"}],
  353. {struct, [{"result", _}]} = tests_utils:post(BaseUrl, "/event/testmeeting", Params),
  354. ParamsGet = [{"uid", RootUid},
  355. {"sid", RootSid},
  356. {"search", "hungry"},
  357. {"count", "1"}],
  358. ?assertMatch({struct, [{"result", {array,
  359. [{struct, [{"type", "search_event"}
  360. , {"domain", _}
  361. , {"datetime", _}
  362. , {"id", _}
  363. , {"location", "testmeeting"}
  364. , {"from", RootUid}
  365. , {"metadata", {struct, [{"description", "lonely hungry event"}]}}
  366. ]}]}}]}, tests_utils:get(BaseUrl, "/event/", ParamsGet)).
  367. test_get_with_keywords_with_from(BaseUrl, {RootUid, RootSid}, {ParticipantUid, ParticipantSid}) ->
  368. Params = [{"uid", RootUid},
  369. {"sid", RootSid},
  370. {"type", "search_event_test_from"},
  371. {"metadata[description]", "lonely event"}],
  372. {struct, [{"result", _}]} = tests_utils:post(BaseUrl, "/event/testmeeting", Params),
  373. Params2 = [{"uid", ParticipantUid},
  374. {"sid", ParticipantSid},
  375. {"type", "search_event_test_from"},
  376. {"metadata[description]", "lonely event"}],
  377. {struct, [{"result", _}]} = tests_utils:post(BaseUrl, "/event/testmeeting", Params2),
  378. timer:sleep(1000),
  379. ParamsGet = [{"uid", RootUid},
  380. {"sid", RootSid},
  381. {"from", RootUid},
  382. {"search", "lonely"},
  383. {"order", "desc"},
  384. {"count", "1"}],
  385. ?assertMatch({struct, [{"result", {array,
  386. [{struct, [{"type", "search_event_test_from"}
  387. , {"domain", _}
  388. , {"datetime", _}
  389. , {"id", _}
  390. , {"location", "testmeeting"}
  391. , {"from", RootUid}
  392. , {"metadata", {struct, [{"description", "lonely event"}]}}
  393. ]}]}}]},
  394. tests_utils:get(BaseUrl, "/event/testmeeting", ParamsGet)).
  395. test_get_with_keywords_in_metadata(BaseUrl, {RootUid, RootSid}) ->
  396. Params = [{"uid", RootUid},
  397. {"sid", RootSid},
  398. {"type", "search_event"},
  399. {"metadata[description]", "lonely happy event"}],
  400. {struct, [{"result", _}]} = tests_utils:post(BaseUrl, "/event/testmeeting", Params),
  401. timer:sleep(1000),
  402. ParamsGet = [{"uid", RootUid},
  403. {"sid", RootSid},
  404. {"search", "happy"},
  405. {"count", "1"}],
  406. ?assertMatch({struct, [{"result", {array,
  407. [{struct, [{"type", "search_event"}
  408. , {"domain", _}
  409. , {"datetime", _}
  410. , {"id", _}
  411. , {"location", "testmeeting"}
  412. , {"from", RootUid}
  413. , {"metadata", {struct, [{"description", "lonely happy event"}]}}
  414. ]}]}}]},
  415. tests_utils:get(BaseUrl, "/event/testmeeting", ParamsGet)).
  416. test_get_with_keywords_and_timestart_and_timeend(BaseUrl, {RootUid, RootSid}) ->
  417. Params = [{"uid", RootUid},
  418. {"sid", RootSid}],
  419. {struct, [{"result", {array,
  420. [ {struct, [{"type", "test_event_1"}
  421. , {"domain", _}
  422. , {"datetime", _}
  423. , {"id", _}
  424. , {"location", "testmeeting"}
  425. , {"from", _}
  426. , {"metadata", {struct, []}}
  427. ]},
  428. {struct, [{"type", "test_event_2"}
  429. , {"domain", _}
  430. , {"datetime", _}
  431. , {"id", _}
  432. , {"location", "testmeeting"}
  433. , {"from", _}
  434. , {"metadata", {struct, []}}
  435. ]},
  436. {struct, [{"type", "test_event_3"}
  437. , {"domain", _}
  438. , {"datetime", Third}
  439. , {"id", _}
  440. , {"location", "testmeeting"}
  441. , {"from", _}
  442. , {"metadata", {struct, [{"description", "test"}]}}
  443. ]}|_]
  444. }}]} = tests_utils:get(BaseUrl, "/event/testmeeting", Params),
  445. ParamsGetStart = [{"uid", RootUid},
  446. {"sid", RootSid},
  447. {"type", "test_event_3"},
  448. {"search", "test"},
  449. {"start", integer_to_list(Third)},
  450. {"end", integer_to_list(Third + 1)}],
  451. {struct, [{"result", {array,
  452. [ {struct, [{"type", "test_event_3"}
  453. , {"domain", _}
  454. , {"datetime", Third}
  455. , {"id", _}
  456. , {"location", "testmeeting"}
  457. , {"from", _}
  458. , {"metadata", {struct, [{"description", "test"}]}}
  459. ]}|_]
  460. }}]} = tests_utils:get(BaseUrl, "/event/testmeeting/", ParamsGetStart),
  461. ParamsGetNothing = [{"uid", RootUid},
  462. {"sid", RootSid},
  463. {"type", "test_event_3"},
  464. {"search", "test"},
  465. {"start", integer_to_list(Third - 2)},
  466. {"end", integer_to_list(Third - 1)}],
  467. {struct, [{"result", {array,[]}}]} =
  468. tests_utils:get(BaseUrl, "/event/testmeeting/", ParamsGetNothing).
  469. test_get_with_type(BaseUrl, {RootUid, RootSid}) ->
  470. Params = [{"uid", RootUid},
  471. {"sid", RootSid}],
  472. {struct, [{"result", {array,
  473. [ {struct, [{"type", "test_event_1"}
  474. , {"domain", _}
  475. , {"datetime", _}
  476. , {"id", _}
  477. , {"location", "testmeeting"}
  478. , {"from", _}
  479. , {"metadata", {struct, []}}
  480. ]},
  481. {struct, [{"type", "test_event_2"}
  482. , {"domain", _}
  483. , {"datetime", _}
  484. , {"id", _}
  485. , {"location", "testmeeting"}
  486. , {"from", _}
  487. , {"metadata", {struct, []}}
  488. ]},
  489. {struct, [{"type", "test_event_3"}
  490. , {"domain", _}
  491. , {"datetime", Third}
  492. , {"id", _}
  493. , {"location", "testmeeting"}
  494. , {"from", _}
  495. , {"metadata", {struct, [{"description", "test"}]}}
  496. ]}|_]
  497. }}]} = tests_utils:get(BaseUrl, "/event/testmeeting", Params),
  498. ParamsGetStart = [{"uid", RootUid},
  499. {"sid", RootSid},
  500. {"type", "test_event_3"}],
  501. ?assertMatch({struct, [{"result", {array,
  502. [ {struct, [{"type", "test_event_3"}
  503. , {"domain", _}
  504. , {"datetime", Third}
  505. , {"id", _}
  506. , {"location", "testmeeting"}
  507. , {"from", _}
  508. , {"metadata", {struct, [{"description", "test"}]}}
  509. ]}|_]
  510. }}]},
  511. tests_utils:get(BaseUrl, "/event/testmeeting/", ParamsGetStart)).
  512. test_get_with_types(BaseUrl, {RootUid, RootSid}) ->
  513. Params = [{"uid", RootUid},
  514. {"sid", RootSid}],
  515. {struct, [{"result", {array,
  516. [ {struct, [{"type", "test_event_1"}
  517. , {"domain", _}
  518. , {"datetime", _}
  519. , {"id", _}
  520. , {"location", "testmeeting"}
  521. , {"from", _}
  522. , {"metadata", {struct, []}}
  523. ]},
  524. {struct, [{"type", "test_event_2"}
  525. , {"domain", _}
  526. , {"datetime", _}
  527. , {"id", _}
  528. , {"location", "testmeeting"}
  529. , {"from", _}
  530. , {"metadata", {struct, []}}
  531. ]},
  532. {struct, [{"type", "test_event_3"}
  533. , {"domain", _}
  534. , {"datetime", Third}
  535. , {"id", _}
  536. , {"location", "testmeeting"}
  537. , {"from", _}
  538. , {"metadata", {struct, [{"description", "test"}]}}
  539. ]}|_]
  540. }}]} = tests_utils:get(BaseUrl, "/event/testmeeting", Params),
  541. ParamsGetStart = [{"uid", RootUid},
  542. {"sid", RootSid},
  543. {"type", "test_event_3,test_event_1"}],
  544. ?assertMatch({struct, [{"result", {array,
  545. [ {struct, [{"type", "test_event_1"}
  546. , {"domain", _}
  547. , {"datetime", _}
  548. , {"id", _}
  549. , {"location", "testmeeting"}
  550. , {"from", _}
  551. , {"metadata", {struct, []}}
  552. ]},
  553. {struct, [{"type", "test_event_3"}
  554. , {"domain", _}
  555. , {"datetime", Third}
  556. , {"id", _}
  557. , {"location", "testmeeting"}
  558. , {"from", _}
  559. , {"metadata", {struct, [{"description", "test"}]}}
  560. ]}|_]
  561. }}]},
  562. tests_utils:get(BaseUrl, "/event/testmeeting/", ParamsGetStart)).
  563. test_get_with_type_and_timestart(BaseUrl, {RootUid, RootSid}) ->
  564. Params = [{"uid", RootUid},
  565. {"sid", RootSid}],
  566. {struct, [{"result", {array,
  567. [ {struct, [{"type", "test_event_1"}
  568. , {"domain", _}
  569. , {"datetime", _}
  570. , {"id", _}
  571. , {"location", "testmeeting"}
  572. , {"from", _}
  573. , {"metadata", {struct, []}}
  574. ]},
  575. {struct, [{"type", "test_event_2"}
  576. , {"domain", _}
  577. , {"datetime", _}
  578. , {"id", _}
  579. , {"location", "testmeeting"}
  580. , {"from", _}
  581. , {"metadata", {struct, []}}
  582. ]},
  583. {struct, [{"type", "test_event_3"}
  584. , {"domain", _}
  585. , {"datetime", Third}
  586. , {"id", _}
  587. , {"location", "testmeeting"}
  588. , {"from", _}
  589. , {"metadata", {struct, [{"description", "test"}]}}
  590. ]}|_]
  591. }}]} = tests_utils:get(BaseUrl, "/event/testmeeting", Params),
  592. ParamsGetStart = [{"uid", RootUid},
  593. {"sid", RootSid},
  594. {"type", "test_event_3"},
  595. {"start", integer_to_list(Third)}],
  596. ?assertMatch({struct, [{"result", {array,
  597. [ {struct, [{"type", "test_event_3"}
  598. , {"domain", _}
  599. , {"datetime", Third}
  600. , {"id", _}
  601. , {"location", "testmeeting"}
  602. , {"from", _}
  603. , {"metadata", {struct, [{"description", "test"}]}}
  604. ]}|_]
  605. }}]},
  606. tests_utils:get(BaseUrl, "/event/testmeeting/", ParamsGetStart)).
  607. test_get_with_type_and_timestart_and_timeend(BaseUrl, {RootUid, RootSid}) ->
  608. Params = [{"uid", RootUid},
  609. {"sid", RootSid}],
  610. {struct, [{"result", {array,
  611. [ {struct, [{"type", "test_event_1"}
  612. , {"domain", _}
  613. , {"datetime", _}
  614. , {"id", _}
  615. , {"location", "testmeeting"}
  616. , {"from", _}
  617. , {"metadata", {struct, []}}
  618. ]},
  619. {struct, [{"type", "test_event_2"}
  620. , {"domain", _}
  621. , {"datetime", _}
  622. , {"id", _}
  623. , {"location", "testmeeting"}
  624. , {"from", _}
  625. , {"metadata", {struct, []}}
  626. ]},
  627. {struct, [{"type", "test_event_3"}
  628. , {"domain", _}
  629. , {"datetime", Third}
  630. , {"id", _}
  631. , {"location", "testmeeting"}
  632. , {"from", _}
  633. , {"metadata", {struct, [{"description", "test"}]}}
  634. ]}|_]
  635. }}]} = tests_utils:get(BaseUrl, "/event/testmeeting", Params),
  636. ParamsGetStart = [{"uid", RootUid},
  637. {"sid", RootSid},
  638. {"type", "test_event_3"},
  639. {"start", integer_to_list(Third)},
  640. {"end", integer_to_list(Third + 1)}],
  641. {struct, [{"result", {array,
  642. [ {struct, [{"type", "test_event_3"}
  643. , {"domain", _}
  644. , {"datetime", Third}
  645. , {"id", _}
  646. , {"location", "testmeeting"}
  647. , {"from", _}
  648. , {"metadata", {struct, [{"description", "test"}]}}
  649. ]}|_]
  650. }}]} = tests_utils:get(BaseUrl, "/event/testmeeting/", ParamsGetStart),
  651. ParamsGetNothing = [{"uid", RootUid},
  652. {"sid", RootSid},
  653. {"type", "test_event_3"},
  654. {"start", integer_to_list(Third - 2)},
  655. {"end", integer_to_list(Third - 1)}],
  656. {struct, [{"result", {array,[]}}]} =
  657. tests_utils:get(BaseUrl, "/event/testmeeting/", ParamsGetNothing).
  658. test_get_with_type_and_timeend(BaseUrl, {RootUid, RootSid}) ->
  659. Params = [{"uid", RootUid},
  660. {"sid", RootSid}],
  661. {struct, [{"result", {array,
  662. [ {struct, [{"type", "test_event_1"}
  663. , {"domain", _}
  664. , {"datetime", _}
  665. , {"id", _}
  666. , {"location", "testmeeting"}
  667. , {"from", _}
  668. , {"metadata", {struct, []}}
  669. ]},
  670. {struct, [{"type", "test_event_2"}
  671. , {"domain", _}
  672. , {"datetime", Second}
  673. , {"id", _}
  674. , {"location", "testmeeting"}
  675. , {"from", _}
  676. , {"metadata", {struct, []}}
  677. ]},
  678. {struct, [{"type", "test_event_3"}
  679. , {"domain", _}
  680. , {"datetime", Third}
  681. , {"id", _}
  682. , {"location", "testmeeting"}
  683. , {"from", _}
  684. , {"metadata", {struct, [{"description", "test"}]}}
  685. ]}|_]
  686. }}]} = tests_utils:get(BaseUrl, "/event/testmeeting", Params),
  687. ParamsGetStart = [{"uid", RootUid},
  688. {"sid", RootSid},
  689. {"type", "test_event_2"},
  690. {"end", integer_to_list(Third - 1)}],
  691. {struct, [{"result", {array,
  692. [ {struct, [{"type", "test_event_2"}
  693. , {"domain", _}
  694. , {"datetime", Second}
  695. , {"id", _}
  696. , {"location", "testmeeting"}
  697. , {"from", _}
  698. , {"metadata", {struct, []}}
  699. ]}|_]
  700. }}]} = tests_utils:get(BaseUrl, "/event/testmeeting/", ParamsGetStart).
  701. test_last(BaseUrl, {RootUid, RootSid}) ->
  702. Params = [{"uid", RootUid},
  703. {"sid", RootSid},
  704. {"type", "last_event"},
  705. {"metadata[description]", "pushed_event"}],
  706. {struct, [{"result", _}]} = tests_utils:post(BaseUrl, "/event/testmeeting", Params),
  707. ParamsGetLast = [{"uid", RootUid},
  708. {"sid", RootSid},
  709. {"count", "1"},
  710. {"order", "desc"}],
  711. ?assertMatch({struct, [{"result",
  712. {array, [{struct, [{"type", "last_event"}
  713. , {"domain", _}
  714. , {"datetime", _}
  715. , {"id", _}
  716. , {"location", "testmeeting"}
  717. , {"from", _}
  718. , {"metadata", {struct, [{"description", "pushed_event"}]}}
  719. ]}]}}]}, tests_utils:get(BaseUrl, "/event/testmeeting/", ParamsGetLast)).
  720. send_long_polling_event(BaseUrl, {RootUid, RootSid}) ->
  721. send_long_polling_event(BaseUrl, {RootUid, RootSid}, []).
  722. send_long_polling_event(BaseUrl, {RootUid, RootSid}, ParamsEvent) ->
  723. timer:sleep(4000),
  724. Params = ParamsEvent ++[{"uid", RootUid},
  725. {"sid", RootSid},
  726. {"type", "long_polling_event"},
  727. {"metadata[description]", "relax, don't do it"}],
  728. {struct, [{"result", _}]} = tests_utils:post(BaseUrl, "/event/testmeeting", Params).
  729. do_long_polling(BaseUrl, {RootUid, RootSid}, Now, Params) ->
  730. ParamsGet = Params ++ [{"uid", RootUid},
  731. {"sid", RootSid},
  732. {"start", integer_to_list(Now)},
  733. {"mode", "longpolling"}],
  734. tests_utils:get(BaseUrl, "/live/testmeeting", ParamsGet).
  735. assert_long_polling(BaseUrl, AuthParams = {RootUid, _RootSid}, Params) ->
  736. Now = utils:now(),
  737. Result = do_long_polling(BaseUrl, AuthParams, Now, Params),
  738. {struct, [{"result", {array,
  739. [{struct, [{"type", "long_polling_event"}
  740. , {"domain", _}
  741. , {"datetime", _Datetime}
  742. , {"id", _}
  743. , {"location", "testmeeting"}
  744. , {"from", RootUid}
  745. , {"metadata", {struct, [{"description", "relax, don't do it"}]}}
  746. ]}]}}]} = Result.
  747. assert_long_polling_to(BaseUrl, AuthParams, Params, From, To) ->
  748. Now = utils:now(),
  749. Result = do_long_polling(BaseUrl, AuthParams, Now, Params),
  750. {struct, [{"result", {array,
  751. [{struct, [{"type", "long_polling_event"}
  752. , {"domain", _}
  753. , {"datetime", _Datetime}
  754. , {"id", _}
  755. , {"location", "testmeeting"}
  756. , {"to", To}
  757. , {"from", From}
  758. , {"metadata", {struct, [{"description", "relax, don't do it"}]}}
  759. ]}]}}]} = Result.
  760. assert_long_polling_parent(BaseUrl, AuthParams = {RootUid, _RootSid}, Params, Parent) ->
  761. Now = utils:now(),
  762. Result = do_long_polling(BaseUrl, AuthParams, Now, Params),
  763. {struct, [{"result", {array,
  764. [{struct, [{"type", "long_polling_event"}
  765. , {"domain", _}
  766. , {"datetime", _Datetime}
  767. , {"id", _}
  768. , {"location", "testmeeting"}
  769. , {"from", RootUid}
  770. , {"parent", Parent}
  771. , {"metadata", {struct, [{"description", "relax, don't do it"}]}}
  772. ]}]}}]} = Result.
  773. assert_no_result_long_polling(BaseUrl, AuthParams, Params) ->
  774. Now = utils:now(),
  775. Result = do_long_polling(BaseUrl, AuthParams, Now, Params),
  776. {struct, [{"result", {array, []}}]} = Result.
  777. test_long_polling(BaseUrl, AuthParams) ->
  778. spawn(?MODULE, send_long_polling_event, [BaseUrl, AuthParams]),
  779. assert_long_polling(BaseUrl, AuthParams, [{"type", "long_polling_event"}]).
  780. test_long_polling_with_types(BaseUrl, AuthParams) ->
  781. spawn(?MODULE, send_long_polling_event, [BaseUrl, AuthParams]),
  782. assert_long_polling(BaseUrl, AuthParams, [{"type", "long_polling_event,long_polling_event2"}]).
  783. test_long_polling_with_from(BaseUrl, AuthParams = {RootUid, _}) ->
  784. spawn(?MODULE, send_long_polling_event, [BaseUrl, AuthParams]),
  785. assert_long_polling(BaseUrl, AuthParams, [{"from", RootUid}]).
  786. test_long_polling_with_other_from(BaseUrl, AuthParams) ->
  787. spawn(?MODULE, send_long_polling_event, [BaseUrl, AuthParams]),
  788. assert_no_result_long_polling(BaseUrl, AuthParams, [{"from", "other_from"}]).
  789. test_long_polling_with_parent(Domain, BaseUrl, AuthParams = {RootUid, _}) ->
  790. {ok, EventId} = uce_event:add(Domain,
  791. #uce_event{ id=none,
  792. type="test_long_polling_for_parent",
  793. location="testmeeting",
  794. from=RootUid}),
  795. spawn(?MODULE, send_long_polling_event, [BaseUrl, AuthParams, [{"parent", EventId}]]),
  796. assert_long_polling_parent(BaseUrl, AuthParams, [{"parent", EventId}], EventId).
  797. test_long_polling_with_other_parent(BaseUrl, AuthParams) ->
  798. spawn(?MODULE, send_long_polling_event, [BaseUrl, AuthParams]),
  799. assert_no_result_long_polling(BaseUrl, AuthParams, [{"parent", "other_parent"}]).
  800. test_long_polling_with_search(BaseUrl, AuthParams) ->
  801. spawn(?MODULE, send_long_polling_event, [BaseUrl, AuthParams]),
  802. assert_long_polling(BaseUrl, AuthParams, [{"search", "relax"}]).
  803. test_long_polling_with_other_search(BaseUrl, AuthParams) ->
  804. spawn(?MODULE, send_long_polling_event, [BaseUrl, AuthParams]),
  805. assert_no_result_long_polling(BaseUrl, AuthParams, [{"search", "plop"}]).
  806. test_long_polling_with_to(BaseUrl, {RootUid, _} = RootAuthParams, {ParticipantUid, _ParticipantSid} = _ParticipantAuthParams) ->
  807. spawn(?MODULE, send_long_polling_event, [BaseUrl, RootAuthParams, [{"to", ParticipantUid}]]),
  808. assert_long_polling_to(BaseUrl, RootAuthParams, [{"type", "long_polling_event"}], RootUid, ParticipantUid).
  809. test_long_polling_with_to_and_participant(BaseUrl, {RootUid, _} = RootAuthParams, {ParticipantUid, _} = ParticipantAuthParams) ->
  810. spawn(?MODULE, send_long_polling_event, [BaseUrl, RootAuthParams, [{"to", ParticipantUid}]]),
  811. assert_long_polling_to(BaseUrl, ParticipantAuthParams, [{"type", "long_polling_event"}], RootUid, ParticipantUid).
  812. test_long_polling_with_to_and_other_participant(BaseUrl, RootAuthParams, ParticipantAuthParams, {OtherUid, _}) ->
  813. spawn(?MODULE, send_long_polling_event, [BaseUrl, RootAuthParams, [{"to", OtherUid}]]),
  814. assert_no_result_long_polling(BaseUrl, ParticipantAuthParams, [{"type", "long_polling_event"}]).