Fossil SCM
minor ajax test code cleanups.
Commit
7eb52b23ae3505f8e7fca0be9d08f341465584e9
Parent
10e677c968f668f…
2 files changed
+12
-6
+2
-2
+12
-6
| --- ajax/i-test/rhino-test.js | ||
| +++ ajax/i-test/rhino-test.js | ||
| @@ -16,11 +16,11 @@ | ||
| 16 | 16 | for( var i in includes ) { |
| 17 | 17 | load(includes[i]); |
| 18 | 18 | } |
| 19 | 19 | WhAjaj.Connector.prototype.sendImpl = WhAjaj.Connector.sendImpls.rhino; |
| 20 | 20 | 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. */ | |
| 22 | 22 | url:TestApp.serverUrl, |
| 23 | 23 | beforeSend:function(req,opt){ |
| 24 | 24 | if(!TestApp.verbose) return; |
| 25 | 25 | print("SENDING REQUEST: AJAJ options="+JSON.stringify(opt)); |
| 26 | 26 | if(req) print("Request envelope="+WhAjaj.stringify(req)); |
| @@ -43,11 +43,11 @@ | ||
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | 45 | Throws an exception of cond is a falsy value. |
| 46 | 46 | */ |
| 47 | 47 | function assert(cond, descr){ |
| 48 | - descr = descr || "Undescribed condition failed."; | |
| 48 | + descr = descr || "Undescribed condition."; | |
| 49 | 49 | if(!cond){ |
| 50 | 50 | throw new Error("Assertion failed: "+descr); |
| 51 | 51 | }else{ |
| 52 | 52 | print("Assertion OK: "+descr); |
| 53 | 53 | } |
| @@ -86,18 +86,24 @@ | ||
| 86 | 86 | function assertResponseOK(resp){ |
| 87 | 87 | assert('object' === typeof resp,'Response is-a object.'); |
| 88 | 88 | assert( 'string' === typeof resp.fossil, 'Response contains fossil property.'); |
| 89 | 89 | assert( !resp.resultCode, 'resp.resultCode='+resp.resultCode); |
| 90 | 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 | +*/ | |
| 91 | 96 | function assertResponseError(resp,expectCode){ |
| 92 | 97 | assert('object' === typeof resp,'Response is-a object.'); |
| 93 | 98 | assert( 'string' === typeof resp.fossil, 'Response contains fossil property.'); |
| 94 | 99 | assert( resp.resultCode, 'resp.resultCode='+resp.resultCode); |
| 95 | 100 | if(expectCode){ |
| 96 | 101 | assert( 'FOSSIL-'+expectCode == resp.resultCode, 'Expecting result code '+expectCode ); |
| 97 | 102 | } |
| 98 | 103 | } |
| 104 | + | |
| 99 | 105 | function testHAI(){ |
| 100 | 106 | TestApp.fossil.HAI({ |
| 101 | 107 | onResponse:function(resp,req){ |
| 102 | 108 | assertResponseOK(resp); |
| 103 | 109 | TestApp.serverVersion = resp.fossil; |
| @@ -125,21 +131,21 @@ | ||
| 125 | 131 | |
| 126 | 132 | function testAnonWikiList(){ |
| 127 | 133 | TestApp.fossil.sendCommand('/json/wiki/list',undefined,{ |
| 128 | 134 | beforeSend:function(req,opt){ |
| 129 | 135 | 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.' ); | |
| 131 | 137 | }, |
| 132 | 138 | onResponse:function(resp,req){ |
| 133 | 139 | assertResponseOK(resp); |
| 134 | 140 | assert( (typeof [] === typeof resp.payload) && resp.payload.length, |
| 135 | 141 | "Wiki list seems to be okay."); |
| 136 | 142 | TestApp.wiki.list = resp.payload; |
| 137 | 143 | } |
| 138 | 144 | }); |
| 139 | 145 | } |
| 140 | -testAnonWikiList.description = 'Fetch wiki list as anonymous uses.'; | |
| 146 | +testAnonWikiList.description = 'Fetch wiki list as anonymous user.'; | |
| 141 | 147 | |
| 142 | 148 | function testAnonLogout(){ |
| 143 | 149 | TestApp.fossil.logout({ |
| 144 | 150 | onResponse:function(resp,req){ |
| 145 | 151 | assertResponseOK(resp); |
| @@ -149,11 +155,11 @@ | ||
| 149 | 155 | onResponse:function(resp,req){ |
| 150 | 156 | assertResponseError(resp); |
| 151 | 157 | } |
| 152 | 158 | }); |
| 153 | 159 | } |
| 154 | -testAnonLogout.description = 'Fetch wiki list as anonymous uses.'; | |
| 160 | +testAnonLogout.description = 'Log out anonymous user.'; | |
| 155 | 161 | |
| 156 | 162 | (function runAllTests(){ |
| 157 | 163 | var testList = [ |
| 158 | 164 | testHAI, |
| 159 | 165 | testIAmNobody, |
| @@ -163,11 +169,11 @@ | ||
| 163 | 169 | ]; |
| 164 | 170 | var i, f; |
| 165 | 171 | for( i = 0; i < testList.length; ++i ){ |
| 166 | 172 | f = testList[i]; |
| 167 | 173 | try{ |
| 168 | - print("Running #"+(i+1)+": "+(f.description || "no description.")); | |
| 174 | + print("Running test #"+(i+1)+": "+(f.description || "no description.")); | |
| 169 | 175 | f(); |
| 170 | 176 | }catch(e){ |
| 171 | 177 | print("Test failed: "+e); |
| 172 | 178 | throw e; |
| 173 | 179 | } |
| 174 | 180 |
| --- 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 |
+2
-2
| --- ajax/js/fossil-ajaj.js | ||
| +++ ajax/js/fossil-ajaj.js | ||
| @@ -151,21 +151,21 @@ | ||
| 151 | 151 | if( WhAjaj.isFunction(oldOnResponse) ) { |
| 152 | 152 | try { oldOnResponse.apply(thisOpt,[resp,req]); } |
| 153 | 153 | catch(e) {} |
| 154 | 154 | } |
| 155 | 155 | }; |
| 156 | - this.sendCommand('/json/logout', false, ajajOpt ); | |
| 156 | + this.sendCommand('/json/logout', undefined, ajajOpt ); | |
| 157 | 157 | }; |
| 158 | 158 | |
| 159 | 159 | /** |
| 160 | 160 | Sends a HAI request to the server. /json/HAI is an alias /json/version. |
| 161 | 161 | |
| 162 | 162 | ajajOpt is an optional configuration object suitable for passing |
| 163 | 163 | to sendCommand(). |
| 164 | 164 | */ |
| 165 | 165 | FossilAjaj.prototype.HAI = function(ajajOpt) { |
| 166 | - this.sendCommand('/json/HAI', null, ajajOpt); | |
| 166 | + this.sendCommand('/json/HAI', undefined, ajajOpt); | |
| 167 | 167 | }; |
| 168 | 168 | |
| 169 | 169 | |
| 170 | 170 | /** |
| 171 | 171 | Sends a /json/whoami request. Updates this.userName and this.authToken |
| 172 | 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', 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 |