CreateSession: Add other required props

This commit is contained in:
Jonathon Wilson 2012-11-23 12:09:01 -07:00
parent a3748c941d
commit 54924bd322
6 changed files with 125 additions and 31 deletions

View File

@ -114,13 +114,15 @@ Message from Seth on sequence for creating/joining sessions:
}
var $this = $(this);
var data = $this.formToObject();
data.musician_access = Boolean(data.musician_access);
data.client_id = app.clientId;
if (typeof(data.genres) === "string") {
data.genres = [data.genres];
}
// FIXME: Hard-code tracks for now. Needs to be pickable
// FIXME: Hard-code tracks for now. Needs to default to:
// 1. If no previous session data, a single stereo track with the
// top instrument in the user's profile.
// 2. Otherwise, use the tracks from the last created session.
data.tracks = [
{ instrument_id: "electric guitar", sound: "mono" },
{ instrument_id: "keyboard", sound: "mono" }
@ -148,15 +150,15 @@ Message from Seth on sequence for creating/joining sessions:
contentType: 'application/json',
url: url,
processData:false,
data: JSON.stringify(data)
}).done(
function(response) {
data: JSON.stringify(data),
success: function(response) {
var newSessionId = response.id;
createInvitations(newSessionId, function() {
self.location = '#/session/' + newSessionId;
});
}
).fail(app.ajaxError);
},
error: app.ajaxError
});
return false;
}

View File

@ -84,7 +84,7 @@
* Generic error handler for Ajax calls.
*/
function ajaxError(jqXHR, textStatus, errorMessage) {
notify({title: textStatus, text: errorMessage, detail: jqXHR.responseText});
app.notify({title: textStatus, text: errorMessage, detail: jqXHR.responseText});
}
/**

View File

@ -455,8 +455,6 @@
this.initialize = function(inOpts) {
me = this;
opts = $.extend(opts, inOpts);
logger.error("layout.initialize.opts:");
logger.error(opts);
setup();
events();
};

View File

@ -19,14 +19,42 @@
</label>
</div>
-->
<div class="formrow">
<label>Fan Access
<fieldset>Musician Access
<label>
<input type="radio" name="fan_access"/>
<input type="radio" value="true" checked="checked" name="musician_access"/>
Public
</label>
<label>
<input type="radio" name="fan_access"/>
<input type="radio" value="false" name="musician_access"/>
Private
</label>
</fieldset>
</div>
<div class="formrow">
<fieldset>Musician Access Method
<label>
<input type="radio" value="true" name="approval_required"/>
By request/approval
</label>
<label>
<input type="radio" value="false" checked="checked" name="approval_required"/>
Open
</label>
</fieldset>
</div>
<div class="formrow">
<label>Fan Access
<label>
<input type="radio" value="true" checked="checked" name="fan_access"/>
Public
</label>
<label>
<input type="radio" value="false" name="fan_access"/>
Private
</label>
</label>
@ -35,26 +63,15 @@
<div class="formrow">
<label>Fan Chat
<label>
<input type="radio" name="fan_chat"/>
<input type="radio" value="true" checked="checked" name="fan_chat"/>
Yes
</label>
<label>
<input type="radio" name="fan_chat"/>
<input type="radio" value="false" name="fan_chat"/>
No
</label>
</label>
</div>
-->
<div class="formrow">
<fieldset>Musician Access
<label>By request/approval
<input type="radio" value="false" name="musician_access"/>
</label>
<label>Open
<input type="radio" value="true" checked="checked" name="musician_access"/>
</label>
</fieldset>
</div>
<div class="formrow">
<label>Genres

View File

@ -12,10 +12,17 @@
};
var selectors = {
form: '#create-session-form',
genres: '#create-session-form select[name="genres"]',
description: '#create-session-form textarea[name="description"]'
};
function makeValid() {
var genre = '<option selected="selected" value="1">1</option>';
$(selectors.genres).html(genre);
$(selectors.description).val('XYZ');
}
beforeEach(function() {
// Use the actual screen markup
jasmine.getFixtures().fixturesPath = '/app/views/clients';
@ -44,13 +51,62 @@
});
});
describe("submitForm", function() {
var fakeEvt = { preventDefault: $.noop };
var passedData = {};
beforeEach(function() {
makeValid();
spyOn($, "ajax").andCallFake(function(opts) {
opts.success(TestResponses.sessionPost);
});
css.submitForm.call($(selectors.form), fakeEvt);
passedData = JSON.parse($.ajax.mostRecentCall.args[0].data);
});
it("should pass client_id", function() {
expect(passedData.client_id).toEqual("12345");
});
it("should pass genres as non-empty list", function() {
expect("genres" in passedData).toBeTruthy();
var isArray = $.isArray(passedData.genres);
expect(isArray).toBeTruthy();
expect(passedData.genres.length).toBeGreaterThan(0);
});
it("should pass tracks as non-empty list", function() {
expect("tracks" in passedData).toBeTruthy();
var isArray = $.isArray(passedData.tracks);
expect(isArray).toBeTruthy();
expect(passedData.tracks.length).toBeGreaterThan(0);
});
it("should pass musician_access as boolean", function() {
expect("musician_access" in passedData).toBeTruthy();
expect(typeof(passedData.musician_access)).toEqual("boolean");
});
it("should pass approval_required as boolean", function() {
expect("approval_required" in passedData).toBeTruthy();
expect(typeof(passedData.approval_required)).toEqual("boolean");
});
it("should pass fan_access as boolean", function() {
expect("fan_access" in passedData).toBeTruthy();
expect(typeof(passedData.fan_access)).toEqual("boolean");
});
it("should pass fan_chat as boolean", function() {
expect("fan_chat" in passedData).toBeTruthy();
expect(typeof(passedData.fan_chat)).toEqual("boolean");
});
});
describe("validateForm", function() {
function makeValid() {
var genre = '<option selected="selected" value="1">1</option>';
$(selectors.genres).html(genre);
$(selectors.description).val('XYZ');
}
beforeEach(function() {
makeValid();

View File

@ -1,4 +1,25 @@
window.TestResponses = {
sessionPost: {
"id": "1234",
"description": "Hello",
"musician_access" : true,
"genres" : ['classical'],
"participants": [
{
"client_id": "0f8f7987-29a0-4e5d-a60c-6b23103e3533",
"ip_address":"1.1.1.1",
"user_id" : "02303020402042040", // NOTE THIS WILL BE UNDEFINED (ABSENT) IF THIS CLIENT IS NOT YOUR FRIEND
"tracks" : [
{
"id" : "xxxx",
"instrument_id" : "electric guitar",
"sound" : "mono"
}
]
}
]
},
loadGenres: [
{
id: "african",