|
|
|
@ -5,6 +5,7 @@ var async = require('async');
|
|
|
|
|
var path = require('path');
|
|
|
|
|
var nconf = require('nconf');
|
|
|
|
|
var request = require('request');
|
|
|
|
|
var jwt = require('jsonwebtoken');
|
|
|
|
|
|
|
|
|
|
var db = require('./mocks/databasemock');
|
|
|
|
|
var User = require('../src/user');
|
|
|
|
@ -1257,6 +1258,9 @@ describe('User', function () {
|
|
|
|
|
function (next) {
|
|
|
|
|
User.setSetting(uid, 'dailyDigestFreq', 'day', next);
|
|
|
|
|
},
|
|
|
|
|
function (next) {
|
|
|
|
|
User.setSetting(uid, 'notificationType_test', 'notificationemail', next);
|
|
|
|
|
},
|
|
|
|
|
], done);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -1273,6 +1277,110 @@ describe('User', function () {
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('unsubscribe via POST', function () {
|
|
|
|
|
it('should unsubscribe from digest if one-click unsubscribe is POSTed', function (done) {
|
|
|
|
|
const token = jwt.sign({
|
|
|
|
|
template: 'digest',
|
|
|
|
|
uid: uid,
|
|
|
|
|
}, nconf.get('secret'));
|
|
|
|
|
|
|
|
|
|
request({
|
|
|
|
|
method: 'post',
|
|
|
|
|
url: nconf.get('url') + '/email/unsubscribe/' + token,
|
|
|
|
|
}, function (err, res) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.strictEqual(res.statusCode, 200);
|
|
|
|
|
|
|
|
|
|
db.getObjectField('user:' + uid + ':settings', 'dailyDigestFreq', function (err, value) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.strictEqual(value, 'off');
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should unsubscribe from notifications if one-click unsubscribe is POSTed', function (done) {
|
|
|
|
|
const token = jwt.sign({
|
|
|
|
|
template: 'notification',
|
|
|
|
|
type: 'test',
|
|
|
|
|
uid: uid,
|
|
|
|
|
}, nconf.get('secret'));
|
|
|
|
|
|
|
|
|
|
request({
|
|
|
|
|
method: 'post',
|
|
|
|
|
url: nconf.get('url') + '/email/unsubscribe/' + token,
|
|
|
|
|
}, function (err, res) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.strictEqual(res.statusCode, 200);
|
|
|
|
|
|
|
|
|
|
db.getObjectField('user:' + uid + ':settings', 'notificationType_test', function (err, value) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.strictEqual(value, 'notification');
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should return errors on missing template in token', function (done) {
|
|
|
|
|
const token = jwt.sign({
|
|
|
|
|
uid: uid,
|
|
|
|
|
}, nconf.get('secret'));
|
|
|
|
|
|
|
|
|
|
request({
|
|
|
|
|
method: 'post',
|
|
|
|
|
url: nconf.get('url') + '/email/unsubscribe/' + token,
|
|
|
|
|
}, function (err, res) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.strictEqual(res.statusCode, 404);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should return errors on wrong template in token', function (done) {
|
|
|
|
|
const token = jwt.sign({
|
|
|
|
|
template: 'user',
|
|
|
|
|
uid: uid,
|
|
|
|
|
}, nconf.get('secret'));
|
|
|
|
|
|
|
|
|
|
request({
|
|
|
|
|
method: 'post',
|
|
|
|
|
url: nconf.get('url') + '/email/unsubscribe/' + token,
|
|
|
|
|
}, function (err, res) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.strictEqual(res.statusCode, 404);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should return errors on missing token', function (done) {
|
|
|
|
|
request({
|
|
|
|
|
method: 'post',
|
|
|
|
|
url: nconf.get('url') + '/email/unsubscribe/',
|
|
|
|
|
}, function (err, res) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.strictEqual(res.statusCode, 404);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should return errors on token signed with wrong secret (verify-failure)', function (done) {
|
|
|
|
|
const token = jwt.sign({
|
|
|
|
|
template: 'notification',
|
|
|
|
|
type: 'test',
|
|
|
|
|
uid: uid,
|
|
|
|
|
}, nconf.get('secret') + 'aababacaba');
|
|
|
|
|
|
|
|
|
|
request({
|
|
|
|
|
method: 'post',
|
|
|
|
|
url: nconf.get('url') + '/email/unsubscribe/' + token,
|
|
|
|
|
}, function (err, res) {
|
|
|
|
|
assert.ifError(err);
|
|
|
|
|
assert.strictEqual(res.statusCode, 403);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('socket methods', function () {
|
|
|
|
|