-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
45 lines (37 loc) · 1.43 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const tap = require('tap');
const {
wrapTwitterErrors,
errors: {
ProblemWithAuth,
NotFound
},
codes,
} = require('./index');
const Twit = require('twit');
const t = new Twit({
consumer_key: process.env.TWITTER_CONSUMER_KEY || 'something',
consumer_secret: process.env.TWITTER_CONSUMER_SECRET || 'something',
access_token: process.env.TWITTER_ACCESS_TOKEN || 'something',
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRE || 'something',
});
t.get('statuses/mentions_timeline')
.catch(e => wrapTwitterErrors('statuses/mentions_timeline', e))
.catch(e => {
tap.true(e instanceof ProblemWithAuth);
tap.same(e.code, codes.INVALID_OR_EXPIRED_TOKEN);
});
t.get('nonexistentpath')
.catch(e => wrapTwitterErrors('nonexistentpath', e))
.catch(e => {
tap.true(e instanceof NotFound);
tap.same(e.code, codes.NOT_FOUND);
});
// A simple mock. We want to assert other errors are also propagated.
t.get = () => Promise.reject(new RangeError());
t.get('statuses/mentions_timeline', )
.catch(e => wrapTwitterErrors('statuses/mentions_timeline', e))
.catch(e => {
tap.true(e instanceof RangeError);
});
const fakeResponse = {"message":"Invalid or expired token.","code":89,"allErrors":[{"code":89,"message":"Invalid or expired token."}],"twitterReply":{
"errors":[{"code":89,"message":"Invalid or expired token."}]},"statusCode":401};