1
0
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.7 KiB

15 years ago
var sys = require('sys'),
15 years ago
colors = require('colors'),
xmpp = require('node-xmpp'),
15 years ago
Client = require('../lib/xmpp-client').Client,
15 years ago
conf = require('./conf').conf;
15 years ago
15 years ago
exports.testClientInit = function(test) {
var c = new Client({jid: 'mathieu@gtalk.com', password:'toto'});
15 years ago
test.equals('gtalk.com', c.host);
test.done();
};
15 years ago
/*
15 years ago
exports.testClient = function(test) {
15 years ago
test.expect(3);
var MESSAGE = "Beuha de test!";
var b = new Client(conf.b);
15 years ago
b.addListener('message', function(from, msg, stanza){
sys.debug('Message from ' + from.red + ' : ' + msg.yellow);
test.equals(MESSAGE, msg);
15 years ago
test.done();
});
15 years ago
b.addListener('online', function() {
sys.debug('b is connected'.red);
test.ok(true);
var a = new Client(conf.a);
15 years ago
a.addListener('online', function() {
sys.debug('a is connected'.green);
sys.debug('a presences : ' + JSON.stringify(a.presences).green);
// test.equals('available', a.presences['' + b.jid]);
15 years ago
test.ok(true);
a.message(conf.b.jid, MESSAGE);
});
});
15 years ago
};
15 years ago
*/
14 years ago
/*
15 years ago
exports.testRoom = function(test) {
test.expect(1);
15 years ago
var ROOM = 'mushroom@conference.' + conf.b.jid.split('@')[1];
14 years ago
var MESSAGE = "Hello everybody";
var cpt = 0;
var b = new Client(conf.b, function() {
15 years ago
sys.debug('b is connected'.red);
sys.debug(('enter in ' + ROOM).green);
//console.log(sys.inspect(this, true, null));
15 years ago
var b_room = b.room(ROOM, function(status) {
sys.debug('b room is created'.green);
this.addListener('message', function(from, msg, stanza) {
sys.debug(from.yellow);
test.equals(MESSAGE, msg);
if(MESSAGE == msg) {
test.done();
}
});
var a = new Client(conf.a, function() {
15 years ago
sys.debug('a is connected'.green);
var a_room = a.room(ROOM, function(status) {
sys.debug(status.green);
sys.debug(this.role.green);
14 years ago
this.addListener('message', function(from, msg, stanza) {
sys.debug('message : ' + msg);
});
this.message(MESSAGE);
15 years ago
});
});
15 years ago
});
});
};
14 years ago
*/
exports.testPubSub = function(test) {
14 years ago
var POEMS = 'poems';
var b = new Client(conf.b, function() {
sys.debug('b is connected'.red);
this.addListener('iq:error', function(id, stanza) {
sys.error(stanza.toString().red);
test.done();
});
14 years ago
this.pubsub().node(POEMS, function() {
14 years ago
sys.debug('got my node'.yellow);
14 years ago
sys.debug('node : ' + this.toString().red);
this.suscribe(
14 years ago
function(item) {
sys.debug('MESSAGE PUBSUB : ' + item.toString().yellow);
test.done();
},
function(subsription, id) {
14 years ago
this.publish(new xmpp.Element('entry', {xmlns: 'http://www.w3.org/2005/Atom'})
14 years ago
.c('title').t('blab blah')
.tree());
}
);
});
});
};
14 years ago
/*if(module.id == '.') {
var testrunner = require('nodeunit').reporters.default;
15 years ago
testrunner.run([__filename]);
14 years ago
}*/