11 lines
4.4 KiB
JavaScript
11 lines
4.4 KiB
JavaScript
//>>built
|
|
define("dstore/tests/Request","intern!object intern/chai!assert dojo/_base/declare dojo/_base/lang dojo/json dojo/request/registry dojo/when dojo/promise/all dstore/Request dstore/SimpleQuery ./mockRequest dojo/text!./data/treeTestRoot".split(" "),function(q,c,r,x,t,y,n,C,u,z,f,v){function d(a,b,e){var d=[{id:1,name:"one"},{id:2,name:"two"}];f.setResponseText(t.stringify(d));e?a=a.fetchRange(b):(e=b,a=a.fetch());return n(a).then(function(b){e.headers&&f.assertRequestHeaders(e.headers);e.queryParams&&
|
|
f.assertQueryParams(e.queryParams);c.strictEqual(b.length,d.length);for(var a=0;a<b.length;++a){var l=b[a],g=d[a],p;for(p in g)c.strictEqual(l[p],g[p])}})}function h(l){return{name:"dstore Request",before:function(){w=y.register(/.*mockRequest.*/,f)},after:function(){w.remove()},beforeEach:function(){f.setResponseText("{}");f.setResponseHeaders({});a=new l({target:"/mockRequest/",headers:A,Model:B});a.Model.prototype.describe=function(){return"name is "+this.name};h.store=a},filter:function(){f.setResponseText(v);
|
|
return n(a.filter("data/treeTestRoot").fetch()).then(function(b){b=b[0];c.strictEqual(b.name,"node1");c.strictEqual(b.describe(),"name is node1");c.strictEqual(b.someProperty,"somePropertyA")})},"filter iterative":function(){f.setResponseText(v);var b=0;return a.filter("data/treeTestRoot").forEach(function(a){b++;c.strictEqual(a.name,"node"+b);c.equal(typeof a.describe,"function")})},"filter object":function(){var b={prop1:"Prop1Value",prop2:"Prop2Value"};return d(a.filter(b),{queryParams:b})},"filter builder":function(){var b=
|
|
(new a.Filter).gt("id",2).lt("price",5);return d(a.filter(b),{queryParams:{id:"gt\x3d2",price:"lt\x3d5"}})},"filter builder ne or":function(){var b=new a.Filter,b=b.ne("id",2).or(b.eq("foo",!0),b.eq("foo"));return d(a.filter(b),{queryParams:{id:"ne\x3d2","(foo":"true|foo\x3dundefined)"}})},sort:function(){var b=a.sort({property:"prop1",descending:!0},{property:"prop2"},{property:"prop3",descending:!0});return d(b,{queryParams:{"sort(-prop1,+prop2,-prop3)":""}})},"sort with this.sortParam":function(){a.sortParam=
|
|
"sort-param";var b=a.sort({property:"prop1",descending:!0},{property:"prop2"},{property:"prop3",descending:!0});return d(b,{queryParams:{"sort-param":"-prop1,+prop2,-prop3"}})},"sort with different prefixes":function(){a.descendingPrefix="--";a.ascendingPrefix="++";var b=a.sort({property:"prop1",descending:!0},{property:"prop2"},{property:"prop3",descending:!0});return d(b,{queryParams:{"sort(--prop1,++prop2,--prop3)":""}})},range:function(){return d(a,{start:15,end:25},{queryParams:{"limit(10,15)":""}})},
|
|
"range with rangeParam":function(){a.rangeStartParam="start";a.rangeCountParam="count";return d(a,{start:15,end:25},{queryParams:{start:"15",count:"10"}})},"range with headers":function(){a.useRangeHeaders=!0;return d(a,{start:15,end:25},{headers:{Range:"items\x3d15-24"}})},"range with headers without end":function(){a.useRangeHeaders=!0;return d(a,{start:15,end:Infinity},{headers:{Range:"items\x3d15-Infinity"}})},"filter+sort+fetchRange":function(){var b={prop1:"Prop1Value",prop2:"Prop2Value"},c=
|
|
a.filter(b).sort("prop1");return d(c,{start:15,end:25},{queryParams:x.mixin({},b,{"limit(10,15)":"","sort(+prop1)":""})})},"composition with client-side queriers":function(){var a=new (r([l,z],{target:"/mockRequest/"})),e=[{id:1,name:"one",odd:!0},{id:2,name:"two",odd:!1},{id:3,name:"three",odd:!0}];f.setResponseText(t.stringify(e));var d={odd:!0},m=a.filter(d),k,h=function(a){a=a.queryLog;return a[a.length-1]},g;c.strictEqual(m.queryLog.length,1);return n(m.fetch()).then(function(a){f.assertQueryParams(d);
|
|
c.strictEqual(a.length,e.length);a=h(m);c.property(a,"querier");g=a.querier;a=g(e);c.equal(a.length,2);c.deepEqual(a[0],e[0]);c.deepEqual(a[1],e[2]);k=m.sort("id",!0);c.strictEqual(k.queryLog.length,2);return k.fetch()}).then(function(a){f.assertQueryParams({"sort(-id)":""});c.strictEqual(a.length,e.length);var b=h(k);c.property(b,"querier");g=function(){var a=g,c=b.querier;return function(b){return c(a(b))}}();a=g(e);c.equal(a.length,2);c.deepEqual(a[0],e[2]);c.deepEqual(a[1],e[0]);return k.fetchRange({start:0,
|
|
end:25})}).then(function(a){f.assertQueryParams({"sort(-id)":"","limit(25)":""});c.strictEqual(a.length,e.length)})}}}var B=r(null,{}),A={"test-global-header-a":"true","test-global-header-b":"yes"},a,w;q(h(u));q({name:"dstore Request default",cancel:function(){var a=(new u({target:"/test/"})).fetch();c.property(a.response,"then");a.cancel()}});return h});
|
|
//# sourceMappingURL=Request.js.map
|