OrgUnitTestsUtil.assertCreateOrgUnit(global.tests.admins.cam2013.client, 'Test orgunit 1', 'type', null, function(orgUnit) {

                    // Generate some test series with some events and add them to the organisational unit
                    var calendarStart = moment().subtract(1, 'day').format();
                    var calendarEnd = moment().add(30, 'day').format();
                    SeriesTestsUtil.generateSerieWithEvents(global.tests.admins.cam2013.client, 3, 5, calendarStart, calendarEnd, function(series) {
                        var serieIds = _.pluck(series, 'id');
                        OrgUnitTestsUtil.assertAddOrgUnitSeries(global.tests.admins.cam2013.client, orgUnit.id, serieIds, function() {

                            // Subscribe to the first serie
                            SeriesTestsUtil.assertSubscribeSeries(simon.client, series[0].id, simon.profile.id, orgUnit.id, function() {

                                // Subscribe to the organisational unit
                                OrgUnitTestsUtil.assertSubscribeOrgUnit(simon.client, orgUnit.id, null, function() {

                                    // Verify the user calendar contains the events of all 3 series
                                    var allEvents = _.union(series[0].events, series[1].events, series[2].events);
                                    UsersTestsUtil.assertGetUserCalendar(simon.client, simon.profile.id, calendarStart, calendarEnd, allEvents, function(calendar) {
                                        assert.strictEqual(calendar.results.length, 15);
                                        return callback();
                                    });
                                });
                            });
                        });
                    });
                });
                    OrgUnitTestsUtil.assertCreateOrgUnit(global.tests.admins.cam2013.client, 'Test orgunit 2', 'type', null, function(orgUnit2) {

                        // Generate a test serie with some events and add it to both organisational units
                        var calendarStart = moment().subtract(1, 'day').format();
                        var calendarEnd = moment().add(30, 'day').format();
                        SeriesTestsUtil.generateSerieWithEvents(global.tests.admins.cam2013.client, 1, 5, calendarStart, calendarEnd, function(series) {
                            var serie = series[0];
                            OrgUnitTestsUtil.assertAddOrgUnitSeries(global.tests.admins.cam2013.client, orgUnit1.id, [serie.id], function() {
                                OrgUnitTestsUtil.assertAddOrgUnitSeries(global.tests.admins.cam2013.client, orgUnit2.id, [serie.id], function() {

                                    // Subscribe to both organisational units
                                    OrgUnitTestsUtil.assertSubscribeOrgUnit(simon.client, orgUnit1.id, null, function() {
                                        OrgUnitTestsUtil.assertSubscribeOrgUnit(simon.client, orgUnit2.id, null, function() {

                                            // Verify only 5 unique events are in the user's calendar
                                            UsersTestsUtil.assertGetUserCalendar(simon.client, simon.profile.id, calendarStart, calendarEnd, serie.events, function(calendar) {
                                                assert.strictEqual(calendar.results.length, 5);
                                                return callback();
                                            });
                                        });
                                    });
                                });
                            });
                        });
                    });
Example #3
0
                OrgUnitTestsUtil.assertCreateOrgUnit(global.tests.admins.cam2013.client, 'Test org unit', 'module', null, function(orgUnit) {
                    var calendarStart = moment().subtract(1, 'day').format();
                    var calendarEnd = moment().add(30, 'day').format();
                    SeriesTestsUtil.generateSerieWithEvents(global.tests.admins.cam2013.client, 1, 5, calendarStart, calendarEnd, function(series) {
                        var series1 = series[0];
                        SeriesTestsUtil.generateSerieWithEvents(global.tests.admins.cam2013.client, 1, 5, calendarStart, calendarEnd, function(series) {
                            var series2 = series[0];
                            OrgUnitTestsUtil.assertAddOrgUnitSeries(global.tests.admins.cam2013.client, orgUnit.id, [series1.id, series2.id], function() {

                                // Simon subscribes to both series within the context of the organisational unit
                                SeriesTestsUtil.assertSubscribeSeries(simon.client, series1.id, simon.profile.id, orgUnit.id, function() {
                                    SeriesTestsUtil.assertSubscribeSeries(simon.client, series2.id, simon.profile.id, orgUnit.id, function() {

                                        // Nico subscribes to both series, but doesn't provide a context
                                        SeriesTestsUtil.assertSubscribeSeries(nico.client, series1.id, nico.profile.id, null, function() {
                                            SeriesTestsUtil.assertSubscribeSeries(nico.client, series2.id, nico.profile.id, null, function() {

                                                // Remove series 1 from the organisational unit
                                                OrgUnitTestsUtil.assertDeleteOrgUnitSeries(global.tests.admins.cam2013.client, orgUnit.id, [series1.id], function() {

                                                    // Verify the evens from series 1 have been removed from Simon's calendar but the events from series 2 are still present
                                                    UsersTestsUtil.assertGetUserCalendar(simon.client, simon.profile.id, calendarStart, calendarEnd, series2.events, function(calendar) {
                                                        assert.strictEqual(calendar.results.length, 5);
                                                        var series1EventIds = _.pluck(series1.events, 'id');
                                                        _.each(calendar.results, function(event) {
                                                            assert.ok(!_.contains(series1EventIds, event.id));
                                                        });

                                                        // Verify both series are still in Nico's calendar
                                                        UsersTestsUtil.assertGetUserCalendar(nico.client, nico.profile.id, calendarStart, calendarEnd, _.union(series1.events, series2.events), function(calendar) {
                                                            assert.strictEqual(calendar.results.length, 10);
                                                            return callback();
                                                        });
                                                    });
                                                });
                                            });
                                        });
                                    });
                                });
                            });
                        });
                    });
                });
                OrgUnitTestsUtil.assertCreateOrgUnit(global.tests.admins.cam2013.client, 'B', 'part', {'parent': root.id}, function(partB) {

                    // Create a series and stick it under both parts
                    var start = moment().format();
                    var end = moment().add(2, 'hour').format();
                    SeriesTestsUtil.generateSerieWithEvents(global.tests.admins.cam2013.client, 1, 5, start, end, function(series) {
                        series = series[0];
                        OrgUnitTestsUtil.assertAddOrgUnitSeries(global.tests.admins.cam2013.client, partA.id, [series.id], function() {
                            OrgUnitTestsUtil.assertAddOrgUnitSeries(global.tests.admins.cam2013.client, partB.id, [series.id], function() {

                                // Export the root node
                                OrgUnitTestsUtil.assertExportOrgUnit(global.tests.admins.cam2013.client, root.id, null, function(data) {
                                    // Sanity-check the series is present under both nodes
                                    assert.strictEqual(data.children[0].series[0].id, series.id);
                                    assert.strictEqual(data.children[1].series[0].id, series.id);
                                    return callback();
                                });
                            });
                        });
                    });
                });