test if invite mail gets sent to new user

This commit is contained in:
Girish Ramakrishnan 2016-06-23 16:41:07 -05:00
parent 359fcae054
commit 0412ca1f43
2 changed files with 26 additions and 2 deletions

View File

@ -31,6 +31,10 @@ function Cloudron(box) {
};
}
Cloudron.prototype.adminFqdn = function () {
return 'my' + (this._isCustomDomain ? '.' : '-') + this._box.domain;
};
Cloudron.prototype.appFqdn = function (location) {
return location + (this._isCustomDomain ? '.' : '-') + this._box.domain;
};
@ -327,7 +331,7 @@ Cloudron.prototype.waitForUpdate = function (toVersion) {
};
Cloudron.prototype.addUser = function (username, email) {
var res = request.post(this._origin + '/api/v1/users').query({ access_token: this._credentials.accessToken }).send({ username: username, email: email, invite: false }).end();
var res = request.post(this._origin + '/api/v1/users').query({ access_token: this._credentials.accessToken }).send({ username: username, email: email, invite: true }).end();
common.verifyResponse2xx(res, 'Could not add user');
return res.body;

View File

@ -8,7 +8,8 @@
var AppStore = require('../appstore.js'),
Cloudron = require('../cloudron.js'),
common = require('../common.js');
common = require('../common.js'),
ImapProbe = require('../imap-probe.js');
require('colors');
@ -24,6 +25,15 @@ describe('Cloudron user creation testing', function () {
var admin = common.getAdmin();
var cloudron, box, newUser;
var imap = new ImapProbe({
user: process.env.IMAP_USERNAME,
password: process.env.IMAP_PASSWORD,
host: process.env.IMAP_HOST,
port: 993, // imap port
tls: true,
readOnly: true
});
it('can login to the store', function () {
var accessToken = appStore.getAccessToken(owner);
appStore.setCredentials(owner.password, accessToken);
@ -56,6 +66,16 @@ describe('Cloudron user creation testing', function () {
newUser = cloudron.addUser('newuser', 'test+foo@cloudron.io');
});
it('did send invite mail to user', function (done) {
var url = 'https://' + cloudron.adminFqdn() + '/api/v1/session/account/setup.html?reset_token=' + newUser.resetToken;
var escapedUrl = url.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
imap.probe({
subject: new RegExp('Welcome to Cloudron ' + box.domain + '$'),
body: new RegExp(escapedUrl)
}, done);
});
it('can use reset token to reset password', function () {
cloudron.resetPassword(newUser.resetToken, 'Strong?132');
});