Currently, I am utilizing sails.js v0.11.0 and delving into unit testing. While I have a good grasp on testing normal controllers through http requests, I am at a loss on how to approach testing the same calls via socket requests. Any recommendations for helpful resources or sample tests involving sockets would be greatly appreciated.
var assert = require('assert');
var request = require('supertest');
describe('Auth Controller', function () {
describe('#callback()', function () {
it ('Should successfully authenticate passport-local if email and password are valid', function (done) {
// HTTP Request version
request(sails.hooks.http.app)
.post('/auth/local')
.send({
identifier: 'test@example.com',
password: 'admin1234'
})
.expect(200)
.end(function(err) {
done(err);
});
});
it ('Should return error code if email is invalid during passport-local authentication', function (done) {
// HTTP Request version
request(sails.hooks.http.app)
.post('/auth/local')
.send({
identifier: 'invalid_email@example.com',
password: 'admin1234'
})
.expect(403)
.end(function(err) {
done(err);
});
});
it ('Should return error code if password is invalid during passport-local authentication', function (done) {
// HTTP Request version
request(sails.hooks.http.app)
.post('/auth/local')
.send({
identifier: 'test@example.com',
password: 'invalid_password'
})
.expect(403)
.end(function(err) {
done(err);
});
});
// Test with Web Sockets from sails.io
describe('sails.socket', function () {
describe('With default settings', function() {
describe('once connected, socket', function () {
it ('Should successfully authenticate passport-local via web socket if email and password are valid', function (done) {
// Socket version
request(sails.hooks.http.app)
.post('/auth/local')
.send({
identifier: 'socket_test@example.com',
password: 'admin1234'
})
.expect(200)
.end(function(err) {
done(err);
});
});
it ('Should return error code if email is invalid during passport-local authentication via web socket', function (done) {
// Socket version
request(sails.hooks.http.app)
.post('/auth/local')
.send({
identifier: 'invalid_socket_email@example.com',
password: 'admin1234'
})
.expect(403)
.end(function(err) {
done(err);
});
});
it ('Should return error code if password is invalid during passport-local authentication via web socket', function (done) {
// Socket version
request(sails.hooks.http.app)
.post('/auth/local')
.send({
identifier: 'socket_test@example.com',
password: 'invalid_socket_password'
})
.expect(403)
.end(function(err) {
done(err);
});
});
});
});
});
});
});