PageRenderTime 7ms CodeModel.GetById 2ms app.highlight 73ms RepoModel.GetById 1ms app.codeStats 0ms

/js/amplify-1.1.0/src/request/test/unit.js

https://bitbucket.org/dreamfactory/web-core
JavaScript | 1375 lines | 1249 code | 99 blank | 27 comment | 11 complexity | 97d5db5dd2ed883dbf5b4844f6966aa6 MD5 | raw file
   1(function() {
   2
   3var subscriptions = {};
   4function subscribe( topic, callback ) {
   5	subscriptions[ topic ] = subscriptions[ topic ] || [];
   6	subscriptions[ topic ].push( callback );
   7	return amplify.subscribe( topic, callback );
   8}
   9
  10var ajax = $.ajax;
  11var lifecycle = {
  12	setup: function() {
  13		amplify.request.resources = {};
  14	},
  15	teardown: function() {
  16		$.ajax = ajax;
  17		$.each( subscriptions, function( topic, callbacks ) {
  18			$.each( callbacks, function( _,callback ) {
  19				amplify.unsubscribe( topic, callback );
  20			});
  21		});
  22	}
  23};
  24
  25module( "amplify.request", lifecycle );
  26
  27test( "invalid resource id", function() {
  28	expect( 4 );
  29
  30	subscribe( "request.before", function() {
  31		ok( false, "no messages should be published for invalid resources" );
  32	});
  33
  34	try {
  35		amplify.request();
  36		ok( false, "should throw error with no resrouceId" );
  37	} catch( e ) {
  38		equal( e, "amplify.request: no resourceId provided" );
  39	}
  40
  41	try {
  42		amplify.request( "missing" );
  43		ok( false, "should throw error with invalid resourceId" );
  44	} catch ( e ) {
  45		equal( e, "amplify.request: unknown resourceId: missing" );
  46	}
  47
  48	try {
  49		amplify.request({ data: { foo: "bar" } });
  50		ok( false, "should throw error with invalid resourceId" );
  51	} catch ( e ) {
  52		equal( e, "amplify.request: no resourceId provided" );
  53	}
  54
  55	try {
  56		amplify.request({ resourceId: "missing" });
  57		ok( false, "should throw error with invalid resourceId" );
  58	} catch ( e ) {
  59		equal( e, "amplify.request: unknown resourceId: missing" );
  60	}
  61});
  62
  63module( "amplify.request.define - fn", lifecycle );
  64
  65asyncTest( "request( id )", function() {
  66	expect( 11 );
  67
  68	amplify.request.define( "test", function( settings ) {
  69		equal( settings.resourceId, "test", "defintion: resouceId" );
  70		deepEqual( settings.data, {}, "definition: data" );
  71		settings.success({ simple: true });
  72	});
  73	subscribe( "request.before", function( settings ) {
  74		equal( settings.resourceId, "test", "before message: settings.resourceId" );
  75	});
  76	subscribe( "request.success", function( settings, data, status ) {
  77		equal( settings.resourceId, "test", "success message: settings.resrouceId" );
  78		deepEqual( settings.data, {},
  79			"success message: settings.data" );
  80		deepEqual( data, { simple: true }, "success message: data" );
  81		equal( status, "success", "success message: status" );
  82	});
  83	subscribe( "request.complete", function( settings, data, status ) {
  84		equal( settings.resourceId, "test", "complete message: settings.resrouceId" );
  85		deepEqual( settings.data, {},
  86			"complete message: settings.data" );
  87		deepEqual( data, { simple: true }, "complete message: data" );
  88		equal( status, "success", "complete message: status" );
  89		start();
  90	});
  91	subscribe( "request.error", function() {
  92		ok( false, "error message published" );
  93	});
  94	amplify.request( "test" );
  95});
  96
  97asyncTest( "request( id, fn )", function() {
  98	expect( 13 );
  99
 100	amplify.request.define( "test", function( settings ) {
 101		equal( settings.resourceId, "test", "defintion: resouceId" );
 102		deepEqual( settings.data, {}, "definition: data" );
 103		settings.success({ simple: true });
 104	});
 105	subscribe( "request.before", function( settings ) {
 106		equal( settings.resourceId, "test", "before message: settings.resourceId" );
 107	});
 108	subscribe( "request.success", function( settings, data, status ) {
 109		equal( settings.resourceId, "test", "success message: settings.resrouceId" );
 110		deepEqual( settings.data, {},
 111			"success message: settings.data" );
 112		deepEqual( data, { simple: true }, "success message: data" );
 113		equal( status, "success", "success message: status" );
 114	});
 115	subscribe( "request.complete", function( settings, data, status ) {
 116		equal( settings.resourceId, "test", "complete message: settings.resrouceId" );
 117		deepEqual( settings.data, {},
 118			"complete message: settings.data" );
 119		deepEqual( data, { simple: true }, "complete message: data" );
 120		equal( status, "success", "complete message: status" );
 121		start();
 122	});
 123	subscribe( "request.error", function() {
 124		ok( false, "error message published" );
 125	});
 126	amplify.request( "test", function( data, status ) {
 127		deepEqual( data, { simple: true }, "success callback: data" );
 128		equal( status, "success", "success callback: status" );
 129	});
 130});
 131
 132asyncTest( "request( id, data, fn )", function() {
 133	expect( 13 );
 134
 135	amplify.request.define( "test", function( settings ) {
 136		equal( settings.resourceId, "test", "defintion: resouceId" );
 137		deepEqual( settings.data, { foo: "bar", baz: 1 }, "definition: data" );
 138		settings.success({ simple: true });
 139	});
 140	subscribe( "request.before", function( settings ) {
 141		equal( settings.resourceId, "test", "before message: settings.resourceId" );
 142	});
 143	subscribe( "request.success", function( settings, data, status ) {
 144		equal( settings.resourceId, "test", "success message: settings.resrouceId" );
 145		deepEqual( settings.data, { foo: "bar", baz: 1 },
 146			"success message: settings.data" );
 147		deepEqual( data, { simple: true }, "success message: data" );
 148		equal( status, "success", "success message: status" );
 149	});
 150	subscribe( "request.complete", function( settings, data, status ) {
 151		equal( settings.resourceId, "test", "complete message: settings.resrouceId" );
 152		deepEqual( settings.data, { foo: "bar", baz: 1 },
 153			"complete message: settings.data" );
 154		deepEqual( data, { simple: true }, "complete message: data" );
 155		equal( status, "success", "complete message: status" );
 156		start();
 157	});
 158	subscribe( "request.error", function() {
 159		ok( false, "error message published" );
 160	});
 161	amplify.request( "test", { foo: "bar", baz: 1 }, function( data, status ) {
 162		deepEqual( data, { simple: true }, "success callback: data" );
 163		equal( status, "success", "success callback: status" );
 164	});
 165});
 166
 167asyncTest( "request( hash ) success", function() {
 168	expect( 13 );
 169
 170	amplify.request.define( "test", function( settings ) {
 171		equal( settings.resourceId, "test", "defintion: resouceId" );
 172		deepEqual( settings.data, { foo: "bar", baz: 1 }, "definition: data" );
 173		settings.success({ simple: true });
 174	});
 175	subscribe( "request.before", function( settings ) {
 176		equal( settings.resourceId, "test", "before message: settings.resourceId" );
 177	});
 178	subscribe( "request.success", function( settings, data, status ) {
 179		equal( settings.resourceId, "test", "success message: settings.resrouceId" );
 180		deepEqual( settings.data, { foo: "bar", baz: 1 },
 181			"success message: settings.data" );
 182		deepEqual( data, { simple: true }, "success message: data" );
 183		equal( status, "success", "success message: status" );
 184	});
 185	subscribe( "request.complete", function( settings, data, status ) {
 186		equal( settings.resourceId, "test", "complete message: settings.resrouceId" );
 187		deepEqual( settings.data, { foo: "bar", baz: 1 },
 188			"complete message: settings.data" );
 189		deepEqual( data, { simple: true }, "complete message: data" );
 190		equal( status, "success", "complete message: status" );
 191		start();
 192	});
 193	subscribe( "request.error", function() {
 194		ok( false, "error message published" );
 195	});
 196	amplify.request({
 197		resourceId: "test",
 198		data: { foo: "bar", baz: 1 },
 199		success: function( data, status ) {
 200			deepEqual( data, { simple: true }, "success callback: data" );
 201			equal( status, "success", "success callback: status" );
 202		}
 203	});
 204});
 205
 206asyncTest( "request( hash ) error", function() {
 207	expect( 13 );
 208
 209	amplify.request.define( "test", function( settings ) {
 210		equal( settings.resourceId, "test", "defintion: resouceId" );
 211		deepEqual( settings.data, { foo: "bar", baz: 1 }, "definition: data" );
 212		settings.error({ simple: true });
 213	});
 214	subscribe( "request.before", function( settings ) {
 215		equal( settings.resourceId, "test", "before message: settings.resourceId" );
 216	});
 217	subscribe( "request.error", function( settings, data, status ) {
 218		equal( settings.resourceId, "test", "error message: settings.resrouceId" );
 219		deepEqual( settings.data, { foo: "bar", baz: 1 },
 220			"error message: settings.data" );
 221		deepEqual( data, { simple: true }, "error message: data" );
 222		equal( status, "error", "error message: status" );
 223	});
 224	subscribe( "request.complete", function( settings, data, status ) {
 225		equal( settings.resourceId, "test", "complete message: settings.resrouceId" );
 226		deepEqual( settings.data, { foo: "bar", baz: 1 },
 227			"complete message: settings.data" );
 228		deepEqual( data, { simple: true }, "complete message: data" );
 229		equal( status, "error", "complete message: status" );
 230		start();
 231	});
 232	subscribe( "request.success", function() {
 233		ok( false, "success message published" );
 234	});
 235	amplify.request({
 236		resourceId: "test",
 237		data: { foo: "bar", baz: 1 },
 238		success: function() {
 239			ok( false, "success callback invoked" );
 240		},
 241		error: function( data, status ) {
 242			deepEqual( data, { simple: true }, "error callback: data" );
 243			equal( status, "error", "error callback: status" );
 244		}
 245	});
 246});
 247
 248asyncTest( "custom status - success", function() {
 249	expect( 6 );
 250
 251	amplify.request.define( "test", function( settings ) {
 252		settings.success( { data: "is good" }, "custom status" );
 253	});
 254	subscribe( "request.success", function( settings, data, status ) {
 255		deepEqual( data, { data: "is good" }, "success message: data " );
 256		equal( status, "custom status", "success message: status" );
 257	});
 258	subscribe( "request.complete", function( settings, data, status ) {
 259		deepEqual( data, { data: "is good" }, "complete message: data " );
 260		equal( status, "custom status", "complete message: status" );
 261		start();
 262	});
 263
 264	amplify.request( "test", function( data, status ) {
 265		deepEqual( data, { data: "is good" }, "success callback: data " );
 266		equal( status, "custom status", "success callback: status" );
 267	});
 268});
 269
 270asyncTest( "custom status - error", function() {
 271	expect( 6 );
 272
 273	amplify.request.define( "test", function( settings ) {
 274		settings.error( { data: "is bad" }, "custom error" );
 275	});
 276	subscribe( "request.error", function( settings, data, status ) {
 277		deepEqual( data, { data: "is bad" }, "error message: data " );
 278		equal( status, "custom error", "error message: status" );
 279	});
 280	subscribe( "request.complete", function( settings, data, status ) {
 281		deepEqual( data, { data: "is bad" }, "complete message: data " );
 282		equal( status, "custom error", "complete message: status" );
 283		start();
 284	});
 285
 286	amplify.request({
 287		resourceId: "test",
 288		error: function( data, status ) {
 289			deepEqual( data, { data: "is bad" }, "error callback: data " );
 290			equal( status, "custom error", "error callback: status" );
 291		}
 292	});
 293});
 294
 295asyncTest( "prevent request", function() {
 296	expect( 3 );
 297
 298	amplify.request.define( "test", function( settings ) {
 299		deepEqual( settings.data, { pass: true }, "request occurred" );
 300		start();
 301	});
 302	subscribe( "request.before", function( settings ) {
 303		ok( true, "message published" );
 304		return settings.data.pass;
 305	});
 306	amplify.request( "test", { pass: false } );
 307	amplify.request( "test", { pass: true } );
 308});
 309
 310module( "amplify.request.define - ajax", lifecycle );
 311
 312asyncTest( "request( id )", function() {
 313	expect( 23 );
 314
 315	var ajax = $.ajax;
 316	$.ajax = function( settings ) {
 317		equal( settings.url, "data/data.json", "correct url" );
 318		equal( settings.dataType, "json", "correct dataType" );
 319		equal( settings.type, "GET", "default type" );
 320		ajax.apply( this, arguments );
 321	};
 322	amplify.request.define( "test", "ajax", {
 323		url: "data/data.json",
 324		dataType: "json"
 325	});
 326	subscribe( "request.before", function( settings ) {
 327		equal( settings.resourceId, "test", "before message: settings.resourceId" );
 328		deepEqual( settings.data, {}, "before message: settings.data" );
 329	});
 330	subscribe( "request.before.ajax", function( resource, settings, ajaxSettings, xhr ) {
 331		equal( resource.resourceId, "test", "before.ajax message: resource.resourceId" );
 332		equal( resource.url, "data/data.json", "before.ajax message: resource.url" );
 333		equal( resource.dataType, "json", "before.ajax message: resource.dataType" );
 334		equal( resource.type, "GET", "before.ajax message: resource.type" );
 335		equal( settings.resourceId, "test", "before.ajax message: settings.resourceId" );
 336		deepEqual( settings.data, {}, "before.ajax message: settings.data" );
 337		equal( ajaxSettings.url, "data/data.json", "before.ajax message: ajaxSettings.url" );
 338		equal( ajaxSettings.dataType, "json", "before.ajax message: ajaxSettings.dataType" );
 339		equal( ajaxSettings.type, "GET", "before.ajax message: ajaxSettings.type" );
 340		ok( "abort" in xhr, "before.ajax message: xhr object provided" );
 341	});
 342	subscribe( "request.success", function( settings, data, status ) {
 343		equal( settings.resourceId, "test", "success message: settings.resrouceId" );
 344		deepEqual( settings.data, {}, "success message: settings.data" );
 345		deepEqual( data, { foo: "bar" }, "success message: data" );
 346		equal( status, "success", "success message: status" );
 347	});
 348	subscribe( "request.complete", function( settings, data, status ) {
 349		equal( settings.resourceId, "test", "complete message: settings.resrouceId" );
 350		deepEqual( settings.data, {}, "complete message: settings.data" );
 351		deepEqual( data, { foo: "bar" }, "complete message: data" );
 352		equal( status, "success", "complete message: status" );
 353		start();
 354	});
 355	subscribe( "request.error", function() {
 356		ok( false, "error message published" );
 357	});
 358	amplify.request( "test" );
 359});
 360
 361asyncTest( "request( id, fn )", function() {
 362	expect( 10 );
 363
 364	amplify.request.define( "test", "ajax", {
 365		url: "data/data.json",
 366		dataType: "json"
 367	});
 368	subscribe( "request.success", function( settings, data, status ) {
 369		equal( settings.resourceId, "test", "success message: settings.resrouceId" );
 370		deepEqual( settings.data, {}, "success message: settings.data" );
 371		deepEqual( data, { foo: "bar" }, "success message: data" );
 372		equal( status, "success", "success message: status" );
 373	});
 374	subscribe( "request.complete", function( settings, data, status ) {
 375		equal( settings.resourceId, "test", "complete message: settings.resrouceId" );
 376		deepEqual( settings.data, {}, "complete message: settings.data" );
 377		deepEqual( data, { foo: "bar" }, "complete message: data" );
 378		equal( status, "success", "complete message: status" );
 379		start();
 380	});
 381	amplify.request( "test", function( data, status ) {
 382		deepEqual( data, { foo: "bar" }, "success callback: data" );
 383		equal( status, "success", "success callback: status" );
 384	});
 385});
 386
 387asyncTest( "request( id, data, fn )", function() {
 388	expect( 10 );
 389	
 390	amplify.request.define( "test", "ajax", {
 391		url: "data/echo.php",
 392		dataType: "json",
 393		type: "POST"
 394	});
 395	subscribe( "request.success", function( settings, data, status ) {
 396		equal( settings.resourceId, "test", "success message: settings.resrouceId" );
 397		deepEqual( settings.data, { open: "source" }, "success message: settings.data" );
 398		deepEqual( data, { open: "source", echoed: true }, "success message: data" );
 399		equal( status, "success", "success message: status" );
 400	});
 401	subscribe( "request.complete", function( settings, data, status ) {
 402		equal( settings.resourceId, "test", "complete message: settings.resrouceId" );
 403		deepEqual( settings.data, { open: "source" }, "complete message: settings.data" );
 404		deepEqual( data, { open: "source", echoed: true }, "complete message: data" );
 405		equal( status, "success", "complete message: status" );
 406		start();
 407	});
 408	amplify.request( "test", { open: "source" }, function( data, status ) {
 409		deepEqual( data, { open: "source", echoed: true }, "success callback: data" );
 410		equal( status, "success", "success callback: status" );
 411	});
 412});
 413
 414asyncTest( "request( hash ) success", function() {
 415	expect( 8 );
 416
 417	amplify.request.define( "test", "ajax", {
 418		url: "data/data.json",
 419		dataType: "json"
 420	});
 421	subscribe( "request.success", function( settings, data, status ) {
 422		equal( settings.resourceId, "test", "success message: settings.resrouceId" );
 423		deepEqual( data, { foo: "bar" }, "success message: data" );
 424		equal( status, "success", "success message: status" );
 425	});
 426	subscribe( "request.complete", function( settings, data, status ) {
 427		equal( settings.resourceId, "test", "complete message: settings.resrouceId" );
 428		deepEqual( data, { foo: "bar" }, "complete message: data" );
 429		equal( status, "success", "complete message: status" );
 430		start();
 431	});
 432	subscribe( "request.error", function() {
 433		ok( false, "error message published" );
 434	});
 435	amplify.request({
 436		resourceId: "test",
 437		success: function( data, status ) {
 438			deepEqual( data, { foo: "bar" }, "success callback: data" );
 439			equal( status, "success", "success callback: status" );
 440		},
 441		error: function() {
 442			ok( false, "error callback invoked" );
 443		}
 444	});
 445});
 446
 447asyncTest( "request( hash ) error", function() {
 448	expect( 8 );
 449
 450	amplify.request.define( "test", "ajax", {
 451		url: "data/missing.html",
 452		dataType: "json"
 453	});
 454	subscribe( "request.error", function( settings, data, status ) {
 455		equal( settings.resourceId, "test", "error message: settings.resrouceId" );
 456		deepEqual( data, null, "error message: data" );
 457		equal( status, "error", "error message: status" );
 458	});
 459	subscribe( "request.complete", function( settings, data, status ) {
 460		equal( settings.resourceId, "test", "complete message: settings.resrouceId" );
 461		deepEqual( data, null, "complete message: data" );
 462		equal( status, "error", "complete message: status" );
 463		start();
 464	});
 465	subscribe( "request.success", function() {
 466		ok( false, "success message published" );
 467	});
 468	amplify.request({
 469		resourceId: "test",
 470		error: function( data, status ) {
 471			deepEqual( data, null, "error callback: data" );
 472			equal( status, "error", "error callback: status" );
 473		},
 474		success: function() {
 475			ok( false, "success callback invoked" );
 476		}
 477	});
 478});
 479
 480asyncTest( "prevent request - beforeSend", function() {
 481	expect( 10 );
 482
 483	amplify.request.define( "test", "ajax", {
 484		url: "data/data.json",
 485		dataType: "json",
 486		// should execute 2 times
 487		beforeSend: function( xhr, settings ) {
 488			ok( "abort" in xhr, "xhr object provided" );
 489			equal( settings.url.substring( 0, 20 ), "data/data.json?pass=", "correct url" );
 490			equal( settings.dataType, "json", "correct dataType" );
 491			return settings.url.substring( settings.url.length - 4 ) === "true";
 492		}
 493	});
 494	// should execute 2 times
 495	subscribe( "request.before", function( settings ) {
 496		ok( true, "before message published" );
 497	});
 498	// should execute 1 time
 499	subscribe( "request.before.ajax", function( settings ) {
 500		ok( true, "before.ajax message published" );
 501	});
 502	// should execute 1 time
 503	subscribe( "request.complete", function( settings ) {
 504		ok( settings.data.pass, "request completed" );
 505		start();
 506	});
 507	amplify.request( "test", { pass: false } );
 508	amplify.request( "test", { pass: true } );
 509});
 510
 511asyncTest( "prevent request - request.before", function() {
 512	expect( 4 );
 513
 514	amplify.request.define( "test", "ajax", {
 515		url: "data/data.json",
 516		dataType: "json"
 517	});
 518	subscribe( "request.before", function( settings ) {
 519		ok( true, "message published" );
 520		return settings.data.pass;
 521	});
 522	subscribe( "request.complete", function( settings, data, status ) {
 523		if ( !settings.data.pass ) {
 524			equal( status, "abort", "aborted" );
 525		} else {
 526			equal( status, "success", "successful" );
 527			start();
 528		}
 529	});
 530	amplify.request( "test", { pass: false } );
 531	amplify.request( "test", { pass: true } );
 532});
 533
 534asyncTest( "prevent request - request.before.ajax", function() {
 535	expect( 3 );
 536	
 537	amplify.request.define( "test", "ajax", {
 538		url: "data/data.json",
 539		dataType: "json"
 540	});
 541	subscribe( "request.before.ajax", function( resouce, settings ) {
 542		ok( true, "message published" );
 543		return settings.data.pass;
 544	});
 545	subscribe( "request.complete", function( settings, data, status ) {
 546		if ( !settings.data.pass ) {
 547			equal( status, "abort", "aborted" );
 548		} else {
 549			equal( status, "success", "successful" );
 550			start();
 551		}
 552	});
 553	amplify.request( "test", { pass: false } );
 554	amplify.request( "test", { pass: true } );
 555});
 556
 557test( "data merging", function() {
 558	expect( 3 );
 559
 560	$.ajax = function( settings ) {
 561		deepEqual( settings.data, {
 562			foo: "bar",
 563			bar: "baz",
 564			baz: "qux"
 565		}, "default data passed through" );
 566	};
 567	amplify.request.define( "test", "ajax", {
 568		url: "",
 569		data: {
 570			foo: "bar",
 571			bar: "baz",
 572			baz: "qux"
 573		}
 574	});
 575	amplify.request( "test" );
 576	amplify.request( "test", {} );
 577
 578	$.ajax = function( settings ) {
 579		deepEqual( settings.data, {
 580			foo: "changed",
 581			bar: "baz",
 582			baz: {
 583				qux: "remains",
 584				quux: "is changed"
 585			}
 586		}, "data merged" );
 587	};
 588	amplify.request.define( "test", "ajax", {
 589		url: "",
 590		data: {
 591			foo: "bar",
 592			bar: "baz",
 593			baz: {
 594				qux: "remains",
 595				quux: "changes"
 596			}
 597		}
 598	});
 599	amplify.request( "test", {
 600		foo: "changed",
 601		baz: {
 602			quux: "is changed"
 603		}
 604	});
 605});
 606
 607test( "url substitution", function() {
 608	expect( 7 );
 609
 610	$.ajax = function( settings ) {
 611		equal( settings.url, "/path/bar", "url" );
 612		deepEqual( settings.data, {}, "data" );
 613	};
 614	amplify.request.define( "test", "ajax", {
 615		url: "/path/{foo}",
 616		data: {
 617			foo: "bar"
 618		}
 619	});
 620	amplify.request( "test" );
 621
 622	$.ajax = function( settings ) {
 623		equal( settings.url, "/path/qux", "url" );
 624		deepEqual( settings.data, {}, "data" );
 625	};
 626	amplify.request( "test", { foo: "qux" } );
 627
 628	$.ajax = function( settings ) {
 629		equal( settings.url, "/path/bar", "url" );
 630		deepEqual( settings.data, { qux: "quux" }, "data" );
 631	};
 632	amplify.request( "test", { qux: "quux" } );
 633
 634	$.ajax = function( settings ) {
 635		equal( settings.url, "/a/bar/b/bar", "url" );
 636	};
 637	amplify.request.define( "test", "ajax", {
 638		url: "/a/{foo}/b/{foo}"
 639	});
 640	amplify.request( "test", { foo: "bar" } );
 641});
 642
 643asyncTest( "data as string", function() {
 644	expect( 1 );
 645
 646	amplify.request.define( "test", "ajax", {
 647		url: "data/echo-raw.php",
 648		type: "POST"
 649	});
 650	amplify.request( "test", "sending {raw} [data]", function( data ) {
 651		equal( data, "sending {raw} [data]" );
 652		start();
 653	});
 654});
 655
 656test( "dataMap: hash", function() {
 657	expect( 1 );
 658
 659	$.ajax = function( settings ) {
 660		deepEqual( settings.data, {
 661			sillyNameForFoo: "foo val",
 662			bar: "bar val"
 663		}, "keys mapped" );
 664	};
 665	amplify.request.define( "test", "ajax", {
 666		url: "",
 667		dataMap: {
 668			foo: "sillyNameForFoo",
 669			baz: "sillyNameForBaz"
 670		}
 671	});
 672	amplify.request( "test", {
 673		foo: "foo val",
 674		bar: "bar val"
 675	});
 676});
 677
 678test( "dataMap: function", function() {
 679	expect( 2 );
 680
 681	$.ajax = function( settings ) {
 682		deepEqual( settings.data, {
 683			foo: "bar",
 684			baz: "qux"
 685		}, "keys mapped" );
 686	};
 687	amplify.request.define( "test", "ajax", {
 688		url: "",
 689		dataMap: function( data ) {
 690			deepEqual( data, {
 691				orig: "data"
 692			}, "original data in dataMap" );
 693
 694			return {
 695				foo: "bar",
 696				baz: "qux"
 697			};
 698		}
 699	});
 700	amplify.request( "test", {
 701		orig: "data"
 702	});
 703});
 704
 705asyncTest( "abort", function() {
 706	expect( 9 );
 707
 708	amplify.request.define( "test", "ajax", {
 709		url: "data/delay.php",
 710		dataType: "json",
 711		cache: false
 712	});
 713	var request = amplify.request({
 714		resourceId: "test",
 715		error: function( data, status ) {
 716			deepEqual( data, null, "error callback: data" );
 717			equal( status, "abort", "error callback: status" );
 718		},
 719		success: function() {
 720			ok( false, "success callback invoked" );
 721		}
 722	});
 723	subscribe( "request.error", function( settings, data, status ) {
 724		equal( settings.resourceId, "test", "error message: resourceId" );
 725		deepEqual( data, null, "error message: data" );
 726		equal( status, "abort", "error message: status" );
 727	});
 728	subscribe( "request.complete", function( settings, data, status ) {
 729		equal( settings.resourceId, "test", "complete message: resourceId" );
 730		deepEqual( data, null, "complete message: data" );
 731		equal( status, "abort", "complete message: status" );
 732		start();
 733	});
 734	subscribe( "request.success", function() {
 735		ok( false, "success message published" );
 736	});
 737	ok( "abort" in request, "request object has abort method" );
 738	request.abort();
 739	// make sure calling abort() multiple times does nothing
 740	// tested via expected number of assertions
 741	request.abort();
 742});
 743
 744asyncTest( "ampXHR", function() {
 745	expect( 7 );
 746
 747	var ampXHR;
 748	amplify.request.define( "ampXHR", "ajax", {
 749		// prevent caching to ensure we get proper headers
 750		cache: false,
 751		url: "data/headers.php",
 752		dataType: "json"
 753	});
 754	subscribe( "request.before.ajax", function( resource, settings, ajaxSettings, xhr ) {
 755		ampXHR = xhr;
 756		ampXHR.setRequestHeader( "X-Amplify-Request", "custom request header" );
 757	});
 758	subscribe( "request.success", function( settings, data, status ) {
 759		equal( ampXHR.readyState, 4, "ampXHR.readyState" );
 760		deepEqual( data, { header: "custom request header" }, "ampXHR.setRequestHeader()" );
 761		equal( ampXHR.getResponseHeader( "X-Amplify-Response" ), "custom response header",
 762			"ampXHR.getResponseHeader()" );
 763		ok( ampXHR.getAllResponseHeaders().toLowerCase().indexOf(
 764			"x-amplify-response: custom response header" ) !== -1,
 765			"ampXHR.getAllResponseHeaders()" );
 766		equal( ampXHR.status, 200, "ampXHR.status" );
 767		equal( ampXHR.statusText, "success", "ampXHR.statusText" );
 768		equal( ampXHR.responseText, "{\"header\":\"custom request header\"}",
 769			"ampXHR.responseText" );
 770	});
 771	subscribe( "request.complete", function() {
 772		start();
 773	});
 774	subscribe( "request.error", function() {
 775		ok( false, "error message published" );
 776	});
 777	amplify.request( "ampXHR" );
 778});
 779
 780test( "cache keys", function() {
 781	expect( 2 );
 782
 783	equal( amplify.request.cache._key( "x", "" ), "request-x-1996950016" );
 784	equal( amplify.request.cache._key( "x", "foo=bar" ), "request-x-50601290" );
 785});
 786
 787asyncTest( "cache: true", function() {
 788	expect( 14 );
 789
 790	var ajaxCalls = 0;
 791	$( "#ajax-listener" ).ajaxComplete(function( event, xhr ) {
 792		if ( xhr.statusText !== "abort" ) {
 793			ok( !ajaxCalls++, "ajax call completed" );
 794		}
 795	});
 796	amplify.request.define( "memory-cache", "ajax", {
 797		url: "data/data.json",
 798		dataType: "json",
 799		cache: true
 800	});
 801	// should execute for both requests
 802	subscribe( "request.before", function( settings ) {
 803		equal( settings.resourceId, "memory-cache", "before message: settings.resourceId" );
 804	});
 805	// should execute for first request only
 806	subscribe( "request.before.ajax", function( resource ) {
 807		equal( resource.resourceId, "memory-cache", "before.ajax message: resource.resourceId" );
 808	});
 809	// should execute for both requests
 810	subscribe( "request.success", function( settings, data ) {
 811		equal( settings.resourceId, "memory-cache", "success message: settings.resourceId" );
 812		deepEqual( data, { foo: "bar" }, "success message: data" );
 813	});
 814	// should execute for both requests
 815	subscribe( "request.complete", function( settings, data ) {
 816		equal( settings.resourceId, "memory-cache", "complete message: settings.resourceId" );
 817		deepEqual( data, { foo: "bar" }, "complete message: data" );
 818	});
 819	subscribe( "request.error", function() {
 820		ok( false, "error message published" );
 821	});
 822	amplify.request( "memory-cache", function( data ) {
 823		deepEqual( data, { foo: "bar" }, "first request callback" );
 824		amplify.request( "memory-cache", function( data ) {
 825			deepEqual( data, { foo: "bar" }, "second request callback" );
 826			start();
 827		});
 828	});
 829});
 830
 831asyncTest( "cache with data", function() {
 832	expect( 8 );
 833
 834	var expectAjax = true;
 835	amplify.request.define( "data-cache", "ajax", {
 836		url: "data/echo-raw.php",
 837		cache: true
 838	});
 839	subscribe( "request.before.ajax", function() {
 840		ok( expectAjax );
 841	});
 842	amplify.request( "data-cache", function( data ) {
 843		equal( data, "empty", "no data; empty cache" );
 844		amplify.request( "data-cache", { foo: "bar" }, function( data ) {
 845			equal( data, "foo=bar", "data; empty cache" );
 846			amplify.request( "data-cache", { foo: "qux" }, function( data ) {
 847				equal( data, "foo=qux", "different data; empty cache" );
 848				expectAjax = false;
 849				amplify.request( "data-cache", { foo: "bar" }, function( data ) {
 850					equal( data, "foo=bar", "data; cached" );
 851					amplify.request( "data-cache", function( data ) {
 852						equal( data, "empty", "no data; cached" );
 853						start();
 854					});
 855				});
 856			});
 857		});
 858	});
 859});
 860
 861asyncTest( "cache with data-replaced URL", function() {
 862	expect( 5 );
 863
 864	var expectAjax = true;
 865	amplify.request.define( "data-cache-url", "ajax", {
 866		url: "data/echo-raw.php?{foo}",
 867		cache: true
 868	});
 869	subscribe( "request.before.ajax", function() {
 870		ok( expectAjax );
 871	});
 872	amplify.request( "data-cache-url", { foo: "bar" }, function( data ) {
 873		equal( data, "bar", "data; empty cache" );
 874		amplify.request( "data-cache-url", { foo: "qux" }, function( data ) {
 875			equal( data, "qux", "different data; empty cache" );
 876			expectAjax = false;
 877			amplify.request( "data-cache-url", { foo: "bar" }, function( data ) {
 878				equal( data, "bar", "data; cached" );
 879				start();
 880			});
 881		});
 882	});
 883});
 884
 885asyncTest( "cache: Number", function() {
 886	expect( 22 );
 887	
 888	var shouldCache = false;
 889	$( "#ajax-listener" ).ajaxComplete(function( event, xhr ) {
 890		if ( xhr.statusText !== "abort" ) {
 891			ok( !shouldCache, "ajax call completed" );
 892		}
 893	});
 894	amplify.request.define( "cache-duration", "ajax", {
 895		url: "data/data.json",
 896		dataType: "json",
 897		cache: 500
 898	});
 899	// should execute for 3 requests
 900	subscribe( "request.before", function( settings ) {
 901		equal( settings.resourceId, "cache-duration", "before message: settings.resourceId" );
 902	});
 903	// should execute for 2 requests
 904	subscribe( "request.before.ajax", function( resource ) {
 905		equal( resource.resourceId, "cache-duration", "before.ajax message: resource.resourceId" );
 906	});
 907	// should execute for 3 requests
 908	subscribe( "request.success", function( settings, data ) {
 909		equal( settings.resourceId, "cache-duration", "success message: settings.resourceId" );
 910		deepEqual( data, { foo: "bar" }, "success message: data" );
 911	});
 912	// should execute for 3 requests
 913	subscribe( "request.complete", function( settings, data ) {
 914		equal( settings.resourceId, "cache-duration", "complete message: settings.resourceId" );
 915		deepEqual( data, { foo: "bar" }, "complete message: data" );
 916	});
 917	subscribe( "request.error", function() {
 918		ok( false, "error message published" );
 919	});
 920	amplify.request( "cache-duration", function( data ) {
 921		// delay setting the flag because the success callback will be invoked
 922		// before the ajaxComplete event is triggered
 923		setTimeout(function() {
 924			shouldCache = true;
 925		}, 1 );
 926		deepEqual( data, { foo: "bar" }, "first request callback" );
 927		amplify.request( "cache-duration", function( data ) {
 928			deepEqual( data, { foo: "bar" }, "second request callback" );
 929		});
 930		setTimeout(function() {
 931			shouldCache = false;
 932			amplify.request( "cache-duration", function( data ) {
 933				deepEqual( data, { foo: "bar" }, "third request callback" );
 934				start();
 935			});
 936		}, 700 );
 937	});
 938});
 939
 940if ( amplify.store ) {
 941	var storeExpiresLifecycle = {
 942		setup: function() {
 943			$.each( amplify.store(), function( key ) {
 944				if ( /^request/.test( key ) ) {
 945					amplify.store( key, null );
 946				}
 947			});
 948		}
 949	};
 950	asyncTest( "cache: persist - no expires", storeExpiresLifecycle, function() {
 951		expect( 15 );
 952
 953		var ajaxCalls = 0;
 954		$( "#ajax-listener" ).ajaxComplete(function( event, xhr ) {
 955			if ( xhr.statusText !== "abort" ) {
 956				ok( !ajaxCalls++, "ajax call completed" );
 957			}
 958		});
 959		amplify.request.define( "persist-cache", "ajax", {
 960			url: "data/data.json",
 961			dataType: "json",
 962			cache: "persist"
 963		});
 964		// should execute for both requests
 965		subscribe( "request.before", function( settings ) {
 966			equal( settings.resourceId, "persist-cache", "before message: settings.resourceId" );
 967		});
 968		// should execute for first request only
 969		subscribe( "request.before.ajax", function( resource ) {
 970			equal( resource.resourceId, "persist-cache", "before.ajax message: resource.resourceId" );
 971			equal( resource.cache.expires, undefined, "before.ajax message: resource.expires");
 972		});
 973		// should execute for both requests
 974		subscribe( "request.success", function( settings, data ) {
 975			equal( settings.resourceId, "persist-cache", "success message: settings.resourceId" );
 976			deepEqual( data, { foo: "bar" }, "success message: data" );
 977		});
 978		// should execute for both requests
 979		subscribe( "request.complete", function( settings, data ) {
 980			equal( settings.resourceId, "persist-cache", "complete message: settings.resourceId" );
 981			deepEqual( data, { foo: "bar" }, "complete message: data" );
 982		});
 983		subscribe( "request.error", function() {
 984			ok( false, "error message published" );
 985		});
 986		amplify.request( "persist-cache", function( data ) {
 987			deepEqual( data, { foo: "bar" }, "first request callback" );
 988			amplify.request( "persist-cache", function( data ) {
 989				deepEqual( data, { foo: "bar" }, "second request callback" );
 990				start();
 991			});
 992		});
 993	});
 994
 995	asyncTest( "cache: persist - expires", storeExpiresLifecycle, function() {
 996		expect( 24 );
 997
 998		var shouldCache = false;
 999		$( "#ajax-listener" ).ajaxComplete(function( event, xhr ) {
1000			if ( xhr.statusText !== "abort" ) {
1001				ok( !shouldCache, "ajax call completed" );
1002			}
1003		});
1004
1005		amplify.request.define( "persist-cache", "ajax", {
1006			url: "data/data.json",
1007			dataType: "json",
1008			cache: { type: "persist", expires: 450 }
1009		});
1010
1011		// should execute for 3 requests
1012		subscribe( "request.before", function( settings ) {
1013			equal( settings.resourceId, "persist-cache", "before message: settings.resourceId" );
1014		});
1015		// should execute for 2 requests
1016		subscribe( "request.before.ajax", function( resource ) {
1017			equal( resource.resourceId, "persist-cache", "before.ajax message: resource.resourceId" );
1018			equal( resource.cache.expires, 450, "before.ajax message: resource.expires");
1019		});
1020		// should execute 3 requests
1021		subscribe( "request.success", function( settings, data ) {
1022			equal( settings.resourceId, "persist-cache", "success message: settings.resourceId" );
1023			deepEqual( data, { foo: "bar" }, "success message: data" );
1024		});
1025		// should execute for 3 requests
1026		subscribe( "request.complete", function( settings, data ) {
1027			equal( settings.resourceId, "persist-cache", "complete message: settings.resourceId" );
1028			deepEqual( data, { foo: "bar" }, "complete message: data" );
1029		});
1030		subscribe( "request.error", function() {
1031			ok( false, "error message published" );
1032		});
1033
1034		amplify.request( "persist-cache", function( data ) {
1035			// delay setting the flag because the success callback will be invoked
1036			// before the ajaxComplete event is triggered
1037			setTimeout(function() {
1038				shouldCache = true;
1039			}, 1 );
1040			deepEqual( data, { foo: "bar" }, "first request callback" );
1041			amplify.request( "persist-cache", function( data ) {
1042				deepEqual( data, { foo: "bar" }, "second request callback" );
1043			});
1044			setTimeout(function() {
1045				shouldCache = false;
1046				amplify.request( "persist-cache", function( data ) {
1047					deepEqual( data, { foo: "bar" }, "third request callback" );
1048					start();
1049				});
1050			}, 500 );
1051		});
1052	});
1053
1054	test( "cache types", function() {
1055		$.each( amplify.store.types, function( type ) {
1056			ok( type in amplify.request.cache, type );
1057		});
1058	});
1059}
1060
1061asyncTest( "decoder: Function - success", function() {
1062	expect( 11 );
1063
1064	amplify.request.define( "test", "ajax", {
1065		url: "data/data.json",
1066		dataType: "json",
1067		decoder: function( data, status, xhr, success, error ) {
1068			deepEqual( data, { foo: "bar" }, "data in decoder" );
1069			equal( status, "success", "status in decoder" );
1070			ok( "abort" in xhr, "xhr in decoder" );
1071			success({ baz: "qux" });
1072		}
1073	});
1074	subscribe( "request.success", function( settings, data, status ) {
1075		equal( settings.resourceId, "test", "success message: settings.resrouceId" );
1076		deepEqual( data, { baz: "qux" }, "success message: data" );
1077		equal( status, "success", "success message: status" );
1078	});
1079	subscribe( "request.complete", function( settings, data, status ) {
1080		equal( settings.resourceId, "test", "complete message: settings.resrouceId" );
1081		deepEqual( data, { baz: "qux" }, "complete message: data" );
1082		equal( status, "success", "complete message: status" );
1083		start();
1084	});
1085	subscribe( "request.error", function() {
1086		ok( false, "error message published" );
1087	});
1088	amplify.request({
1089		resourceId: "test",
1090		success: function( data, status ) {
1091			deepEqual( data, { baz: "qux" }, "success callback: data" );
1092			equal( status, "success", "success callback: status" );
1093		},
1094		error: function() {
1095			ok( false, "error callback invoked" );
1096		}
1097	});
1098});
1099
1100asyncTest( "decoder: Function - error", function() {
1101	expect( 11 );
1102
1103	amplify.request.define( "test", "ajax", {
1104		url: "data/data.json",
1105		dataType: "json",
1106		decoder: function( data, status, xhr, success, error ) {
1107			deepEqual( data, { foo: "bar" }, "data in decoder" );
1108			equal( status, "success", "status in decoder" );
1109			ok( "abort" in xhr, "xhr in decoder" );
1110			error({ baz: "qux" });
1111		}
1112	});
1113	subscribe( "request.error", function( settings, data, status ) {
1114		equal( settings.resourceId, "test", "error message: settings.resrouceId" );
1115		deepEqual( data, { baz: "qux" }, "error message: data" );
1116		equal( status, "error", "error message: status" );
1117	});
1118	subscribe( "request.complete", function( settings, data, status ) {
1119		equal( settings.resourceId, "test", "complete message: settings.resrouceId" );
1120		deepEqual( data, { baz: "qux" }, "complete message: data" );
1121		equal( status, "error", "complete message: status" );
1122		start();
1123	});
1124	subscribe( "request.success", function() {
1125		ok( false, "success message published" );
1126	});
1127	amplify.request({
1128		resourceId: "test",
1129		success: function() {
1130			ok( false, "success callback invoked" );
1131		},
1132		error: function( data, status ) {
1133			deepEqual( data, { baz: "qux" }, "error callback: data" );
1134			equal( status, "error", "error callback: status" );
1135		}
1136	});
1137});
1138
1139asyncTest( "decoder: jsend - success", function() {
1140	expect( 8 );
1141
1142	amplify.request.define( "test", "ajax", {
1143		url: "data/jsend.json",
1144		dataType: "json",
1145		decoder: "jsend"
1146	});
1147	subscribe( "request.success", function( settings, data, status ) {
1148		equal( settings.resourceId, "test", "success message: settings.resrouceId" );
1149		deepEqual( data, { unwrapped: true }, "success message: data" );
1150		equal( status, "success", "success message: status" );
1151	});
1152	subscribe( "request.complete", function( settings, data, status ) {
1153		equal( settings.resourceId, "test", "complete message: settings.resrouceId" );
1154		deepEqual( data, { unwrapped: true }, "complete message: data" );
1155		equal( status, "success", "complete message: status" );
1156		start();
1157	});
1158	subscribe( "request.error", function() {
1159		ok( false, "error message published" );
1160	});
1161	amplify.request({
1162		resourceId: "test",
1163		success: function( data, status ) {
1164			deepEqual( data, { unwrapped: true }, "success callback: data" );
1165			equal( status, "success", "success callback: status" );
1166		},
1167		error: function() {
1168			ok( false, "error callback invoked" );
1169		}
1170	});
1171});
1172
1173asyncTest( "decoder: jsend - fail", function() {
1174	expect( 8 );
1175
1176	amplify.request.define( "test", "ajax", {
1177		url: "data/jsend-fail.json",
1178		dataType: "json",
1179		decoder: "jsend"
1180	});
1181	subscribe( "request.error", function( settings, data, status ) {
1182		equal( settings.resourceId, "test", "error message: settings.resrouceId" );
1183		deepEqual( data, { broken: true }, "error message: data" );
1184		equal( status, "fail", "error message: status" );
1185	});
1186	subscribe( "request.complete", function( settings, data, status ) {
1187		equal( settings.resourceId, "test", "complete message: settings.resrouceId" );
1188		deepEqual( data, { broken: true }, "complete message: data" );
1189		equal( status, "fail", "complete message: status" );
1190		start();
1191	});
1192	subscribe( "request.success", function() {
1193		ok( false, "success message published" );
1194	});
1195	amplify.request({
1196		resourceId: "test",
1197		success: function() {
1198			ok( false, "success callback invoked" );
1199		},
1200		error: function( data, status ) {
1201			deepEqual( data, { broken: true }, "error callback: data" );
1202			equal( status, "fail", "error callback: status" );
1203		}
1204	});
1205});
1206
1207asyncTest( "decoder: jsend - error", function() {
1208	expect( 8 );
1209
1210	amplify.request.define( "test", "ajax", {
1211		url: "data/jsend-error.json",
1212		dataType: "json",
1213		decoder: "jsend"
1214	});
1215	subscribe( "request.error", function( settings, data, status ) {
1216		equal( settings.resourceId, "test", "error message: settings.resrouceId" );
1217		deepEqual( data, { message: "it broke" }, "error message: data" );
1218		equal( status, "error", "error message: status" );
1219	});
1220	subscribe( "request.complete", function( settings, data, status ) {
1221		equal( settings.resourceId, "test", "complete message: settings.resrouceId" );
1222		deepEqual( data, { message: "it broke" }, "complete message: data" );
1223		equal( status, "error", "complete message: status" );
1224		start();
1225	});
1226	subscribe( "request.success", function() {
1227		ok( false, "success message published" );
1228	});
1229	amplify.request({
1230		resourceId: "test",
1231		success: function() {
1232			ok( false, "success callback invoked" );
1233		},
1234		error: function( data, status ) {
1235			deepEqual( data, { message: "it broke" }, "error callback: data" );
1236			equal( status, "error", "error callback: status" );
1237		}
1238	});
1239});
1240
1241asyncTest( "decoder: jsend - error with details", function() {
1242	expect( 8 );
1243
1244	amplify.request.define( "test", "ajax", {
1245		url: "data/jsend-error2.json",
1246		dataType: "json",
1247		decoder: "jsend"
1248	});
1249	subscribe( "request.error", function( settings, data, status ) {
1250		equal( settings.resourceId, "test", "error message: settings.resrouceId" );
1251		deepEqual( data, {
1252			message: "it broke",
1253			code: 15,
1254			data: { you: "broke", it: "bad" }
1255		}, "error message: data" );
1256		equal( status, "error", "error message: status" );
1257	});
1258	subscribe( "request.complete", function( settings, data, status ) {
1259		equal( settings.resourceId, "test", "complete message: settings.resrouceId" );
1260		deepEqual( data, {
1261			message: "it broke",
1262			code: 15,
1263			data: { you: "broke", it: "bad" }
1264		}, "complete message: data" );
1265		equal( status, "error", "complete message: status" );
1266		start();
1267	});
1268	subscribe( "request.success", function() {
1269		ok( false, "success message published" );
1270	});
1271	amplify.request({
1272		resourceId: "test",
1273		success: function() {
1274			ok( false, "success callback invoked" );
1275		},
1276		error: function( data, status ) {
1277			deepEqual( data, {
1278				message: "it broke",
1279				code: 15,
1280				data: { you: "broke", it: "bad" }
1281			}, "error callback: data" );
1282			equal( status, "error", "error callback: status" );
1283		}
1284	});
1285});
1286
1287asyncTest( "decoder: custom", function() {
1288	expect( 11 );
1289
1290	amplify.request.decoders.silly = function( data, status, xhr, success, error ) {
1291		deepEqual( data, { foo: "bar" }, "data in decoder" );
1292		equal( status, "success", "status in decoder" );
1293		ok( "abort" in xhr, "xhr in decoder" );
1294		var sillyData = {};
1295		$.each( data, function( key, value ) {
1296			sillyData[ "silly-" + key ] = value;
1297		});
1298		success( sillyData, "silly" );
1299	};
1300	amplify.request.define( "test", "ajax", {
1301		url: "data/data.json",
1302		dataType: "json",
1303		decoder: "silly"
1304	});
1305	subscribe( "request.success", function( settings, data, status ) {
1306		equal( settings.resourceId, "test", "success message: settings.resrouceId" );
1307		deepEqual( data, { "silly-foo": "bar" }, "success message: data" );
1308		equal( status, "silly", "success message: status" );
1309	});
1310	subscribe( "request.complete", function( settings, data, status ) {
1311		equal( settings.resourceId, "test", "complete message: settings.resrouceId" );
1312		deepEqual( data, { "silly-foo": "bar" }, "complete message: data" );
1313		equal( status, "silly", "complete message: status" );
1314		start();
1315		delete amplify.request.decoders.silly;
1316	});
1317	subscribe( "request.error", function() {
1318		ok( false, "error message published" );
1319	});
1320	amplify.request({
1321		resourceId: "test",
1322		success: function( data, status ) {
1323			deepEqual( data, { "silly-foo": "bar" }, "success callback: data" );
1324			equal( status, "silly", "success callback: status" );
1325		},
1326		error: function() {
1327			ok( false, "error callback invoked" );
1328		}
1329	});
1330});
1331
1332asyncTest( "decoder: jsonp", function() {
1333	expect( 11 );
1334
1335	amplify.request.define( "test", "ajax", {
1336		url: "data/jsonp.php",
1337		dataType: "jsonp",
1338		decoder: function( data, status, xhr, success, error ) {
1339			deepEqual( data, { foo: "bar" }, "data in decoder" );
1340			equal( status, "success", "status in decoder" );
1341			ok( "abort" in xhr, "xhr in decoder" );
1342			var decodedData = {};
1343			$.each( data, function( key, value ) {
1344				decodedData[ "decoded-" + key ] = value;
1345			});
1346			success( decodedData, "decoded-jsonp" );
1347		}
1348	});
1349	subscribe( "request.success", function( settings, data, status ) {
1350		equal( settings.resourceId, "test", "success message: settings.resrouceId" );
1351		deepEqual( data, { "decoded-foo": "bar" }, "success message: data" );
1352		equal( status, "decoded-jsonp", "success message: status" );
1353	});
1354	subscribe( "request.complete", function( settings, data, status ) {
1355		equal( settings.resourceId, "test", "complete message: settings.resrouceId" );
1356		deepEqual( data, { "decoded-foo": "bar" }, "complete message: data" );
1357		equal( status, "decoded-jsonp", "complete message: status" );
1358		start();
1359	});
1360	subscribe( "request.error", function() {
1361		ok( false, "error message published" );
1362	});
1363	amplify.request({
1364		resourceId: "test",
1365		success: function( data, status ) {
1366			deepEqual( data, { "decoded-foo": "bar" }, "success callback: data" );
1367			equal( status, "decoded-jsonp", "success callback: status" );
1368		},
1369		error: function() {
1370			ok( false, "error callback invoked" );
1371		}
1372	});
1373});
1374
1375}());