Test that userId is recorded when sending package stats.

This commit is contained in:
Avital Oliver
2014-05-12 16:08:40 -07:00
parent 5d67910ce8
commit a51b4697ae
3 changed files with 52 additions and 14 deletions

View File

@@ -31,13 +31,7 @@ var recordPackages = function (appDir) {
// to the package stats server. If we can't connect, for example, we
// don't care; we'll just miss out on recording these packages.
Fiber(function () {
var Package = uniload.load({
packages: ["livedata"]
});
var conn = new ServiceConnection(
Package,
config.getPackageStatsServerUrl()
);
var conn = connectToPackagesStatsServer();
if (auth.isLoggedIn()) {
auth.loginWithTokenOrOAuth(
@@ -58,5 +52,25 @@ var recordPackages = function (appDir) {
}).run();
};
// Used in a test (and can only be used against the testing packages
// server) to fetch one package stats entry for a given application.
var getAppPackagesForAppIdInTest = function (appDir) {
return connectToPackagesStatsServer().call(
"getAppPackagesForAppId",
project.getAppIdentifier(appDir) /*appId*/);
};
var connectToPackagesStatsServer = function () {
var Package = uniload.load({
packages: ["livedata"]
});
var conn = new ServiceConnection(
Package,
config.getPackageStatsServerUrl()
);
return conn;
};
exports.recordPackages = recordPackages;
exports.packageList = packageList; // for use in the "stats" self-test.
exports.getAppPackagesForAppIdInTest = getAppPackagesForAppIdInTest;

View File

@@ -133,6 +133,11 @@ exports.logout = function (s) {
run.expectExit(0);
};
exports.getUserId = function (s) {
var data = JSON.parse(s.readSessionFile());
return data.sessions["www.meteor.com"].userId;
};
var registrationUrlRegexp =
/https:\/\/www\.meteor\.com\/setPassword\?([a-zA-Z0-9\+\/]+)/;
exports.registrationUrlRegexp = registrationUrlRegexp;

View File

@@ -18,12 +18,9 @@ selftest.define("report-stats", function () {
selftest.expectEqual(!! identifier, true);
selftest.expectEqual(identifier.length > 0, true);
// verify that identifier file when running 'meteor bundle' on old
// apps
s.unlink(".meteor/identifier");
run = s.run("bundle", "foo.tar.gz");
run.waitSecs(30);
run.expectExit(0);
// verify that identifier file when running 'meteor bundle' on apps
// with no identifier file (eg pre-0.9.0 apps)
bundleWithFreshIdentifier(s);
identifier = s.read(".meteor/identifier");
selftest.expectEqual(!! identifier, true);
selftest.expectEqual(identifier.length > 0, true);
@@ -33,11 +30,33 @@ selftest.define("report-stats", function () {
var usage = fetchPackageUsageForApp(identifier);
selftest.expectEqual(usage.packages, stats.packageList(s.cwd));
// verify that the stats server recorded that with no userId
var appPackages = stats.getAppPackagesForAppIdInTest(s.cwd);
selftest.expectEqual(appPackages.appId, identifier);
selftest.expectEqual(appPackages.userId, null);
selftest.expectEqual(appPackages.packages, stats.packageList(s.cwd));
// now bundle again while logged in. verify that the stats server
// recorded that with the right userId
testUtils.login(s, "test", "testtest");
bundleWithFreshIdentifier(s);
appPackages = stats.getAppPackagesForAppIdInTest(s.cwd);
selftest.expectEqual(appPackages.userId, testUtils.getUserId(s));
// TODO:
// - test both the logged in state and the logged out state
// - opt out
});
// Bundle the app in the current working directory after deleting its
// identifier file (meaning a new one will be created).
// @param s {Sandbox}
var bundleWithFreshIdentifier = function (s) {
s.unlink(".meteor/identifier");
run = s.run("bundle", "foo.tar.gz");
run.waitSecs(30);
run.expectExit(0);
};
// Contact the package stats server and look for a given app
// identifier reported in the range (now - 30 minutes, now + 30
// minutes). Fails if packages for the same app was not recorded, or