Skip to content
This repository was archived by the owner on Nov 7, 2020. It is now read-only.

Commit

Permalink
Fix tests; tear out farming
Browse files Browse the repository at this point in the history
  • Loading branch information
yourcelf committed Mar 22, 2016
1 parent 6bc1b4c commit 6a0b494
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 369 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## v2.1.0

- Upgrade to selenium-server-standalone v2.53.0 and selenium-webdriver v2.47.0. You will likely need to re-download selenium-server-standalone:

curl -L https://selenium-release.storage.googleapis.com/2.53/selenium-server-standalone-2.53.0.jar > bin/selenium-server-standalone.jar

- Tear out old farming functionality, which Google broke. See [hangout-farmer](https://github.com/unhangout/hangout-farmer.git) for a temporary workaround until we can replace Google Hangouts.

## v2.0.0

- First version of changelog.
114 changes: 1 addition & 113 deletions lib/hangout-farming.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,119 +18,7 @@ exports.init = function(app, db, options) {
db.redis.llen('global:hangout_urls', function(err, len) {
numHangoutUrlsAvailable = len;
});

// set up an HTTP endpoint that will put us in the endpoint redirect loop
// people who load this url
app.get('/hangout-farming', function(req, res){
if (!(req.isAuthenticated() && req.user.hasPerm("farmHangouts"))) {
return res.send(401, "Permission Denied");
}
var url = options.baseUrl + "/hangout-callback";

// initialize an oauth client request, using our google client id
oauth2Client =
new googleapis.OAuth2Client(
options.UNHANGOUT_GOOGLE_CLIENT_ID,
options.UNHANGOUT_GOOGLE_CLIENT_SECRET,
url);

var url = oauth2Client.generateAuthUrl({
access_type: 'offline',
scope: 'https://www.googleapis.com/auth/calendar'
});

// redirect the request to the google calendar api
res.redirect(url);
});

var getCalendarEvent = function(code, callback) {
try {
oauth2Client.getToken(code, function(err, token) {
if (err) { return callback(err); }
oauth2Client.credentials = token;
try {
googleapis.discover('calendar', 'v3').execute(function(err, client) {
if (err) { return callback(err); }
try {
var now = moment().format();
var preppedClient = client.calendar
.events
.insert({calendarId: "primary"}, {
summary: 'hangout',
description: 'hangout',
anyoneCanAddSelf: true,
visibility: "public",
transparency: "transparent",
reminders: { overrides: { method: 'popup', minutes: 0 } },
start: {
dateTime: moment().add('days', 1).format()
},
end: {
dateTime: moment().add('days', 1).add('hours', 1).format()
},
attendees: []
}).withAuthClient(oauth2Client);
} catch (e) {
return callback(e);
}
try {
preppedClient.execute(function(err, event) {
callback(err, event);
});
} catch (e) {
return callback(e);
}
});
} catch (e) {
return callback(e);
}
});
} catch (e) {
return callback(e);
}
}
// users who complete the authentication request will get redirected back here
// from google, after they authorize our app. The request they make back to
// our server will have a token attached to it, that we will use to
// place requests on behalf of this user.
app.get('/hangout-callback', function(req, res) {
if (!(req.isAuthenticated() && req.user.hasPerm("farmHangouts"))) {
return res.send(401, "Permission Denied");
} else if (!req.query.code) {
return res.send(400, "Missing code param.");
}
getCalendarEvent(req.query.code, function(err, event) {
if (err) {
logger.error("Error getting calendar event", err);
return res.send(500, "Error getting calendar event: " + JSON.stringify(err));
}
if("hangoutLink" in event) {
// push it into redis for safekeeping.
db.redis.lpush("global:hangout_urls", event.hangoutLink, function(err, num) {
if (err) {
logger.error("Redis error", err);
return res.send(500, JSON.stringify(err));
}
// purely for convenience of clicking to farm another url.
res.send("urls available: " + num +
"<br><a href='" + options.baseUrl + "/hangout-farming'>CLICK ME</a>");

// update the tracking number.
numHangoutUrlsAvailable = num;
logger.analytics("farming", {action: "create",
url: event.hangoutLink, total: num});
});
} else {
// we send this error if the calendar event created doesn't have a hangout url
// included in the object. Give the user some rudimentary instructions about
// how to fix this situation.
var msg = "your account doesn't seem to have the 'create video calls for events I create' option enabled. go to <a href='http://calendar.google.com'>google calendar</a>, settings (in the upper right hand corner) and enable that option. Then <a href='" + options.baseUrl + "/hangout-farming'>CLICK HERE!</a><br>" + JSON.stringify(event);
logger.error(msg);
res.send(500, msg);
}
});
});
}
};

