PageRenderTime 126ms CodeModel.GetById 29ms app.highlight 86ms RepoModel.GetById 1ms app.codeStats 1ms

/wwwroot/lib/tests/test_ucejs.js

http://github.com/AF83/ucengine
JavaScript | 816 lines | 747 code | 63 blank | 6 comment | 8 complexity | 98fa53050bdca9833a70bb9fd1e92d3e MD5 | raw file
  1module('ucejs', {
  2    setup: function() {
  3        this.client = uce.createClient();
  4    },
  5    teardown: function() {
  6        $.mockjaxClear();
  7    }
  8});
  9
 10var Factories = {
 11    createPresence: function() {
 12        return {"user": "myuid", "id": "mysid"};
 13    },
 14    getDefaultMeeting: function() {
 15        return uce.createClient().attachPresence(Factories.createPresence()).meeting("mymeeting");
 16    }
 17};
 18
 19function jackTest(name, fun) {
 20    test(name, function() {
 21        var that = this;
 22        jack($.proxy(fun, that));
 23        ok(true, "mock are ok");
 24    });
 25}
 26
 27function addUceApiCall(method, url, data, status, responseText, xhr, callback) {
 28    if (url[0] == "/")
 29        url = "/api/"+ uce.version + url;
 30    jack.expect("$.ajax")
 31        .exactly("1 time")
 32        .mock(function(args) {
 33            equals(args.type, method, "");
 34            equals(args.url, url, "");
 35            same(args.data, data, "");
 36            setTimeout(function() {
 37                args.complete({
 38                    status      : status,
 39                    responseText: responseText
 40                });
 41                (callback || $.noop)();
 42            }, 1);
 43            return xhr;
 44        });
 45}
 46
 47test("can be accessed via window.uce", function() {
 48    same(window.uce, uce, "");
 49});
 50
 51jackTest("can create a presence", function() {
 52    stop();
 53    addUceApiCall("post", "/presence/", { "name": "name",
 54                                          "credential": "pwd" }, 200, '{"result": {"uid":"uid","sid":"sid"}}');
 55    var client = this.client;
 56    ok(!this.client.connected, "not connected");
 57    this.client.auth("name", "pwd", function(err, presence, xhr) {
 58        start();
 59        equals(err, null, "shoud not have error");
 60        equals(presence.user, "uid");
 61        equals(presence.id, "sid");
 62        equals(client.uid, "uid");
 63        ok(client.connected, "client connected");
 64    });
 65});
 66
 67jackTest("can get a presence", function() {
 68    stop();
 69    $.mockjax({
 70        url : '/api/' + uce.version + '/presence/',
 71        responseText: {"result": {"uid":"myuid", "sid":"mysid"}}
 72    });
 73    $.mockjax({
 74        url : '/api/' + uce.version + '/presence/mysid',
 75        data: { "uid": "myuid", "sid": "mysid"},
 76        response: function() {
 77            this.responseText = {"result": {"uid": "myuid", "sid":"mysid"}};
 78        }
 79    });
 80    var client = this.client;
 81    this.client.auth("name", "pwd", function(err, presence) {
 82        client.presence(function(err, r, xhr) {
 83            start();
 84            equals(r.result.sid, presence.id);
 85            equals(err, null);
 86        });
 87    });
 88});
 89
 90jackTest("can close a presence", function() {
 91    stop();
 92    $.mockjax({
 93        url : '/api/' + uce.version + '/presence/',
 94        responseText: {"result": {"uid":"myuid", "sid":"mysid"}}
 95    });
 96    $.mockjax({
 97        url : '/api/' + uce.version + '/presence/mysid',
 98        data: { "_method": "delete", "uid": "myuid", "sid": "mysid"},
 99        response: function() {
100            this.responseText = {"result": "mysid"}
101        }
102    });
103    var client = this.client;
104    this.client.auth("name", "pwd", function(err, presence) {
105        client.close(function(err, r, xhr) {
106            start();
107            ok(!client.connected, "not connected");
108            equals(err, null);
109        });
110    });
111});
112
113jackTest("can list users", function() {
114    stop();
115    addUceApiCall("get", "/user/", {"uid": "myuid", "sid": "mysid"}, 200, '{"result" : [{"name": "myuser"}, {}]}');
116    this.client.attachPresence(Factories.createPresence()).users.get(function(err, r, xhr) {
117        start();
118        equals(err, null);
119        equals(r.length, 2);
120    });
121});
122
123jackTest("can list meetings", function() {
124    stop();
125    addUceApiCall("get", "/meeting/", {"uid": "myuid", "sid": "mysid"}, 200, '{"result" : [{"name": "mymeeting"}]}');
126    this.client.attachPresence(Factories.createPresence()).meetings(function(err, r, xhr) {
127        start();
128        equals(err, null);
129        equals(r.length, 1);
130    });
131});
132
133test("meetings are the same", function() {
134    var client = this.client.attachPresence(Factories.createPresence());
135    ok(client.meeting("mymeeting") === client.meeting("mymeeting"));
136    ok(client.meeting("mymeeting") !== client.meeting("meeting"));
137});
138
139jackTest("can get meeting", function() {
140    stop();
141    addUceApiCall("get", "/meeting/mymeeting", {"uid": "myuid", "sid": "mysid"}, 200, '{"result" : {"name": "mymeeting"}}');
142    this.client.attachPresence(Factories.createPresence()).meeting("mymeeting").get(function(err, r, xhr) {
143        start();
144        equals(err, null);
145        equals(r.name, "mymeeting");
146    });
147});
148
149jackTest("can update meeting", function() {
150    stop();
151    addUceApiCall("post", "/meeting/mymeeting",
152                  {"uid": "myuid",
153                   "sid": "mysid",
154                   "_method": "put",
155                   "metadata": {'description': "a brand new description"}},
156                  200, '{"result" : "ok"}');
157    this.client.attachPresence(Factories.createPresence()).meeting("mymeeting")
158        .update({'description': 'a brand new description'},
159                function(err, r, xhr) {
160                    start();
161                    equals(err, null);
162                    equals(r.result, "ok");
163                });
164});
165
166jackTest("can join meeting", function() {
167    stop();
168    addUceApiCall("post", "/meeting/mymeeting/roster/",  {"uid": "myuid", "sid": "mysid", "metadata": {nickname: "plop"}}, 200, '{"name": "mymeeting"}');
169    var meeting = this.client.attachPresence(Factories.createPresence()).meeting("mymeeting");
170    meeting.join({nickname: 'plop'}, function(err, r, xhr) {
171        start();
172        equals(err, null);
173        equals(r.name, "mymeeting");
174        equals(meeting.uid, "myuid");
175    });
176});
177
178jackTest("can leave meeting", function() {
179    stop();
180    addUceApiCall("post", "/meeting/mymeeting/roster/myuid",  {"_method" :"delete", "uid": "myuid", "sid": "mysid"}, 200, '{"name": "mymeeting"}');
181    this.client.attachPresence(Factories.createPresence()).meeting("mymeeting").leave(function(err, r, xhr) {
182        start();
183        equals(err, null);
184    });
185});
186
187jackTest("can push event on meeting", function() {
188    stop();
189    addUceApiCall("post", "/event/mymeeting",  JSON.stringify({"uid": "myuid", "sid": "mysid", "type": "test_event", "metadata": {_mymetadata: "myvalue"}}, 200, ''));
190    this.client.attachPresence(Factories.createPresence()).meeting("mymeeting").push('test_event', {_mymetadata:"myvalue"}, function(err, r, xhr) {
191        start();
192        equals(err, null);
193    });
194});
195
196jackTest("can push event on meeting with a parent", function() {
197    stop();
198    addUceApiCall("post", "/event/mymeeting",  JSON.stringify({"uid": "myuid", "sid": "mysid", "type": "test_event", "parent": "test", "metadata": {_mymetadata: "myvalue"}}, 200, ''));
199    this.client.attachPresence(Factories.createPresence()).meeting("mymeeting").push({parent: "test", type: 'test_event'}, {_mymetadata:"myvalue"}, function(err, r, xhr) {
200        start();
201        equals(err, null);
202    });
203});
204
205jackTest("getEvents with callback on global success", function() {
206    stop();
207    addUceApiCall("get", "/event/mymeeting",  {"uid": "myuid", "sid": "mysid"}, 200, '{"result": [{}, {}]}');
208    this.client.attachPresence(Factories.createPresence()).meeting("mymeeting").getEvents({}, function(err, r, xhr) {
209        start();
210        equals(err, null);
211        same(r, [{}, {}]);
212    }, false);
213});
214
215jackTest("getEvents with callback on each event", function() {
216    stop();
217    expect(8);
218    var called = 0;
219    addUceApiCall("get", "/event/mymeeting",  {"uid": "myuid", "sid": "mysid"}, 200, '{"result": [{}, {}]}');
220    this.client.attachPresence(Factories.createPresence()).meeting("mymeeting").getEvents({}, function(err, r, xhr) {
221        equals(err, null);
222        called++;
223        if (called == 2) {
224            start();
225            same(r, {});
226            ok(true, "callback have been called 2 times");
227        }
228    }, true);
229});
230
231jackTest("getEvents with start", function() {
232    stop();
233    addUceApiCall("get", "/event/mymeeting",  {"uid": "myuid", "sid": "mysid", "start": "pouet"}, 200, '{"result": [{}, {}]}');
234    this.client.attachPresence(Factories.createPresence()).meeting("mymeeting").getEvents({start: "pouet" }, function(err, r, xhr) {
235        start();
236    }, false);
237});
238
239jackTest("getEvents with end", function() {
240    stop();
241    addUceApiCall("get", "/event/mymeeting",  {"uid": "myuid", "sid": "mysid", "end": "plop"}, 200, '{"result": [{}, {}]}');
242    this.client.attachPresence(Factories.createPresence()).meeting("mymeeting").getEvents({end: "plop"}, function(err, r, xhr) {
243        start();
244    }, false);
245});
246
247jackTest("getEvents with type", function() {
248    stop();
249    addUceApiCall("get", "/event/mymeeting",  {"uid": "myuid", "sid": "mysid", "type": "chuck_norris"}, 200, '{"result": [{}, {}]}');
250    this.client.attachPresence(Factories.createPresence()).meeting("mymeeting").getEvents({type: "chuck_norris"}, function(err, r, xhr) {
251        start();
252    }, false);
253});
254
255jackTest("waitEvents without type param", function() {
256    stop();
257    addUceApiCall("get", "/live/mymeeting",  {"uid": "myuid", "sid": "mysid", "mode": "longpolling", "start": "pouet"}, 200, '{"result": [{}]}');
258    this.client.attachPresence(Factories.createPresence()).meeting("mymeeting").waitEvents({start: "pouet"}, function(err, r, xhr) {
259        start();
260        equals(err, null);
261    }, true, ["longpolling"]);
262});
263
264jackTest("waitEvents with type param", function() {
265    stop();
266    addUceApiCall("get", "/live/mymeeting",  {"uid": "myuid", "sid": "mysid", "mode": "longpolling", "start": "pouet", "type" : "chuck_norris"}, 200, '{"result": [{}]}');
267    this.client.attachPresence(Factories.createPresence()).meeting("mymeeting").waitEvents({"start": "pouet", type: "chuck_norris"}, function(err, r, xhr) {
268        start();
269        equals(err, null);
270    }, true, ["longpolling"]);
271});
272
273jackTest("waitEvents without wait param", function() {
274    stop();
275    addUceApiCall("get", "/live/mymeeting",  {"uid": "myuid", "sid": "mysid", "mode": "longpolling", "start": "pouet"}, 200, '{"result": [{}]}');
276    this.client.attachPresence(Factories.createPresence()).meeting("mymeeting").waitEvents({start: "pouet"}, function(err, r, xhr) {
277        start();
278        equals(err, null);
279    }, true, ["longpolling"]);
280});
281
282jackTest("waitEvents can be stopped", function() {
283    expect(5);
284    stop();
285    addUceApiCall("get", "/live/mymeeting",  {"uid": "myuid", "sid": "mysid", "mode": "longpolling", "start": "pouet"}, 200, '{"result": [{}]}', {
286        abort: function() {
287            start();
288            ok(true, "waitEvent stopped");
289        }
290    }, false, ["longpolling"]);
291    this.client.attachPresence(Factories.createPresence()).meeting("mymeeting").waitEvents({start: "pouet"}, function(err, r, xhr) {}, true, ["longpolling"]).stop();
292});
293
294test("waitEvents auto restart after wait", function() {
295    expect(2);
296    stop();
297    var ajaxcall = 0; // nb of ajax request/response
298    var called   = 0;
299    $.mockjax({
300        url: '/api/' + uce.version + '/live/mymeeting',
301        responseTime: 10,
302        response: function() {
303            this.responseText = {
304                result: [{"datetime":"14"}]
305            };
306            ajaxcall++;
307        }
308    });
309    var client = this.client;
310    var env = {
311        start: function() {
312            var that = this;
313            this.polling = client.attachPresence(Factories.createPresence()).meeting("mymeeting").waitEvents({start: "pouet"}, function(err, r, xhr) {
314                called++;
315                if (ajaxcall > 2)
316                {
317                    that.polling.stop(); // stop polling
318                    // wait 1s to be sure long polling is stopped
319                    setTimeout(function() {
320                        start();
321                        equals(3, ajaxcall, "ajaxcall");
322                        equals(3, called, "callback");
323                    }, 1000);
324                }
325            }, false, ["longpolling"]);
326        }
327    };
328    env.start();
329});
330
331jackTest("waitEvents, callback is called on each events", function() {
332    stop();
333    expect(5);
334    var called = 0;
335    addUceApiCall("get", "/live/mymeeting",  {"uid": "myuid", "sid": "mysid", "mode": "longpolling", "start": "pouet"}, 200, '{"result": [{}, {}]}');
336    this.client.attachPresence(Factories.createPresence()).meeting("mymeeting").waitEvents({start: "pouet"}, function(err, r, xhr) {
337        called++;
338        if (called == 2) {
339            start();
340            ok(true, "callback have been called 2 times");
341        }
342    }, true, ["longpolling"]);
343});
344
345function longPollingTest(events, test) {
346    var env = {
347        ajaxcall : 0,
348        start: function() {
349            this.mock();
350            test(this);
351        },
352        mock : function() {
353            var that = this;
354            $.mockjax({
355                url: '/api/' + uce.version + '/live/mymeeting',
356                responseTime: 1,
357                response: function() {
358                    this.responseText = {
359                        result: events
360                    };
361                    that.ajaxcall++;
362                }
363            });
364        }
365    };
366    env.start();
367}
368
369test("startLoop with bind", function() {
370    stop();
371    var client = this.client.attachPresence(Factories.createPresence());
372    longPollingTest([{type: "chuck_norris", datetime : 14}], function(longPolling) {
373        longPolling.xhr = client.meeting("mymeeting").bind(function(event) {
374            same(event, {type: "chuck_norris", datetime : 14});
375            equals(longPolling.ajaxcall, 1);
376            longPolling.xhr.stop();
377            start();
378        }).startLoop(1213, ["longpolling"]);
379    });
380});
381
382test("startLoop widgets/whatever can bind event handler with special type", function() {
383    stop();
384    expect(2);
385    var client = this.client.attachPresence(Factories.createPresence());
386    longPollingTest([{type: "chuck_norris", datetime : 14}, {type: "plop"}],
387                    function(longPolling) {
388                        longPolling.xhr = client.meeting("mymeeting").on("chuck_norris", function(event) {
389                            same(event, {type : "chuck_norris", datetime: 14});
390                            equals(longPolling.ajaxcall, 1);
391                            longPolling.xhr.stop();
392                            start();
393                        }).startLoop(1213, ["longpolling"]);
394                    });
395});
396
397test("startLoop with 'bind', alias of 'on'", function() {
398    stop()
399    expect(2);
400    var client = this.client.attachPresence(Factories.createPresence());
401    longPollingTest([{type: "chuck_norris", datetime : 14}, {type: "plop"}],
402                    function(longPolling) {
403        longPolling.xhr = client.meeting("mymeeting").on("chuck_norris", function(event) {
404            same(event, {type : "chuck_norris", datetime: 14});
405            equals(longPolling.ajaxcall, 1);
406            longPolling.xhr.stop();
407            start();
408        }).startLoop(1213, ["longpolling"]);
409    });
410});
411
412test("get upload url", function() {
413    var url = this.client.attachPresence(Factories.createPresence()).meeting("mymeeting").getFileUploadUrl();
414    equals(url, "/api/" + uce.version + "/file/mymeeting?uid=myuid&sid=mysid");
415    var url = this.client.attachPresence({"user": "myuid2", "id": "mysid2"}).meeting("mymeeting2").getFileUploadUrl();
416    equals(url, "/api/" + uce.version + "/file/mymeeting2?uid=myuid2&sid=mysid2");
417});
418
419test("get download file url", function() {
420    var meeting = this.client.attachPresence(Factories.createPresence()).meeting("mymeeting");
421    var url = meeting.getFileDownloadUrl('mydoc.pdf');
422    equals(url, "/api/" + uce.version + "/file/mymeeting/mydoc.pdf?uid=myuid&sid=mysid");
423    var url = meeting.getFileDownloadUrl('mydoc2.pdf');
424    equals(url, "/api/" + uce.version + "/file/mymeeting/mydoc2.pdf?uid=myuid&sid=mysid");
425});
426
427jackTest("delete file", function() {
428    stop();
429    addUceApiCall("post", "/file/mymeeting/file_id",
430                  {"_method": "delete",
431                   "uid": "myuid",
432                   "sid": "mysid"}, 200, '{"result": "ok"}');
433    this.client.attachPresence(Factories.createPresence()).meeting("mymeeting")
434        .delFile("file_id", function(err, result, xhr) {
435            start();
436            equals(null, err);
437            equals(result.result, "ok");
438        });
439});
440
441jackTest("this.client.time",  function() {
442    stop();
443    addUceApiCall("get", "/time",  {}, 200, '{"result": "4"}');
444    this.client.attachPresence(Factories.createPresence()).time.get(function(err, result, xhr) {
445        start();
446        equals(null, err);
447        equals(result, 4);
448    });
449});
450
451test("uce waiter", function() {
452    var called = 0;
453    var waiter = this.client.getWaiter(4, function() {
454        called++;
455        equals(called, 1);
456    });
457    waiter();waiter();waiter();waiter();
458});
459
460jackTest("register new user", function() {
461    stop();
462    addUceApiCall("post", "/user/",  {name: "test@example.net", auth: 'password', credential: 'mypwd', metadata: {nickname: 'test'}}, 200, '{"result":"uid"}');
463    this.client.user.register('test@example.net', 'password', 'mypwd', {nickname: 'test'}, function(err, result) {
464        start();
465        equals(null, err);
466        same(result, {"result":"uid"});
467    });
468});
469
470jackTest("register with password", function() {
471    stop();
472    addUceApiCall("post", "/user/",  {name: "test@example.net", auth: 'password', credential: 'mypwd', metadata: {nickname: 'test'}}, 200, '{"result":"uid"}');
473    this.client.user.registerWithPassword('test@example.net', 'mypwd', {nickname: 'test'}, function(err, result) {
474        start();
475        equals(null, err);
476        same(result, {"result":"uid"});
477    });
478});
479
480jackTest("get user", function() {
481    stop();
482    addUceApiCall("get", "/user/test@example.net",  {"uid": "myuid", "sid": "mysid"}, 200, '{"result": {}}');
483    this.client.attachPresence(Factories.createPresence()).user.get('test@example.net', function(err, result) {
484        start();
485        equals(null, err);
486        same(result, {"result":{}});
487    });
488});
489
490jackTest("custom api url", function() {
491    stop();
492    addUceApiCall("get", "http://example.com/api/" + uce.version + "/user/test@example.net",  {"uid": "myuid", "sid": "mysid"}, 200, '{"result": {}}');
493    var client = uce.createClient('http://example.com/api');
494    var meeting = client.attachPresence(Factories.createPresence()).meeting("mymeeting");
495    var url = meeting.getFileDownloadUrl('mydoc.pdf');
496    equals(url, "http://example.com/api/" + uce.version + "/file/mymeeting/mydoc.pdf?uid=myuid&sid=mysid");
497    var url = meeting.getFileUploadUrl();
498    equals(url, "http://example.com/api/" + uce.version + "/file/mymeeting?uid=myuid&sid=mysid");
499    client.attachPresence(Factories.createPresence()).user.get('test@example.net', function(err, result) {
500        start();
501    });
502});
503
504jackTest("search events in all meetings", function() {
505    stop();
506    addUceApiCall("get", "/search/event",  {"uid": "myuid", "sid": "mysid", "searchTerms" : "hello"}, 200, '{"result": {}}');
507    this.client.attachPresence(Factories.createPresence()).search({query: 'hello'}, function(err, result) {
508        start();
509        equals(null, err);
510        same(result, {});
511    });
512});
513
514jackTest("search events with options", function() {
515    stop();
516    addUceApiCall("get", "/search/event",  {"uid": "myuid", "sid": "mysid", "searchTerms" : "hello", "order": "asc"}, 200, '{"result": {}}');
517    this.client.attachPresence(Factories.createPresence()).search({query: 'hello'}, {order: "asc"}, function(err, result) {
518        start();
519    });
520});
521
522jackTest("complex search events in all meetings", function() {
523    stop();
524    addUceApiCall("get", "/search/event",  {"uid": "myuid", "sid": "mysid", "searchTerms" : "type:internal.meeting.add,chat.message.new start:42 end:44 hello"}, 200, '{"result": {}}');
525    this.client.attachPresence(Factories.createPresence()).search({type: ["internal.meeting.add","chat.message.new"],
526                                                                   start: 42,
527                                                                   end: 44,
528                                                                   query: 'hello'}, function(err, result) {
529        start();
530    });
531});
532
533jackTest("search events in a meeting", function() {
534    stop();
535    addUceApiCall("get", "/search/event",  {"uid": "myuid", "sid": "mysid", "searchTerms" : "location:demo hello"}, 200, '{"result": {}}');
536    this.client.attachPresence(Factories.createPresence()).meeting('demo').search({query: 'hello'}, function(err, result) {
537        start();
538        equals(null, err);
539        same(result, {});
540    });
541});
542
543jackTest("search events in a meeting with options", function() {
544    stop();
545    addUceApiCall("get", "/search/event",  {"uid": "myuid", "sid": "mysid", "searchTerms" : "location:demo hello", "order": "asc"}, 200, '{"result": {}}');
546    this.client.attachPresence(Factories.createPresence()).meeting('demo').search({query: 'hello'}, {order: "asc"}, function(err, result) {
547        start();
548        equals(null, err);
549        same(result, {});
550    });
551});
552
553jackTest("complex search events in a meeting", function() {
554    stop();
555    addUceApiCall("get", "/search/event",  {"uid": "myuid", "sid": "mysid", "searchTerms" : "type:internal.meeting.add,chat.message.new start:42 end:44 location:demo hello"}, 200, '{"result": {}}');
556    this.client.attachPresence(Factories.createPresence()).meeting('demo').search({type: ["internal.meeting.add","chat.message.new"],
557                                                                                   start: 42,
558                                                                                   end: 44,
559                                                                                   query: 'hello'}, function(err, result) {
560        start();
561    });
562});
563
564module("ucejs.userAccess", {
565    setup:function() {
566        this.client = uce.createClient();
567    }
568});
569
570jackTest("user.addRole", function() {
571    stop();
572    addUceApiCall("post", "/user/otheruid/roles", {"uid": "myuid",
573                                                   "sid": "mysid",
574                                                   "role": "newrole",
575                                                   "location": "testmeeting"},
576                  201, '{"result":"created"}');
577    this.client
578        .attachPresence(Factories.createPresence())
579        .user.addRole("otheruid",
580                      "newrole",
581                      "testmeeting",
582                      function(err, result) {
583                          start();
584                          equals(err, null);
585                          same(result.result, "created");
586                      });
587});
588
589jackTest("user.deleteRole", function() {
590    stop();
591    addUceApiCall("post", "/user/otheruid/roles/newrole/testmeeting",
592                  {uid: "myuid",
593                   sid: "mysid",
594                   _method: "delete"},
595                  200, '{"result":"ok"}');
596    this.client.attachPresence(Factories.createPresence())
597        .user.delRole("otheruid",
598                         "newrole",
599                         "testmeeting",
600                         function(err, result) {
601                             start();
602                             equals(err, null);
603                             same(result.result, "ok");
604                         });
605});
606
607jackTest("user.can", function() {
608    stop();
609    addUceApiCall("get", "/user/otheruid/can/action/object/mymeeting",
610                  {"conditions": {'condition_1': 'value'},
611                   "uid": "myuid",
612                   "sid": "mysid"}, 200, '{"result":"true"}');
613    this.client.attachPresence(Factories.createPresence()).user.can("otheruid", "action", "object", {'condition_1': 'value'}, "mymeeting", function(err, result) {
614        start();
615        equals(err, null);
616        same(result, true);
617    });
618});
619
620jackTest("meeting.can", function() {
621    stop();
622    addUceApiCall("get", "/user/otheruid/can/action/object/mymeeting",
623                  {"conditions": {'condition_1': 'value'},
624                   "uid": "myuid",
625                   "sid": "mysid"}, 200, '{"result":"true"}');
626    this.client.attachPresence(Factories.createPresence()).
627        meeting('mymeeting').can("otheruid", "action", "object", {'condition_1': 'value'}, function(err, result) {
628        start();
629        equals(err, null);
630        ok(result);
631    });
632});
633
634jackTest("meeting.canCurrentUser", function() {
635    stop();
636    addUceApiCall("get", "/user/myuid/can/action/object/mymeeting",
637                  {"conditions": {'condition_1': 'value'},
638                   "uid": "myuid",
639                   "sid": "mysid"}, 200, '{"result":"true"}');
640    this.client.attachPresence(Factories.createPresence()).
641        meeting('mymeeting').canCurrentUser("action", "object", {'condition_1': 'value'}, function(err, result) {
642        start();
643        equals(err, null);
644        ok(result);
645    });
646});
647
648module("ucejs.role", {
649    setup:function() {
650        this.client = uce.createClient();
651    }
652});
653
654jackTest("role.add", function() {
655    stop();
656    addUceApiCall("post", "/role",
657                  {"name": "newrole",
658                   "uid": "myuid",
659                   "sid": "mysid"}, 201, '{"result":"created"}');
660    this.client.attachPresence(Factories.createPresence())
661        .role.add("newrole", function(err, result) {
662            start();
663            equals(err, null);
664            same(result.result, "created");
665        });
666});
667
668jackTest("role.delete", function() {
669    stop();
670    addUceApiCall("post", "/role/newrole",
671                  {"uid": "myuid",
672                   "sid": "mysid",
673                   "_method": "delete"}, 200, '{"result":"ok"}');
674    this.client.attachPresence(Factories.createPresence())
675        .role.del("newrole", function(err, result) {
676            start();
677            equals(err, null);
678            same(result.result, "ok");
679        });
680});
681
682jackTest("role.addAccess", function() {
683    stop();
684    addUceApiCall("post", "/role/myrole/acl",
685                  {"action": "access_action",
686                   "object": "access_object",
687                   "conditions": {'a': 'b', 'c': 'd'},
688                   "uid": "myuid",
689                   "sid": "mysid"}, 201, '{"result":"created"}');
690    this.client.attachPresence(Factories.createPresence())
691        .role.addAccess("myrole", "access_action", "access_object", {'a': 'b', 'c': 'd'},
692                        function(err, result) {
693                            start();
694                            equals(err, null);
695                            same(result.result, "created");
696                        });
697});
698
699jackTest("role.deleteAccess", function() {
700    stop();
701    addUceApiCall("post", "/role/myrole/acl/access_action/access_object",
702                  {"conditions": {'a': 'b', 'c': 'd'},
703                   "uid": "myuid",
704                   "sid": "mysid",
705                   "_method": "delete"}, 200, '{"result":"ok"}');
706    this.client.attachPresence(Factories.createPresence())
707        .role.delAccess("myrole", "access_action", "access_object", {'a': 'b', 'c': 'd'},
708                        function(err, result) {
709                            start();
710                            equals(err, null);
711                            same(result.result, "ok");
712                        });
713});
714
715module("ucejs.replay", {
716    setup:function() {
717        this.meeting = Factories.getDefaultMeeting();
718    },
719    teardown: function() {
720        this.meeting.stopReplay();
721    }
722});
723
724test("start orchestrator", function() {
725    expect(2);
726    stop();
727    var that = this;
728    this.meeting.bind("chuck_norris", function(event) {
729        start();
730        equal(event.type, "chuck_norris");
731        equal(that.meeting.getCurrentReplay(), 100);
732    }).startReplay(0, [{"type": "chuck_norris", "datetime":"14"},
733                       {"type": "bruce_lee",    "datetime":"42"}]);
734});
735
736test("temporize events", function() {
737    expect(4);
738    stop();
739    var called = 0;
740    this.meeting.bind(function(event) {
741        called++;
742    }).startReplay(0, [{"type": "chuck_norris", "datetime":"1000"},
743                       {"type": "jacky_chan",   "datetime":"3000"},
744                       {"type": "bruce_lee",    "datetime":"5000"}]);
745    // no events
746    setTimeout(function() {
747        equals(called, 0);
748    }, 900);
749    // chuck_norris == aie
750    setTimeout(function() {
751        equals(called, 1);
752    }, 2000);
753    // chuck_norris + jacky_chan == outch
754    setTimeout(function() {
755        equals(called, 2);
756    }, 4000);
757    // chuck_norris + jacky_chan + bruce_less == Armageddon
758    setTimeout(function() {
759        start();
760        equals(called, 3); // everyone is dead ?
761    }, 6500);
762});
763
764test("can stop orchestrator", function() {
765    expect(2);
766    stop();
767    var called = 0, that = this;
768    this.meeting.bind(function(event) {
769        called++;
770    }).startReplay(0, [{"type": "chuck_norris", "datetime":"1000"},
771                       {"type": "bruce_lee",    "datetime":"2000"}]);
772    // no events
773    setTimeout(function() {
774        that.meeting.stopReplay();
775        equals(called, 1);
776    }, 1500);
777    setTimeout(function() {
778        start();
779        equals(called, 1);
780    }, 2500);
781});
782
783test("can jump to a specific datetime in the future", function() {
784    stop();
785    var called = 0, that = this;
786    this.meeting.bind(function(event) {
787        called++;
788    }).startReplay(0, [{"type": "chuck_norris", "datetime":1000},
789                       {"type": "bruce_lee",    "datetime":2000},
790                       {"type": "bruce_lee",    "datetime":4000}]);
791    setTimeout(function() {
792        that.meeting.jumpToReplay(2000);
793    }, 100);
794    setTimeout(function() {
795        start();
796        equals(called, 3);
797    }, 2500);
798});
799
800test("can jump to a specific datetime in the past", function() {
801    stop();
802    var called = 0, that = this;
803    this.meeting.bind(function(event) {
804        called++;
805    }).startReplay(0, [{"type": "chuck_norris", "datetime":1000},
806                       {"type": "bruce_lee",    "datetime":2000},
807                       {"type": "bruce_lee",    "datetime":2500}]);
808    setTimeout(function() {
809        that.meeting.jumpToReplay(100);
810        equal(called, 1);
811    }, 1500);
812    setTimeout(function() {
813        start();
814        equals(called, 4);
815    }, 4500);
816});