Fossil SCM

minor ajax test code cleanups.

stephan 2011-09-30 17:00 UTC json
Commit 7eb52b23ae3505f8e7fca0be9d08f341465584e9
--- ajax/i-test/rhino-test.js
+++ ajax/i-test/rhino-test.js
@@ -16,11 +16,11 @@
1616
for( var i in includes ) {
1717
load(includes[i]);
1818
}
1919
WhAjaj.Connector.prototype.sendImpl = WhAjaj.Connector.sendImpls.rhino;
2020
TestApp.fossil = new FossilAjaj({
21
- asynchronous:false, /* rhino-based impl doesn't support asynch. */
21
+ asynchronous:false, /* rhino-based impl doesn't support async or timeout. */
2222
url:TestApp.serverUrl,
2323
beforeSend:function(req,opt){
2424
if(!TestApp.verbose) return;
2525
print("SENDING REQUEST: AJAJ options="+JSON.stringify(opt));
2626
if(req) print("Request envelope="+WhAjaj.stringify(req));
@@ -43,11 +43,11 @@
4343
4444
/**
4545
Throws an exception of cond is a falsy value.
4646
*/
4747
function assert(cond, descr){
48
- descr = descr || "Undescribed condition failed.";
48
+ descr = descr || "Undescribed condition.";
4949
if(!cond){
5050
throw new Error("Assertion failed: "+descr);
5151
}else{
5252
print("Assertion OK: "+descr);
5353
}
@@ -86,18 +86,24 @@
8686
function assertResponseOK(resp){
8787
assert('object' === typeof resp,'Response is-a object.');
8888
assert( 'string' === typeof resp.fossil, 'Response contains fossil property.');
8989
assert( !resp.resultCode, 'resp.resultCode='+resp.resultCode);
9090
}
91
+/**
92
+ Asserts that resp is-a Object, resp.fossil is-a string, and
93
+ resp.resultCode is a truthy value. If expectCode is set then
94
+ it also asserts that (resp.resultCode=='FOSSIL-'+expectCode).
95
+*/
9196
function assertResponseError(resp,expectCode){
9297
assert('object' === typeof resp,'Response is-a object.');
9398
assert( 'string' === typeof resp.fossil, 'Response contains fossil property.');
9499
assert( resp.resultCode, 'resp.resultCode='+resp.resultCode);
95100
if(expectCode){
96101
assert( 'FOSSIL-'+expectCode == resp.resultCode, 'Expecting result code '+expectCode );
97102
}
98103
}
104
+
99105
function testHAI(){
100106
TestApp.fossil.HAI({
101107
onResponse:function(resp,req){
102108
assertResponseOK(resp);
103109
TestApp.serverVersion = resp.fossil;
@@ -125,21 +131,21 @@
125131
126132
function testAnonWikiList(){
127133
TestApp.fossil.sendCommand('/json/wiki/list',undefined,{
128134
beforeSend:function(req,opt){
129135
TestApp.fossil.ajaj.options.beforeSend(req,opt);
130
- assert( req && (req.authToken==TestApp.fossil.authToken) );
136
+ assert( req && (req.authToken==TestApp.fossil.authToken), 'Request envelope contains expected authToken.' );
131137
},
132138
onResponse:function(resp,req){
133139
assertResponseOK(resp);
134140
assert( (typeof [] === typeof resp.payload) && resp.payload.length,
135141
"Wiki list seems to be okay.");
136142
TestApp.wiki.list = resp.payload;
137143
}
138144
});
139145
}
140
-testAnonWikiList.description = 'Fetch wiki list as anonymous uses.';
146
+testAnonWikiList.description = 'Fetch wiki list as anonymous user.';
141147
142148
function testAnonLogout(){
143149
TestApp.fossil.logout({
144150
onResponse:function(resp,req){
145151
assertResponseOK(resp);
@@ -149,11 +155,11 @@
149155
onResponse:function(resp,req){
150156
assertResponseError(resp);
151157
}
152158
});
153159
}
154
-testAnonLogout.description = 'Fetch wiki list as anonymous uses.';
160
+testAnonLogout.description = 'Log out anonymous user.';
155161
156162
(function runAllTests(){
157163
var testList = [
158164
testHAI,
159165
testIAmNobody,
@@ -163,11 +169,11 @@
163169
];
164170
var i, f;
165171
for( i = 0; i < testList.length; ++i ){
166172
f = testList[i];
167173
try{
168
- print("Running #"+(i+1)+": "+(f.description || "no description."));
174
+ print("Running test #"+(i+1)+": "+(f.description || "no description."));
169175
f();
170176
}catch(e){
171177
print("Test failed: "+e);
172178
throw e;
173179
}
174180
--- ajax/i-test/rhino-test.js
+++ ajax/i-test/rhino-test.js
@@ -16,11 +16,11 @@
16 for( var i in includes ) {
17 load(includes[i]);
18 }
19 WhAjaj.Connector.prototype.sendImpl = WhAjaj.Connector.sendImpls.rhino;
20 TestApp.fossil = new FossilAjaj({
21 asynchronous:false, /* rhino-based impl doesn't support asynch. */
22 url:TestApp.serverUrl,
23 beforeSend:function(req,opt){
24 if(!TestApp.verbose) return;
25 print("SENDING REQUEST: AJAJ options="+JSON.stringify(opt));
26 if(req) print("Request envelope="+WhAjaj.stringify(req));
@@ -43,11 +43,11 @@
43
44 /**
45 Throws an exception of cond is a falsy value.
46 */
47 function assert(cond, descr){
48 descr = descr || "Undescribed condition failed.";
49 if(!cond){
50 throw new Error("Assertion failed: "+descr);
51 }else{
52 print("Assertion OK: "+descr);
53 }
@@ -86,18 +86,24 @@
86 function assertResponseOK(resp){
87 assert('object' === typeof resp,'Response is-a object.');
88 assert( 'string' === typeof resp.fossil, 'Response contains fossil property.');
89 assert( !resp.resultCode, 'resp.resultCode='+resp.resultCode);
90 }
 
 
 
 
 
91 function assertResponseError(resp,expectCode){
92 assert('object' === typeof resp,'Response is-a object.');
93 assert( 'string' === typeof resp.fossil, 'Response contains fossil property.');
94 assert( resp.resultCode, 'resp.resultCode='+resp.resultCode);
95 if(expectCode){
96 assert( 'FOSSIL-'+expectCode == resp.resultCode, 'Expecting result code '+expectCode );
97 }
98 }
 
99 function testHAI(){
100 TestApp.fossil.HAI({
101 onResponse:function(resp,req){
102 assertResponseOK(resp);
103 TestApp.serverVersion = resp.fossil;
@@ -125,21 +131,21 @@
125
126 function testAnonWikiList(){
127 TestApp.fossil.sendCommand('/json/wiki/list',undefined,{
128 beforeSend:function(req,opt){
129 TestApp.fossil.ajaj.options.beforeSend(req,opt);
130 assert( req && (req.authToken==TestApp.fossil.authToken) );
131 },
132 onResponse:function(resp,req){
133 assertResponseOK(resp);
134 assert( (typeof [] === typeof resp.payload) && resp.payload.length,
135 "Wiki list seems to be okay.");
136 TestApp.wiki.list = resp.payload;
137 }
138 });
139 }
140 testAnonWikiList.description = 'Fetch wiki list as anonymous uses.';
141
142 function testAnonLogout(){
143 TestApp.fossil.logout({
144 onResponse:function(resp,req){
145 assertResponseOK(resp);
@@ -149,11 +155,11 @@
149 onResponse:function(resp,req){
150 assertResponseError(resp);
151 }
152 });
153 }
154 testAnonLogout.description = 'Fetch wiki list as anonymous uses.';
155
156 (function runAllTests(){
157 var testList = [
158 testHAI,
159 testIAmNobody,
@@ -163,11 +169,11 @@
163 ];
164 var i, f;
165 for( i = 0; i < testList.length; ++i ){
166 f = testList[i];
167 try{
168 print("Running #"+(i+1)+": "+(f.description || "no description."));
169 f();
170 }catch(e){
171 print("Test failed: "+e);
172 throw e;
173 }
174
--- ajax/i-test/rhino-test.js
+++ ajax/i-test/rhino-test.js
@@ -16,11 +16,11 @@
16 for( var i in includes ) {
17 load(includes[i]);
18 }
19 WhAjaj.Connector.prototype.sendImpl = WhAjaj.Connector.sendImpls.rhino;
20 TestApp.fossil = new FossilAjaj({
21 asynchronous:false, /* rhino-based impl doesn't support async or timeout. */
22 url:TestApp.serverUrl,
23 beforeSend:function(req,opt){
24 if(!TestApp.verbose) return;
25 print("SENDING REQUEST: AJAJ options="+JSON.stringify(opt));
26 if(req) print("Request envelope="+WhAjaj.stringify(req));
@@ -43,11 +43,11 @@
43
44 /**
45 Throws an exception of cond is a falsy value.
46 */
47 function assert(cond, descr){
48 descr = descr || "Undescribed condition.";
49 if(!cond){
50 throw new Error("Assertion failed: "+descr);
51 }else{
52 print("Assertion OK: "+descr);
53 }
@@ -86,18 +86,24 @@
86 function assertResponseOK(resp){
87 assert('object' === typeof resp,'Response is-a object.');
88 assert( 'string' === typeof resp.fossil, 'Response contains fossil property.');
89 assert( !resp.resultCode, 'resp.resultCode='+resp.resultCode);
90 }
91 /**
92 Asserts that resp is-a Object, resp.fossil is-a string, and
93 resp.resultCode is a truthy value. If expectCode is set then
94 it also asserts that (resp.resultCode=='FOSSIL-'+expectCode).
95 */
96 function assertResponseError(resp,expectCode){
97 assert('object' === typeof resp,'Response is-a object.');
98 assert( 'string' === typeof resp.fossil, 'Response contains fossil property.');
99 assert( resp.resultCode, 'resp.resultCode='+resp.resultCode);
100 if(expectCode){
101 assert( 'FOSSIL-'+expectCode == resp.resultCode, 'Expecting result code '+expectCode );
102 }
103 }
104
105 function testHAI(){
106 TestApp.fossil.HAI({
107 onResponse:function(resp,req){
108 assertResponseOK(resp);
109 TestApp.serverVersion = resp.fossil;
@@ -125,21 +131,21 @@
131
132 function testAnonWikiList(){
133 TestApp.fossil.sendCommand('/json/wiki/list',undefined,{
134 beforeSend:function(req,opt){
135 TestApp.fossil.ajaj.options.beforeSend(req,opt);
136 assert( req && (req.authToken==TestApp.fossil.authToken), 'Request envelope contains expected authToken.' );
137 },
138 onResponse:function(resp,req){
139 assertResponseOK(resp);
140 assert( (typeof [] === typeof resp.payload) && resp.payload.length,
141 "Wiki list seems to be okay.");
142 TestApp.wiki.list = resp.payload;
143 }
144 });
145 }
146 testAnonWikiList.description = 'Fetch wiki list as anonymous user.';
147
148 function testAnonLogout(){
149 TestApp.fossil.logout({
150 onResponse:function(resp,req){
151 assertResponseOK(resp);
@@ -149,11 +155,11 @@
155 onResponse:function(resp,req){
156 assertResponseError(resp);
157 }
158 });
159 }
160 testAnonLogout.description = 'Log out anonymous user.';
161
162 (function runAllTests(){
163 var testList = [
164 testHAI,
165 testIAmNobody,
@@ -163,11 +169,11 @@
169 ];
170 var i, f;
171 for( i = 0; i < testList.length; ++i ){
172 f = testList[i];
173 try{
174 print("Running test #"+(i+1)+": "+(f.description || "no description."));
175 f();
176 }catch(e){
177 print("Test failed: "+e);
178 throw e;
179 }
180
--- ajax/js/fossil-ajaj.js
+++ ajax/js/fossil-ajaj.js
@@ -151,21 +151,21 @@
151151
if( WhAjaj.isFunction(oldOnResponse) ) {
152152
try { oldOnResponse.apply(thisOpt,[resp,req]); }
153153
catch(e) {}
154154
}
155155
};
156
- this.sendCommand('/json/logout', false, ajajOpt );
156
+ this.sendCommand('/json/logout', undefined, ajajOpt );
157157
};
158158
159159
/**
160160
Sends a HAI request to the server. /json/HAI is an alias /json/version.
161161
162162
ajajOpt is an optional configuration object suitable for passing
163163
to sendCommand().
164164
*/
165165
FossilAjaj.prototype.HAI = function(ajajOpt) {
166
- this.sendCommand('/json/HAI', null, ajajOpt);
166
+ this.sendCommand('/json/HAI', undefined, ajajOpt);
167167
};
168168
169169
170170
/**
171171
Sends a /json/whoami request. Updates this.userName and this.authToken
172172
--- ajax/js/fossil-ajaj.js
+++ ajax/js/fossil-ajaj.js
@@ -151,21 +151,21 @@
151 if( WhAjaj.isFunction(oldOnResponse) ) {
152 try { oldOnResponse.apply(thisOpt,[resp,req]); }
153 catch(e) {}
154 }
155 };
156 this.sendCommand('/json/logout', false, ajajOpt );
157 };
158
159 /**
160 Sends a HAI request to the server. /json/HAI is an alias /json/version.
161
162 ajajOpt is an optional configuration object suitable for passing
163 to sendCommand().
164 */
165 FossilAjaj.prototype.HAI = function(ajajOpt) {
166 this.sendCommand('/json/HAI', null, ajajOpt);
167 };
168
169
170 /**
171 Sends a /json/whoami request. Updates this.userName and this.authToken
172
--- ajax/js/fossil-ajaj.js
+++ ajax/js/fossil-ajaj.js
@@ -151,21 +151,21 @@
151 if( WhAjaj.isFunction(oldOnResponse) ) {
152 try { oldOnResponse.apply(thisOpt,[resp,req]); }
153 catch(e) {}
154 }
155 };
156 this.sendCommand('/json/logout', undefined, ajajOpt );
157 };
158
159 /**
160 Sends a HAI request to the server. /json/HAI is an alias /json/version.
161
162 ajajOpt is an optional configuration object suitable for passing
163 to sendCommand().
164 */
165 FossilAjaj.prototype.HAI = function(ajajOpt) {
166 this.sendCommand('/json/HAI', undefined, ajajOpt);
167 };
168
169
170 /**
171 Sends a /json/whoami request. Updates this.userName and this.authToken
172

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button