2015-01-24 14:50:56 +01:00
|
|
|
import Ember from "ember";
|
2015-04-02 20:09:07 +02:00
|
|
|
import { module, test } from 'qunit';
|
2015-01-24 14:50:56 +01:00
|
|
|
import startApp from '../helpers/start-app';
|
2015-07-27 20:28:00 +02:00
|
|
|
import Pretender from 'pretender';
|
2015-10-14 20:36:47 +02:00
|
|
|
import serverGetPolls from '../helpers/server-get-polls';
|
|
|
|
import serverPostUsers from '../helpers/server-post-users';
|
2015-07-27 20:28:00 +02:00
|
|
|
/* jshint proto: true */
|
2015-01-24 14:50:56 +01:00
|
|
|
|
2015-07-27 20:28:00 +02:00
|
|
|
var application, server;
|
|
|
|
|
|
|
|
module('Acceptance | participate in a poll', {
|
2015-04-02 20:09:07 +02:00
|
|
|
beforeEach: function() {
|
2015-07-27 20:28:00 +02:00
|
|
|
application = startApp();
|
2015-07-27 20:56:52 +02:00
|
|
|
application.__container__.lookup('adapter:application').__proto__.namespace = '';
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-07-27 20:28:00 +02:00
|
|
|
server = new Pretender();
|
2015-01-24 14:50:56 +01:00
|
|
|
},
|
2015-04-02 20:09:07 +02:00
|
|
|
afterEach: function() {
|
2015-07-27 20:28:00 +02:00
|
|
|
server.shutdown();
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-07-27 20:28:00 +02:00
|
|
|
Ember.run(application, 'destroy');
|
2015-01-24 14:50:56 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-07-27 20:28:00 +02:00
|
|
|
test("participate in a default poll", function(assert) {
|
|
|
|
var id = 'test',
|
|
|
|
encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-07-27 20:28:00 +02:00
|
|
|
server.get('/polls/' + id, function() {
|
2015-10-14 20:36:47 +02:00
|
|
|
return serverGetPolls(
|
2015-07-27 20:28:00 +02:00
|
|
|
{
|
|
|
|
id: id
|
|
|
|
}, encryptionKey
|
|
|
|
);
|
|
|
|
});
|
|
|
|
server.post('/users',
|
|
|
|
function (request) {
|
2015-10-14 20:36:47 +02:00
|
|
|
return serverPostUsers(request.requestBody, 1);
|
2015-07-27 20:28:00 +02:00
|
|
|
}
|
|
|
|
);
|
2015-01-24 17:14:57 +01:00
|
|
|
|
2015-07-27 20:28:00 +02:00
|
|
|
visit('/poll/' + id + '?encryptionKey=' + encryptionKey).then(function() {
|
2015-11-02 23:02:59 +01:00
|
|
|
assert.equal(currentPath(), 'poll.participation');
|
2015-10-18 14:04:04 +02:00
|
|
|
pollParticipate('Max Meiner', ['yes', 'no']);
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-01-24 14:50:56 +01:00
|
|
|
andThen(function(){
|
2015-11-02 23:02:59 +01:00
|
|
|
assert.equal(currentPath(), 'poll.evaluation');
|
2015-11-12 15:52:14 +01:00
|
|
|
assert.equal(
|
|
|
|
currentURL().split("?")[1],
|
|
|
|
'encryptionKey=' + encryptionKey,
|
|
|
|
'encryption key is part of query params'
|
|
|
|
);
|
2015-10-16 11:21:06 +02:00
|
|
|
pollHasUsersCount(assert, 1, "user is added to user selections table");
|
2015-10-18 14:04:04 +02:00
|
|
|
pollHasUser(assert, 'Max Meiner', [Ember.I18n.t('answerTypes.yes.label'), Ember.I18n.t('answerTypes.no.label')]);
|
2015-01-24 14:50:56 +01:00
|
|
|
});
|
|
|
|
});
|
2015-01-24 17:14:57 +01:00
|
|
|
});
|
2015-06-20 18:33:51 +02:00
|
|
|
|
|
|
|
test("participate in a poll using freetext", function(assert) {
|
2015-07-27 20:28:00 +02:00
|
|
|
var id = 'test2',
|
|
|
|
encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-07-27 20:28:00 +02:00
|
|
|
server.get('/polls/' + id,
|
|
|
|
function () {
|
2015-10-14 20:36:47 +02:00
|
|
|
return serverGetPolls(
|
2015-07-27 20:28:00 +02:00
|
|
|
{
|
|
|
|
id: id,
|
|
|
|
answerType: 'FreeText',
|
|
|
|
answers: []
|
|
|
|
}, encryptionKey
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
server.post('/users',
|
|
|
|
function (request) {
|
2015-10-14 20:36:47 +02:00
|
|
|
return serverPostUsers(request.requestBody, 1);
|
2015-07-27 20:28:00 +02:00
|
|
|
}
|
|
|
|
);
|
2015-06-20 18:33:51 +02:00
|
|
|
|
2015-07-27 20:28:00 +02:00
|
|
|
visit('/poll/' + id + '?encryptionKey=' + encryptionKey).then(function() {
|
2015-11-02 23:02:59 +01:00
|
|
|
assert.equal(currentPath(), 'poll.participation');
|
2015-10-18 14:04:04 +02:00
|
|
|
pollParticipate('Max Manus', ['answer 1', 'answer 2']);
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-06-20 18:33:51 +02:00
|
|
|
andThen(function(){
|
2015-11-02 23:02:59 +01:00
|
|
|
assert.equal(currentPath(), 'poll.evaluation');
|
2015-10-16 11:21:06 +02:00
|
|
|
pollHasUsersCount(assert, 1, "user is added to user selections table");
|
|
|
|
pollHasUser(assert, 'Max Manus', ['answer 1', 'answer 2']);
|
2015-06-20 18:33:51 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2015-07-01 16:21:18 +02:00
|
|
|
|
|
|
|
test("participate in a poll which doesn't force an answer to all options", function(assert) {
|
2015-07-27 20:28:00 +02:00
|
|
|
var id = 'test',
|
|
|
|
encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-07-27 20:28:00 +02:00
|
|
|
server.get('/polls/' + id,
|
|
|
|
function () {
|
2015-10-14 20:36:47 +02:00
|
|
|
return serverGetPolls(
|
2015-07-27 20:28:00 +02:00
|
|
|
{
|
|
|
|
id: id,
|
|
|
|
forceAnswer: false
|
|
|
|
}, encryptionKey
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
server.post('/users',
|
|
|
|
function (request) {
|
2015-10-14 20:36:47 +02:00
|
|
|
return serverPostUsers(request.requestBody, 1);
|
2015-07-27 20:28:00 +02:00
|
|
|
}
|
|
|
|
);
|
2015-07-01 16:21:18 +02:00
|
|
|
|
2015-07-27 20:28:00 +02:00
|
|
|
visit('/poll/' + id + '?encryptionKey=' + encryptionKey).then(function() {
|
2015-11-02 23:02:59 +01:00
|
|
|
assert.equal(currentPath(), 'poll.participation');
|
2015-10-18 14:04:04 +02:00
|
|
|
pollParticipate('Karl Käfer', ['yes', null]);
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-07-01 16:21:18 +02:00
|
|
|
andThen(function(){
|
2015-11-02 23:02:59 +01:00
|
|
|
assert.equal(currentPath(), 'poll.evaluation');
|
2015-10-16 11:21:06 +02:00
|
|
|
pollHasUsersCount(assert, 1, "user is added to user selections table");
|
|
|
|
pollHasUser(assert, "Karl Käfer", [Ember.I18n.t("answerTypes.yes.label"), ""]);
|
2015-07-01 16:21:18 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-07-27 20:28:00 +02:00
|
|
|
test("participate in a poll which allows anonymous participation", function(assert) {
|
|
|
|
var id = 'test',
|
|
|
|
encryptionKey = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-07-27 20:28:00 +02:00
|
|
|
server.get('/polls/' + id,
|
|
|
|
function () {
|
2015-10-14 20:36:47 +02:00
|
|
|
return serverGetPolls(
|
2015-07-27 20:28:00 +02:00
|
|
|
{
|
|
|
|
id: id,
|
|
|
|
anonymousUser: true
|
|
|
|
}, encryptionKey
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
server.post('/users',
|
|
|
|
function (request) {
|
2015-10-14 20:36:47 +02:00
|
|
|
return serverPostUsers(request.requestBody, 1);
|
2015-07-27 20:28:00 +02:00
|
|
|
}
|
|
|
|
);
|
2015-07-01 16:21:18 +02:00
|
|
|
|
2015-07-27 20:28:00 +02:00
|
|
|
visit('/poll/' + id + '?encryptionKey=' + encryptionKey).then(function() {
|
2015-11-02 23:02:59 +01:00
|
|
|
assert.equal(currentPath(), 'poll.participation');
|
2015-10-18 14:04:04 +02:00
|
|
|
pollParticipate(null, ['yes', 'no']);
|
2015-11-02 23:02:59 +01:00
|
|
|
|
2015-07-01 16:21:18 +02:00
|
|
|
andThen(function(){
|
2015-11-02 23:02:59 +01:00
|
|
|
assert.equal(currentPath(), 'poll.evaluation');
|
2015-10-16 11:21:06 +02:00
|
|
|
pollHasUsersCount(assert, 1, "user is added to user selections table");
|
|
|
|
pollHasUser(assert, "", [Ember.I18n.t("answerTypes.yes.label"), Ember.I18n.t("answerTypes.no.label")]);
|
2015-07-01 16:21:18 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|