UNPKG

2.48 kBJavaScriptView Raw
1var mocha = require('mocha');
2var assert = require('assert');
3var nconf = require('nconf');
4var testingKeys = nconf.env().file({
5 file: __dirname + '/testing_keys.json'
6});
7var util = require('util');
8var merge = require('merge');
9
10var postmark = require('../lib/postmark/index.js');
11
12describe('general client functionality', function() {
13 // allow some of the more intensive tests to take longer.
14 this.timeout(30000);
15 var _client = null;
16
17 beforeEach(function() {
18 _client = new postmark.Client(testingKeys.get('WRITE_TEST_SERVER_TOKEN'));
19 });
20
21 it('properly handles "legacy" options', function() {
22 var client = postmark(testingKeys.get('WRITE_TEST_SERVER_TOKEN'), {
23 testOption: 'asdf',
24 ssl: false
25 });
26
27 assert.notEqual(client, null);
28 assert.equal(testingKeys.get('WRITE_TEST_SERVER_TOKEN'), client.options.apiKey);
29 assert.equal(client.options.testOption, 'asdf');
30 assert.equal(client.options.ssl, false, "ssl should have been set to 'false'");
31 });
32
33 it('constructor assigns options.', function() {
34 assert.equal(_client.options.ssl, true, "ssl should default to 'true'");
35 assert.equal(_client.options.apiKey, testingKeys.get('WRITE_TEST_SERVER_TOKEN'));
36 });
37});
38
39describe('integration test assertion', function() {
40 it('should fail if a non-200 response comes back.', function(done) {
41 // (almost) all of the tests in this project
42 // work on the premise that if we send "good",
43 // data to the server, and we get back a status
44 // of 200, this means the API call worked.
45 //
46 // The clients should also provide a status message
47 // as an error in callbacks if we get anything BUT
48 // a status code of 200, so (almost) all of the tests
49 // in this project simply pass those parameters back to "done",
50 //
51 // Since "done" doesn't care about the second argument, this works
52 // and "done" throws on any error. But, let's go ahead
53 // and assert that here.
54
55 var client = postmark(testingKeys.get('READ_SELENIUM_TEST_SERVER_TOKEN'))
56
57 client.getBounces({
58 count: "invalid count"
59 }, function(err, result) {
60
61 assert.equal(null, result);
62 assert.equal(err.status, 422);
63 assert.equal(err.message, 'Parameter \'count\' should be integer value');
64 done();
65 });
66 });
67});
\No newline at end of file