UNPKG

2.22 kBJavaScriptView Raw
1var assert = require('assert')
2 , Twit = require('../lib/twitter')
3 , config1 = require('../config1')
4
5describe('twit', function () {
6 describe('config', function () {
7 it('throws when passing empty config', function (done) {
8 assert.throws(function () {
9 var twit = new Twit({})
10 }, Error)
11
12 done()
13 })
14
15 it('throws when config is missing a required key', function (done) {
16 assert.throws(function () {
17 var twit = new Twit({
18 consumer_key: 'a'
19 , consumer_secret: 'a'
20 , access_token: 'a'
21 })
22 }, Error)
23
24 done()
25 })
26
27 it('throws when config provides all keys but they\'re empty strings', function (done) {
28 assert.throws(function () {
29 var twit = new Twit({
30 consumer_key: ''
31 , consumer_secret: ''
32 , access_token: ''
33 , access_token_secret: ''
34 })
35 }, Error)
36
37 done()
38 })
39 })
40
41 describe('setAuth()', function () {
42 var twit;
43
44 beforeEach(function () {
45 twit = new Twit({
46 consumer_key: 'a',
47 consumer_secret: 'b',
48 access_token: 'c',
49 access_token_secret: 'd'
50 })
51 })
52
53 it('should update the client\'s auth config', function (done) {
54 // partial update
55 twit.setAuth({
56 consumer_key: 'x',
57 consumer_secret: 'y'
58 })
59
60 assert(twit.config.consumer_key === 'x')
61 assert(twit.config.consumer_secret === 'y')
62
63 // full update
64 twit.setAuth(config1)
65
66 assert(twit.config.consumer_key === config1.consumer_key)
67 assert(twit.config.consumer_secret === config1.consumer_secret)
68 assert(twit.config.access_token === config1.access_token)
69 assert(twit.config.access_token_secret === config1.access_token_secret)
70
71 twit.get('account/verify_credentials', function (err, reply, response) {
72 assert(!err);
73 assert(response.headers['x-rate-limit-limit'])
74 done()
75 })
76 })
77
78 it('should create a new auth object', function () {
79 var oldAuth = twit.auth;
80
81 twit.setAuth({
82 consumer_key: 'a',
83 consumer_secret: 'b'
84 })
85
86 assert(twit.auth && twit.auth !== oldAuth)
87 })
88 })
89});
\No newline at end of file