Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 17c7ddb8b673f7837fb67ea8a800cb8377d49919 1 parent 690f67a
authored August 28, 2012

Showing 1 changed file with 90 additions and 1 deletion. Show diff stats Hide diff stats

  1. 91  test/relational/one-many-test.js
91  test/relational/one-many-test.js
... ...
@@ -1 +1,90 @@
1  
-// TODO
  1
+/*
  2
+ * one-many-test.js: Tests for `socketful` events
  3
+ *
  4
+ * (C) 2012, Nodejitsu Inc.
  5
+ *
  6
+ */
  7
+
  8
+var assert = require('assert'),
  9
+   vows = require('vows'),
  10
+   socketful = require('../../lib/socketful'),
  11
+   io = require('socket.io-client'),
  12
+   fixtures = require('../fixtures');
  13
+
  14
+var server, client;
  15
+vows.describe('socketful/socketful-api-test').addBatch({
  16
+ 'When using `socketful`': {
  17
+   'creating a new server with one resource': {
  18
+     topic: function () {
  19
+       server = socketful.createServer([fixtures.Album], {}, this.callback);
  20
+     },
  21
+     'should return a server': function (err, server) {
  22
+       assert.isObject(server);
  23
+     },
  24
+     'should contain the correct events': function (err, server) {
  25
+       assert.isObject(server);
  26
+     }
  27
+   }
  28
+ }
  29
+}).addBatch({
  30
+  'When using `socketful`': {
  31
+    'running resource tests against the server': {
  32
+      topic: function () {
  33
+        var self = this;
  34
+        client = io.connect('http://localhost:8000');
  35
+        self.callback(null, client);
  36
+      },
  37
+      'should return a client': function (err, client) {
  38
+        assert.isNull(err);
  39
+        assert.isObject(client);
  40
+      },
  41
+      'should contain the correct events': function (err, client) {
  42
+        assert.isObject(client);
  43
+      }
  44
+    }
  45
+  }
  46
+ }).addBatch({
  47
+  "creating an album" : {
  48
+    topic: function() {
  49
+      client.emit('album', 'create', { id: "Ill-Communication" }, this.callback);
  50
+    },
  51
+    'should create a new creature' : function (err, result) {
  52
+      assert.isNull(err)
  53
+      assert.isObject(result)
  54
+    },
  55
+    'should return the right id' : function (err, result) {
  56
+      console.log(result)
  57
+      assert.equal(result.id, "Ill-Communication");
  58
+    }
  59
+  }
  60
+}).addBatch({
  61
+  "creating a song on that album" : {
  62
+    topic: function() {
  63
+      client.emit('album', 'createSong', { id: "Root-Down", album_id: "Ill-Communication" }, this.callback);
  64
+    },
  65
+    'should create a new creature' : function (err, result) {
  66
+      assert.isNull(err)
  67
+      assert.isObject(result)
  68
+    },
  69
+    'should return the right id' : function (err, result) {
  70
+      console.log(result)
  71
+      assert.equal(result.id, "album/Ill-Communication/Root-Down");
  72
+      assert.equal(result.resource, "Song");
  73
+    }
  74
+  }
  75
+}).addBatch({
  76
+  "getting the same album" : {
  77
+    topic: function() {
  78
+      client.emit('album', 'get', { id: "Ill-Communication" }, this.callback);
  79
+    },
  80
+    'should not error' : function (err, result) {
  81
+      assert.isNull(err)
  82
+      assert.isObject(result)
  83
+    },
  84
+    'should return the new song' : function (err, result) {
  85
+      assert.equal(result.id, "Ill-Communication");
  86
+      assert.equal(result.song_ids.length, 1);
  87
+      assert.equal(result.song_ids[0], "Root-Down");
  88
+    }
  89
+  }
  90
+}).export(module);

0 notes on commit 17c7ddb

Please sign in to comment.
Something went wrong with that request. Please try again.