Permalink
Browse files

[tests] First pass at relational tests for one-many

  • Loading branch information...
Marak committed Aug 28, 2012
1 parent 690f67a commit 17c7ddb8b673f7837fb67ea8a800cb8377d49919
Showing with 90 additions and 1 deletion.
  1. +90 −1 test/relational/one-many-test.js
@@ -1 +1,90 @@
-// TODO
+/*
+ * one-many-test.js: Tests for `socketful` events
+ *
+ * (C) 2012, Nodejitsu Inc.
+ *
+ */
+
+var assert = require('assert'),
+ vows = require('vows'),
+ socketful = require('../../lib/socketful'),
+ io = require('socket.io-client'),
+ fixtures = require('../fixtures');
+
+var server, client;
+vows.describe('socketful/socketful-api-test').addBatch({
+ 'When using `socketful`': {
+ 'creating a new server with one resource': {
+ topic: function () {
+ server = socketful.createServer([fixtures.Album], {}, this.callback);
+ },
+ 'should return a server': function (err, server) {
+ assert.isObject(server);
+ },
+ 'should contain the correct events': function (err, server) {
+ assert.isObject(server);
+ }
+ }
+ }
+}).addBatch({
+ 'When using `socketful`': {
+ 'running resource tests against the server': {
+ topic: function () {
+ var self = this;
+ client = io.connect('http://localhost:8000');
+ self.callback(null, client);
+ },
+ 'should return a client': function (err, client) {
+ assert.isNull(err);
+ assert.isObject(client);
+ },
+ 'should contain the correct events': function (err, client) {
+ assert.isObject(client);
+ }
+ }
+ }
+ }).addBatch({
+ "creating an album" : {
+ topic: function() {
+ client.emit('album', 'create', { id: "Ill-Communication" }, this.callback);
+ },
+ 'should create a new creature' : function (err, result) {
+ assert.isNull(err)
+ assert.isObject(result)
+ },
+ 'should return the right id' : function (err, result) {
+ console.log(result)
+ assert.equal(result.id, "Ill-Communication");
+ }
+ }
+}).addBatch({
+ "creating a song on that album" : {
+ topic: function() {
+ client.emit('album', 'createSong', { id: "Root-Down", album_id: "Ill-Communication" }, this.callback);
+ },
+ 'should create a new creature' : function (err, result) {
+ assert.isNull(err)
+ assert.isObject(result)
+ },
+ 'should return the right id' : function (err, result) {
+ console.log(result)
+ assert.equal(result.id, "album/Ill-Communication/Root-Down");
+ assert.equal(result.resource, "Song");
+ }
+ }
+}).addBatch({
+ "getting the same album" : {
+ topic: function() {
+ client.emit('album', 'get', { id: "Ill-Communication" }, this.callback);
+ },
+ 'should not error' : function (err, result) {
+ assert.isNull(err)
+ assert.isObject(result)
+ },
+ 'should return the new song' : function (err, result) {
+ assert.equal(result.id, "Ill-Communication");
+ assert.equal(result.song_ids.length, 1);
+ assert.equal(result.song_ids[0], "Root-Down");
+ }
+ }
+}).export(module);

0 comments on commit 17c7ddb

Please sign in to comment.