twit.js (3208B)
1 var assert = require('assert') 2 , Twit = require('../lib/twitter') 3 , config1 = require('../config1') 4 5 describe('twit', function () { 6 describe('instantiation', function () { 7 it('works with var twit = new Twit()', function () { 8 var twit = new Twit({ 9 consumer_key: 'a', 10 consumer_secret: 'b', 11 access_token: 'c', 12 access_token_secret: 'd' 13 }); 14 assert(twit.config) 15 assert.equal(typeof twit.get, 'function') 16 assert.equal(typeof twit.post, 'function') 17 assert.equal(typeof twit.stream, 'function') 18 }) 19 it('works with var twit = Twit()', function () { 20 var twit = Twit({ 21 consumer_key: 'a', 22 consumer_secret: 'b', 23 access_token: 'c', 24 access_token_secret: 'd' 25 }); 26 assert(twit.config) 27 assert.equal(typeof twit.get, 'function') 28 assert.equal(typeof twit.post, 'function') 29 assert.equal(typeof twit.stream, 'function') 30 }) 31 }) 32 33 describe('config', function () { 34 it('throws when passing empty config', function (done) { 35 assert.throws(function () { 36 var twit = new Twit({}) 37 }, Error) 38 39 done() 40 }) 41 42 it('throws when config is missing a required key', function (done) { 43 assert.throws(function () { 44 var twit = new Twit({ 45 consumer_key: 'a' 46 , consumer_secret: 'a' 47 , access_token: 'a' 48 }) 49 }, Error) 50 51 done() 52 }) 53 54 it('throws when config provides all keys but they\'re empty strings', function (done) { 55 assert.throws(function () { 56 var twit = new Twit({ 57 consumer_key: '' 58 , consumer_secret: '' 59 , access_token: '' 60 , access_token_secret: '' 61 }) 62 }, Error) 63 64 done() 65 }) 66 67 it('throws when config provides invalid strictSSL option', function (done) { 68 assert.throws(function () { 69 var twit = new Twit({ 70 consumer_key: 'a' 71 , consumer_secret: 'a' 72 , access_token: 'a' 73 , access_token_secret: 'a' 74 , strictSSL: 'a' 75 }) 76 }, Error) 77 78 done() 79 }) 80 }) 81 82 describe('setAuth()', function () { 83 var twit; 84 85 beforeEach(function () { 86 twit = new Twit({ 87 consumer_key: 'a', 88 consumer_secret: 'b', 89 access_token: 'c', 90 access_token_secret: 'd' 91 }) 92 }) 93 94 it('should update the client\'s auth config', function (done) { 95 // partial update 96 twit.setAuth({ 97 consumer_key: 'x', 98 consumer_secret: 'y' 99 }) 100 101 assert(twit.config.consumer_key === 'x') 102 assert(twit.config.consumer_secret === 'y') 103 104 // full update 105 twit.setAuth(config1) 106 107 assert(twit.config.consumer_key === config1.consumer_key) 108 assert(twit.config.consumer_secret === config1.consumer_secret) 109 assert(twit.config.access_token === config1.access_token) 110 assert(twit.config.access_token_secret === config1.access_token_secret) 111 112 twit.get('account/verify_credentials', { twit_options: { retry: true } }, function (err, reply, response) { 113 assert(!err, err); 114 assert(response.headers['x-rate-limit-limit']) 115 done() 116 }) 117 }) 118 }) 119 });