Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename variable and function names and add functional tests for booking workflows #131

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cache:
- $HOME/.cache/pip
before_script:
- sudo -- sh -c "echo '127.0.0.1 boxoffice.travis.dev' >> /etc/hosts"
- sudo -- sh -c "echo '127.0.0.1 testing.travis.dev' >> /etc/hosts"
- psql -c 'create database boxoffice_testing;' -U postgres
install:
- pip install -U pip wheel
Expand All @@ -16,7 +17,11 @@ install:
script:
- nosetests -v tests
- nohup python runtestserver.py &
- sleep 10
- cd tests
- python -m SimpleHTTPServer 8000 &
- cd ..
- sleep 30
- casperjs test tests
addons:
postgresql: "9.4"
services:
Expand Down
32 changes: 16 additions & 16 deletions boxoffice/static/js/dist/bundle.js

Large diffs are not rendered by default.

87 changes: 42 additions & 45 deletions boxoffice/static/js/views/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ window.Boxoffice.Order = {
},
assign: {
method: 'POST',
urlFor: function(access_token) {
return Boxoffice.Order.config.baseURL + '/participant/' + access_token + '/assign';
urlFor: function(accessToken) {
return Boxoffice.Order.config.baseURL + '/participant/' + accessToken + '/assign';
}
}
},
Expand Down Expand Up @@ -51,46 +51,43 @@ window.Boxoffice.Order = {
},
view: function(data) {
var order = this;
order.ractive = new Ractive({
order.component = new Ractive({
el: '#boxoffice-order',
template: '#boxoffice-ticket-template',
data: {
order_id: data.order_id,
access_token: data.access_token,
orderId: data.order_id,
accessToken: data.access_token,
eventName: data.item_collection_name,
line_items: data.line_items,
buyer_name: data.buyer_name,
buyer_email: data.buyer_email,
buyer_phone: data.buyer_phone
lineItems: data.line_items
},
scrollTop: function(line_item_seq){
scrollTop: function(lineItemSeq){
//Scroll to the corresponding line_item.
var domElem = order.ractive.nodes[ 'item-' + line_item_seq ];
var domElem = order.component.nodes[ 'item-' + lineItemSeq ];
$('html,body').animate({ scrollTop: $(domElem).offset().top }, '300');
},
viewTicket: function(event, line_item, line_item_seq) {
viewTicket: function(event, lineItem, lineItemSeq) {
event.original.preventDefault();
order.ractive.set(line_item + '.toAssign', false);
order.ractive.scrollTop(line_item_seq);
order.component.set(lineItem + '.toAssign', false);
order.component.scrollTop(lineItemSeq);
},
inputFieldEdit: function(event, line_item) {
inputFieldEdit: function(event, lineItem) {
if (event.node.value) {
event.node.classList.add('filled');
}
else {
event.node.classList.remove('filled');
}
},
assign: function(event, line_item, edit) {
assign: function(event, lineItem, edit) {
event.original.preventDefault();
if (!edit) {
order.ractive.set(line_item + '.assignee.fullname', "");
order.ractive.set(line_item + '.assignee.email', "");
order.ractive.set(line_item + '.assignee.phone', "+91");
order.component.set(lineItem + '.assignee.fullname', "");
order.component.set(lineItem + '.assignee.email', "");
order.component.set(lineItem + '.assignee.phone', "+91");
}
order.ractive.set(line_item + '.toAssign', true);
order.component.set(lineItem + '.toAssign', true);
},
addAttendeeDetails: function(event, line_item, line_item_seq, line_item_id) {
addAssigneeDetails: function(event, lineItem, lineItemSeq, lineItemId) {

var validationConfig = [{
name: 'fullname',
Expand All @@ -106,18 +103,18 @@ window.Boxoffice.Order = {
}
];

var attendeeForm = 'attendee-form-' + line_item_seq;
var assigneeForm = 'assignee-form-' + lineItemSeq;

var formValidator = new FormValidator(attendeeForm, validationConfig, function(errors, event) {
var formValidator = new FormValidator(assigneeForm, validationConfig, function(errors, event) {
event.preventDefault();
order.ractive.set(line_item + '.assignee.errormsg', '');
order.component.set(lineItem + '.assignee.errormsg', '');
if (errors.length > 0) {
order.ractive.set(line_item + '.assignee.errormsg.'+ errors[0].name, errors[0].message);
order.ractive.scrollTop(line_item_seq);
order.component.set(lineItem + '.assignee.errormsg.'+ errors[0].name, errors[0].message);
order.component.scrollTop(lineItemSeq);
}
else {
order.ractive.set(line_item + '.assigningTicket', true);
order.ractive.sendAttendeeDetails(line_item, line_item_seq, line_item_id);
order.component.set(lineItem + '.assigningTicket', true);
order.component.sendAssigneeDetails(lineItem, lineItemSeq, lineItemId);
}
});

Expand All @@ -127,7 +124,7 @@ window.Boxoffice.Order = {
formValidator.registerCallback('validate_phone', function(phone) {
//Remove all punctations (except +) and letters
phone = phone.replace(/[^0-9+]/g,'');
order.ractive.set(line_item + '.assignee.phone', phone);
order.component.set(lineItem + '.assignee.phone', phone);

var validPhone = /^\+[0-9]+$/;

Expand All @@ -148,43 +145,43 @@ window.Boxoffice.Order = {
}
});
},
sendAttendeeDetails: function(line_item, line_item_seq, line_item_id) {
var attendeeForm = 'attendee-details-' + line_item_seq;
var formElements = $('#'+ attendeeForm).serializeArray();
var attendeeDetails ={};
sendAssigneeDetails: function(lineItem, lineItemSeq, lineItemId) {
var assigneeForm = 'assignee-details-' + lineItemSeq;
var formElements = $('#'+ assigneeForm).serializeArray();
var assigneeDetails ={};
for (var formIndex=0; formIndex < formElements.length; formIndex++) {
if (formElements[formIndex].value) {
attendeeDetails[formElements[formIndex].name] = formElements[formIndex].value;
assigneeDetails[formElements[formIndex].name] = formElements[formIndex].value;
}
}

$.ajax({
url: Boxoffice.Order.config.assign.urlFor(order.ractive.get('access_token')),
url: Boxoffice.Order.config.assign.urlFor(order.component.get('accessToken')),
type: Boxoffice.Order.config.assign.method,
contentType: 'application/json',
data: JSON.stringify({
attendee: attendeeDetails,
line_item_id: line_item_id
assignee: assigneeDetails,
line_item_id: lineItemId
}),
timeout: 30000,
retries: 5,
retryInterval: 30000,
success: function(data) {
order.ractive.set(line_item + '.assigningTicket', false);
order.ractive.set(line_item + '.toAssign', false);
order.ractive.set(line_item + '.isTicketAssigned', true);
order.ractive.scrollTop(line_item_seq);
order.component.set(lineItem + '.assigningTicket', false);
order.component.set(lineItem + '.toAssign', false);
order.component.set(lineItem + '.isTicketAssigned', true);
order.component.scrollTop(lineItemSeq);
},
error: function(response) {
var ajaxLoad = this;
ajaxLoad.retries -= 1;
if (response.readyState === 4) {
order.ractive.set(line_item + '.errorMsg', 'Server error');
order.ractive.set(line_item + '.assigningTicket', false);
order.component.set(lineItem + '.errorMsg', 'Server error');
order.component.set(lineItem + '.assigningTicket', false);
} else if (response.readyState === 0) {
if (ajaxLoad.retries < 0) {
order.ractive.set(line_item + '.errorMsg', "Unable to connect. Please try again later.");
order.ractive.set(line_item + '.assigningTicket', false);
order.component.set(lineItem + '.errorMsg', "Unable to connect. Please try again later.");
order.component.set(lineItem + '.assigningTicket', false);
} else {
setTimeout(function() {
$.ajax(ajaxLoad);
Expand Down
Loading