// get a hangout url from redis
exports.getNextHangoutUrl = function(callback) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unhangout-server",
"version": "2.0.0",
"version": "2.1.0",
"author": "Drew Harry <[email protected]>",
"description": "a server for managing un-hangouts; large scale online un-conference-style events using Google Hangout",
"contributors": [
Expand Down Expand Up @@ -73,7 +73,7 @@
"expect.js": "0.3.1",
"libxmljs": "git://github.com/gwicke/libxmljs.git#7e1ceaf",
"mailparser": "~0",
"mocha": "1.18.2",
"mocha": "2.4.5",
"selenium-webdriver": "2.47.0",
"should": "3.2.0-beta1",
"simplesmtp": "~0",
Expand Down
2 changes: 1 addition & 1 deletion public/js/event-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ $(document).ready(function() {
// the server. Showing the admin UI is harmless if a non-admin messes with it.
if(IS_ADMIN) {
if (NUM_HANGOUT_URLS_WARNING > 0 && NUM_HANGOUT_URLS_AVAILABLE < NUM_HANGOUT_URLS_WARNING) {
$("#no-urls-warning").modal('show');
console.error("Too few hangout URLS available!", NUM_HANGOUT_URLS_AVAILABLE);
}
this.adminButtonView = new eventViews.AdminButtonView({
event: curEvent, transport: trans
Expand Down
5 changes: 5 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ var buildBrowser = function(callback) {
browser.get(exports.FAST_URL);
return browser.executeScript("document.cookie = 'mock_user=; path=/';");
};
browser.awaitModalDismissal = function(selector) {
return browser.wait(webdriver.until.elementIsNotVisible(
browser.findElement(webdriver.By.css(selector || ".modal")))
);
};
// This is sugar to wrap selenium's `wait` with a default timeout. We want
// to throw exceptions rather than waiting for mocha's timeout so that we
// can see a stack trace (mocha's timeous don't provide one).
Expand Down
5 changes: 4 additions & 1 deletion test/test.chat.selenium.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe("CHAT", function() {
browser.executeScript('$("#chat-container-region .panel-body").scrollTop(100)');
checkScroll(browser, false)
browser.byCss("#chat-input").sendKeys("msg " + i + "\n");
checkScroll(browser, true).then(function() { done(); });
checkScroll(browser, true);
browser.executeScript('$("#chat-container-region .panel-body").scrollTop(100)').then(function() {;
// Send a message from another user.
sock.write(JSON.stringify({
Expand Down Expand Up @@ -116,6 +116,9 @@ describe("CHAT", function() {
}
});
checkScroll(browser, false);
browser.then(function() {
done();
});

});

Expand Down
3 changes: 2 additions & 1 deletion test/test.create-sessions.selenium.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ describe("CREATE SESSIONS", function() {
browser.byCss("#join_cap").clear();
browser.byCss("#join_cap").sendKeys("wat");
browser.byCss("#join_cap").getAttribute("value").then(function(val) {
expect(val).to.be("wat");
//expect(val).to.be("wat"); // Recent firefox doesn't allow these chars on number input
expect(val).to.be("");
});
browser.byCss("#create-session").click();
browser.waitForSelector(".join-cap-error");
Expand Down
5 changes: 5 additions & 0 deletions test/test.facilitator-embeds.selenium.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ describe("FACILITATOR EMBEDS", function() {
});

// Remove the embed.
browser.awaitModalDismissal();
browser.byCss(".activity-settings").click();
browser.waitForSelector(".remove-embed");
browser.byCss(".remove-embed").click();

// Ensure 'about' is displayed.
browser.awaitModalDismissal();
browser.waitForSelector(".about-activity");
browser.waitForScript("$");
browser.executeScript("return $('.about-activity').text();").then(function(text) {
Expand All @@ -77,6 +79,7 @@ describe("FACILITATOR EMBEDS", function() {
});

// Add a new activity.
browser.awaitModalDismissal();
browser.byCss(".add-activity").click();
browser.waitForSelector(".add-activity-dialog input[type='text']");
// Doesn't allow blank URL's.
Expand All @@ -97,6 +100,8 @@ describe("FACILITATOR EMBEDS", function() {
}]);
});
// Embeds youtube videos.
browser.awaitModalDismissal(".add-activity-dialog");
browser.waitTime(1000);
browser.byCss(".activity-settings").click();
// Can't seem to get around this hard-coded delay; get occasional
// "Element is no longer attached to the DOM" errors without it.
Expand Down
Loading

0 comments on commit 6a0b494

Please sign in to comment.