Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | minor ajax test code cleanups. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | json |
| Files: | files | file ages | folders |
| SHA1: |
7eb52b23ae3505f8e7fca0be9d08f341 |
| User & Date: | stephan 2011-09-30 17:00:07.139 |
Context
|
2011-10-01
| ||
| 02:12 | Changed /json/login output payload structure. check-in: 88ddf2cbce user: stephan tags: json | |
|
2011-09-30
| ||
| 17:00 | minor ajax test code cleanups. check-in: 7eb52b23ae user: stephan tags: json | |
| 16:36 | Added more integration tests. check-in: 10e677c968 user: stephan tags: json | |
Changes
Changes to ajax/i-test/rhino-test.js.
| ︙ | ︙ | |||
14 15 16 17 18 19 20 |
srcdir+'fossil-ajaj.js'
];
for( var i in includes ) {
load(includes[i]);
}
WhAjaj.Connector.prototype.sendImpl = WhAjaj.Connector.sendImpls.rhino;
TestApp.fossil = new FossilAjaj({
| | | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
srcdir+'fossil-ajaj.js'
];
for( var i in includes ) {
load(includes[i]);
}
WhAjaj.Connector.prototype.sendImpl = WhAjaj.Connector.sendImpls.rhino;
TestApp.fossil = new FossilAjaj({
asynchronous:false, /* rhino-based impl doesn't support async or timeout. */
url:TestApp.serverUrl,
beforeSend:function(req,opt){
if(!TestApp.verbose) return;
print("SENDING REQUEST: AJAJ options="+JSON.stringify(opt));
if(req) print("Request envelope="+WhAjaj.stringify(req));
},
afterSend:function(req,opt){
|
| ︙ | ︙ | |||
41 42 43 44 45 46 47 |
});
})();
/**
Throws an exception of cond is a falsy value.
*/
function assert(cond, descr){
| | | 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
});
})();
/**
Throws an exception of cond is a falsy value.
*/
function assert(cond, descr){
descr = descr || "Undescribed condition.";
if(!cond){
throw new Error("Assertion failed: "+descr);
}else{
print("Assertion OK: "+descr);
}
}
|
| ︙ | ︙ | |||
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
!resp.resultCode.
*/
function assertResponseOK(resp){
assert('object' === typeof resp,'Response is-a object.');
assert( 'string' === typeof resp.fossil, 'Response contains fossil property.');
assert( !resp.resultCode, 'resp.resultCode='+resp.resultCode);
}
function assertResponseError(resp,expectCode){
assert('object' === typeof resp,'Response is-a object.');
assert( 'string' === typeof resp.fossil, 'Response contains fossil property.');
assert( resp.resultCode, 'resp.resultCode='+resp.resultCode);
if(expectCode){
assert( 'FOSSIL-'+expectCode == resp.resultCode, 'Expecting result code '+expectCode );
}
}
function testHAI(){
TestApp.fossil.HAI({
onResponse:function(resp,req){
assertResponseOK(resp);
TestApp.serverVersion = resp.fossil;
}
});
| > > > > > > | 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
!resp.resultCode.
*/
function assertResponseOK(resp){
assert('object' === typeof resp,'Response is-a object.');
assert( 'string' === typeof resp.fossil, 'Response contains fossil property.');
assert( !resp.resultCode, 'resp.resultCode='+resp.resultCode);
}
/**
Asserts that resp is-a Object, resp.fossil is-a string, and
resp.resultCode is a truthy value. If expectCode is set then
it also asserts that (resp.resultCode=='FOSSIL-'+expectCode).
*/
function assertResponseError(resp,expectCode){
assert('object' === typeof resp,'Response is-a object.');
assert( 'string' === typeof resp.fossil, 'Response contains fossil property.');
assert( resp.resultCode, 'resp.resultCode='+resp.resultCode);
if(expectCode){
assert( 'FOSSIL-'+expectCode == resp.resultCode, 'Expecting result code '+expectCode );
}
}
function testHAI(){
TestApp.fossil.HAI({
onResponse:function(resp,req){
assertResponseOK(resp);
TestApp.serverVersion = resp.fossil;
}
});
|
| ︙ | ︙ | |||
123 124 125 126 127 128 129 |
}
testAnonymousLogin.description = 'Perform anonymous login.';
function testAnonWikiList(){
TestApp.fossil.sendCommand('/json/wiki/list',undefined,{
beforeSend:function(req,opt){
TestApp.fossil.ajaj.options.beforeSend(req,opt);
| | | | | | 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
}
testAnonymousLogin.description = 'Perform anonymous login.';
function testAnonWikiList(){
TestApp.fossil.sendCommand('/json/wiki/list',undefined,{
beforeSend:function(req,opt){
TestApp.fossil.ajaj.options.beforeSend(req,opt);
assert( req && (req.authToken==TestApp.fossil.authToken), 'Request envelope contains expected authToken.' );
},
onResponse:function(resp,req){
assertResponseOK(resp);
assert( (typeof [] === typeof resp.payload) && resp.payload.length,
"Wiki list seems to be okay.");
TestApp.wiki.list = resp.payload;
}
});
}
testAnonWikiList.description = 'Fetch wiki list as anonymous user.';
function testAnonLogout(){
TestApp.fossil.logout({
onResponse:function(resp,req){
assertResponseOK(resp);
}
});
TestApp.fossil.logout({
onResponse:function(resp,req){
assertResponseError(resp);
}
});
}
testAnonLogout.description = 'Log out anonymous user.';
(function runAllTests(){
var testList = [
testHAI,
testIAmNobody,
testAnonymousLogin,
testAnonWikiList,
testAnonLogout
];
var i, f;
for( i = 0; i < testList.length; ++i ){
f = testList[i];
try{
print("Running test #"+(i+1)+": "+(f.description || "no description."));
f();
}catch(e){
print("Test failed: "+e);
throw e;
}
}
})();
print("Done!");
|
Changes to ajax/js/fossil-ajaj.js.
| ︙ | ︙ | |||
149 150 151 152 153 154 155 |
catch(e){}
}
if( WhAjaj.isFunction(oldOnResponse) ) {
try { oldOnResponse.apply(thisOpt,[resp,req]); }
catch(e) {}
}
};
| | | | 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
catch(e){}
}
if( WhAjaj.isFunction(oldOnResponse) ) {
try { oldOnResponse.apply(thisOpt,[resp,req]); }
catch(e) {}
}
};
this.sendCommand('/json/logout', undefined, ajajOpt );
};
/**
Sends a HAI request to the server. /json/HAI is an alias /json/version.
ajajOpt is an optional configuration object suitable for passing
to sendCommand().
*/
FossilAjaj.prototype.HAI = function(ajajOpt) {
this.sendCommand('/json/HAI', undefined, ajajOpt);
};
/**
Sends a /json/whoami request. Updates this.userName and this.authToken
based on the response, removing them if the response does not contain
that data.
|
| ︙ | ︙ |