first commit
This commit is contained in:
70
server/tests/socket.test.js
Normal file
70
server/tests/socket.test.js
Normal file
@@ -0,0 +1,70 @@
|
||||
const io = require('socket.io-client');
|
||||
const assert = require('chai').assert;
|
||||
|
||||
describe('Plexus Socket Integration Tests', function () {
|
||||
this.timeout(5000);
|
||||
let client;
|
||||
|
||||
before((done) => {
|
||||
client = io('http://localhost:3000');
|
||||
client.on('connect', done);
|
||||
});
|
||||
|
||||
after(() => {
|
||||
client.disconnect();
|
||||
});
|
||||
|
||||
it('should join and broadcast user list', (done) => {
|
||||
client.emit('join', { walletAddress: 'test_wallet', username: 'TestUser' });
|
||||
client.on('userList', (users) => {
|
||||
const user = users.find(u => u.wallet_address === 'test_wallet');
|
||||
assert.exists(user);
|
||||
assert.equal(user.username, 'TestUser');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should send and receive messages', (done) => {
|
||||
const msgData = {
|
||||
channelId: 'nebula',
|
||||
walletAddress: 'test_wallet',
|
||||
content: 'Hello World',
|
||||
txId: 'TX123'
|
||||
};
|
||||
client.emit('sendMessage', msgData);
|
||||
client.on('newMessage', (msg) => {
|
||||
if (msg.content === 'Hello World') {
|
||||
assert.equal(msg.walletAddress, 'test_wallet');
|
||||
assert.equal(msg.txId, 'TX123');
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should toggle reactions', (done) => {
|
||||
const msgData = {
|
||||
channelId: 'nebula',
|
||||
walletAddress: 'test_wallet',
|
||||
content: 'Reaction Test',
|
||||
txId: 'TX_REACT'
|
||||
};
|
||||
|
||||
// Set up listener first
|
||||
client.once('newMessage', (msg) => {
|
||||
const messageId = msg.id;
|
||||
console.log('Received newMessage with ID:', messageId, 'type:', typeof messageId);
|
||||
|
||||
client.emit('toggleReaction', { messageId, walletAddress: 'test_wallet', emoji: '👍' });
|
||||
|
||||
client.on('updateReactions', (data) => {
|
||||
console.log('Received updateReactions for message:', data.messageId, 'type:', typeof data.messageId);
|
||||
if (String(data.messageId) === String(messageId)) {
|
||||
assert.exists(data.reactions);
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
client.emit('sendMessage', msgData);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user