Skip to content

Commit

Permalink
Working on unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nufyoot committed Oct 22, 2014
1 parent 75c6987 commit ddfb128
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 57 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules/
test/test_data.json
.DS_Store
credentials.json
coverage.html
options.json
coverage.html
14 changes: 2 additions & 12 deletions integration/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ var api;

if (process.env.NODE_ENV == 'integration') {
apiDetails = JSON.parse(fs.readFileSync('./integration/credentials.json'));
api = new createsend(apiDetails);
options = JSON.parse(fs.readFileSync('./integration/options.json'));
api = new createsend(apiDetails, options);
} else {
apiDetails = {
apiKey: "981298u298ue98u219e8u2e98u2",
Expand Down Expand Up @@ -46,15 +47,6 @@ describe('Account', function () {
});
});

it('should get your API key', function (done) {
api.getApiKey(apiDetails.siteurl, apiDetails.username, apiDetails.password, function (err, key) {
should.not.exist(err);
should.exist(key.ApiKey);
key.ApiKey.should.equal(apiDetails.apiKey);
done();
});
});

it('should get the list of countries', function (done) {
api.getCountries(function (err, countries) {
should.not.exist(err);
Expand All @@ -69,8 +61,6 @@ describe('Account', function () {
api.getTimezones(function (err, timezones) {
should.not.exist(err);
should.exist(timezones);
timezones.should.have.length(101);
timezones[15].should.equal('(GMT+02:00) Harare, Pretoria');
done();
});
});
Expand Down
19 changes: 10 additions & 9 deletions integration/campaigns.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* The purpose of this file is to test the account functions against a
* The purpose of this file is to test the account functions against a
* CreateSend account. Many of the tests are just to ensure we
* got something valid back from the server
***************************************************************************/
Expand All @@ -13,15 +13,16 @@ var apiDetails;
var api;
var isIntegrationTest = process.env.NODE_ENV == 'integration';

if (isIntegrationTest) {
if (isIntegrationTest) {
apiDetails = JSON.parse(fs.readFileSync('./integration/credentials.json'));
api = new createsend(apiDetails);
options = JSON.parse(fs.readFileSync('./integration/options.json'));
api = new createsend(apiDetails, options);
} else {
apiDetails = {
apiKey: "981298u298ue98u219e8u2e98u2",
siteurl: "",
username: "",
password: ""
apiDetails = {
apiKey: "981298u298ue98u219e8u2e98u2",
siteurl: "",
username: "",
password: ""
};
api = new createsend(apiDetails, {
secure: false,
Expand Down Expand Up @@ -86,4 +87,4 @@ describe('Campaigns', function () {
done();
})
});
});
});
19 changes: 10 additions & 9 deletions integration/lists.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* The purpose of this file is to test the account functions against a
* The purpose of this file is to test the account functions against a
* CreateSend account. Many of the tests are just to ensure we
* got something valid back from the server
***************************************************************************/
Expand All @@ -13,15 +13,16 @@ var apiDetails;
var api;
var isIntegrationTest = process.env.NODE_ENV == 'integration';

if (isIntegrationTest) {
if (isIntegrationTest) {
apiDetails = JSON.parse(fs.readFileSync('./integration/credentials.json'));
api = new createsend(apiDetails);
options = JSON.parse(fs.readFileSync('./integration/options.json'));
api = new createsend(apiDetails, options);
} else {
apiDetails = {
apiKey: "981298u298ue98u219e8u2e98u2",
siteurl: "",
username: "",
password: ""
apiDetails = {
apiKey: "981298u298ue98u219e8u2e98u2",
siteurl: "",
username: "",
password: ""
};
api = new createsend(apiDetails, {
secure: false,
Expand Down Expand Up @@ -190,4 +191,4 @@ describe('Lists', function () {
done();
});
});
})
})
21 changes: 11 additions & 10 deletions integration/subscribers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* The purpose of this file is to test the account functions against a
* The purpose of this file is to test the account functions against a
* CreateSend account. Many of the tests are just to ensure we
* got something valid back from the server
***************************************************************************/
Expand All @@ -13,23 +13,24 @@ var apiDetails;
var api;
var isIntegrationTest = process.env.NODE_ENV == 'integration';

if (isIntegrationTest) {
if (isIntegrationTest) {
apiDetails = JSON.parse(fs.readFileSync('./integration/credentials.json'));
api = new createsend(apiDetails);
options = JSON.parse(fs.readFileSync('./integration/options.json'));
api = new createsend(apiDetails, options);
} else {
apiDetails = {
apiKey: "981298u298ue98u219e8u2e98u2",
siteurl: "",
username: "",
password: ""
apiDetails = {
apiKey: "981298u298ue98u219e8u2e98u2",
siteurl: "",
username: "",
password: ""
};
api = new createsend(apiDetails, {
secure: false,
baseUri: 'localhost:3000'
})
}

describe('Clients', function () {
describe('Subscribers', function () {
var testClient;
var testList;
var testSubscriber;
Expand Down Expand Up @@ -174,4 +175,4 @@ describe('Clients', function () {
done();
})
});
})
})
16 changes: 1 addition & 15 deletions lib/createsend.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,12 @@ function CreateSend (auth, options) {
options = options || {};

var result = {
version: '0.1.0',
version: '0.7.4',
auth: auth,
version: 'v3',
secure: options.secure === undefined ? true : options.secure,
baseUri: options.baseUri || 'api.createsend.com',

getApiKey: function (siteUrl, username, password, callback) {
var uri = ((this.secure) ? 'https' : 'http') + '://' +
this.baseUri + '/api/' + this.version + '/apikey.json';
var self = this;

utils.request(this.secure, { username: username, password: password }, 'GET', uri, { siteurl: siteUrl }, null,
function (err, result) {
if (!err && !this.auth) {
self.auth = { apiKey: result.ApiKey };
}
callback(err, result);
});
},

getCountries: function (callback) {
this.get('countries', null, null, callback);
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Terry Tice <nufyoot@gmail.com>",
"name": "createsend-node",
"description": "A node wrapper for the Campaign Monitor API.",
"version": "0.7.3",
"version": "0.7.4",
"repository": {
"type": "git",
"url": "git://github.com/nufyoot/createsend-node.git"
Expand Down

0 comments on commit ddfb128

Please sign in to comment.