Permalink
Browse files

Added unit tests for MailChimpExportAPI

  • Loading branch information...
1 parent e159d94 commit 78d875087238855f97d68df8b8eb0b10369ea16c @gomfunkel committed Aug 4, 2012
Showing with 113 additions and 0 deletions.
  1. +49 −0 test/MailChimpExportAPI/MailChimpExportAPI.js
  2. +64 −0 test/MailChimpExportAPI/MailChimpExportAPI_v1_0.js
@@ -0,0 +1,49 @@
+var assert = require('assert'),
+ vows = require('vows');
+
+var MailChimpExportAPI = require('mailchimp').MailChimpExportAPI;
+
+vows.describe('MailChimpExportAPI').addBatch({
+
+ 'Instantiating the MailChimp Export API wrapper': {
+
+ 'without any arguments': {
+ topic: function () { return new MailChimpExportAPI() },
+ 'throws an error': function (topic) {
+ assert.throws(topic, Error);
+ assert.strictEqual(topic.message, 'You have to provide an API key for this to work.');
+ }
+ },
+
+ 'with an API key': {
+ topic: function () { return new MailChimpExportAPI('apiKey-dc') },
+ 'successfully creates an instance': function (topic) {
+ assert.isObject(topic);
+ }
+ },
+
+ 'without API key but with parameters': {
+ topic: function () { return new MailChimpExportAPI({ version: '1.0' }) },
+ 'throws an error': function (topic) {
+ assert.throws(topic, Error);
+ }
+ },
+
+ 'with an API key and parameters': {
+ topic: function () { return new MailChimpExportAPI('apiKey-dc', { version: '1.0' }) },
+ 'successfully creates an instance': function (topic) {
+ assert.isObject(topic);
+ }
+ },
+
+ 'with an API key and an unsupported version': {
+ topic: function () { return new MailChimpExportAPI('apiKey-dc', { version: '0.1' }) },
+ 'throws an error': function (topic) {
+ assert.throws(topic, Error);
+ assert.strictEqual(topic.message, 'Version 0.1 of the MailChimp Export API is currently not supported.');
+ }
+ }
+
+ }
+
+}).export(module);
@@ -0,0 +1,64 @@
+var assert = require('assert'),
+ vows = require('vows'),
+ nock = require('nock');
+
+var apiEndpoint = nock('http://dc.api.mailchimp.com:80').get('/export/1.0/campaignSubscriberActivity/?apikey=apiKey-dc')
+ .reply(200, '{\"error\":\"Invalid Campaign ID: \",\"code\":300}')
+ .get('/export/1.0/campaignSubscriberActivity/?apikey=apiKey-dc&id=12345')
+ .reply(200, "{\"user1@domain.tld\":[{\"action\":\"open\",\"timestamp\":\"2012-01-01 00:00:00\",\"url\":null,\"ip\":\"127.0.0.1\"}]}\n{\"user2@domain.tld\":[{\"action\":\"open\",\"timestamp\":\"2012-01-21 01:00:00\",\"url\":null,\"ip\":\"127.0.0.1\"}]}\n")
+ .get('/export/1.0/campaignSubscriberActivity/?apikey=apiKey-dc&id=12345&include_empty=true')
+ .reply(200, "{\"user1@domain.tld\":[{\"action\":\"open\",\"timestamp\":\"2012-01-01 00:00:00\",\"url\":null,\"ip\":\"127.0.0.1\"}]}\n{\"user2@domain.tld\":[{\"action\":\"open\",\"timestamp\":\"2012-01-21 01:00:00\",\"url\":null,\"ip\":\"127.0.0.1\"}]}\n")
+ .get('/export/1.0/campaignSubscriberActivity/?apikey=apiKey-dc&id=12345&include_empty=true')
+ .reply(200, "{\"user1@domain.tld\":[{\"action\":\"open\",\"timestamp\":\"2012-01-01 00:00:00\",\"url\":null,\"ip\":\"127.0.0.1\"}]}\n{\"user2@domain.tld\":[{\"action\":\"open\",\"timestamp\":\"2012-01-21 01:00:00\",\"url\":null,\"ip\":\"127.0.0.1\"}]}\n");
+
+var MailChimpAPI = require('mailchimp').MailChimpExportAPI;
+
+vows.describe('MailChimpExportAPI v1.1').addBatch({
+
+ 'MailChimpExportAPI v1.1 wrapper': {
+
+ 'when instantiated': {
+ topic: function () { return new MailChimpAPI('apiKey-dc', { version : '1.0' }) },
+ 'successfully creates an instance': function (api) {
+ assert.isObject(api);
+ assert.strictEqual(api.version, '1.0');
+ },
+
+ /*** campaignSubscriberActivity ***/
+
+ 'and calling method "campaignSubscriberActivity" with mandatory arguments': {
+ topic: function (api) { api.campaignSubscriberActivity({ id: "12345" }, this.callback) },
+ 'exports subscriber activity for the requested campaign': function (error, data) {
+ assert.isNull(error);
+ assert.isArray(data);
+ }
+ },
+
+ 'and calling method "campaignSubscriberActivity" without mandatory arguments': {
+ topic: function (api) { api.campaignSubscriberActivity(this.callback) },
+ 'returns an error': function (error, data) {
+ assert.instanceOf(error, Error);
+ }
+ },
+
+ 'and calling method "campaignSubscriberActivity" with all arguments': {
+ topic: function (api) { api.campaignSubscriberActivity({ id: "12345", include_empty: "true" }, this.callback) },
+ 'exports subscriber activity for the requested campaign': function (error, data) {
+ assert.isNull(error);
+ assert.isArray(data);
+ }
+ },
+
+ 'and calling method "campaignSubscriberActivity" with superflous arguments': {
+ topic: function (api) { api.campaignSubscriberActivity({ id: "12345", include_empty: "true", superflous: "superflous" }, this.callback) },
+ 'exports subscriber activity for the requested campaign and superflous arguments are discarded': function (error, data) {
+ assert.isNull(error);
+ assert.isArray(data);
+ }
+ }
+
+ }
+
+ }
+
+}).export(module);

0 comments on commit 78d8750

Please sign in to comment.