2018-07-02 23:30:14 -04:00
|
|
|
const twitter = require('../lib/Adapters/Auth/twitter');
|
2016-07-23 21:02:45 +02:00
|
|
|
|
2016-11-24 15:47:41 -05:00
|
|
|
describe('Twitter Auth', () => {
|
|
|
|
|
it('should use the proper configuration', () => {
|
2016-07-23 21:02:45 +02:00
|
|
|
// Multiple options, consumer_key found
|
|
|
|
|
expect(twitter.handleMultipleConfigurations({
|
|
|
|
|
consumer_key: 'hello',
|
|
|
|
|
}, [{
|
|
|
|
|
consumer_key: 'hello'
|
|
|
|
|
}, {
|
|
|
|
|
consumer_key: 'world'
|
2017-03-28 15:16:47 -07:00
|
|
|
}]).consumer_key).toEqual('hello');
|
2016-12-01 18:45:49 -08:00
|
|
|
|
2016-07-23 21:02:45 +02:00
|
|
|
// Multiple options, consumer_key not found
|
2016-12-01 18:45:49 -08:00
|
|
|
expect(function(){
|
2016-07-23 21:02:45 +02:00
|
|
|
twitter.handleMultipleConfigurations({
|
|
|
|
|
consumer_key: 'some',
|
|
|
|
|
}, [{
|
|
|
|
|
consumer_key: 'hello'
|
|
|
|
|
}, {
|
|
|
|
|
consumer_key: 'world'
|
|
|
|
|
}]);
|
|
|
|
|
}).toThrow();
|
|
|
|
|
|
|
|
|
|
// Multiple options, consumer_key not found
|
2016-12-01 18:45:49 -08:00
|
|
|
expect(function(){
|
2016-07-23 21:02:45 +02:00
|
|
|
twitter.handleMultipleConfigurations({
|
|
|
|
|
auth_token: 'token',
|
|
|
|
|
}, [{
|
|
|
|
|
consumer_key: 'hello'
|
|
|
|
|
}, {
|
|
|
|
|
consumer_key: 'world'
|
|
|
|
|
}]);
|
|
|
|
|
}).toThrow();
|
|
|
|
|
|
|
|
|
|
// Single configuration and consumer_key set
|
|
|
|
|
expect(twitter.handleMultipleConfigurations({
|
|
|
|
|
consumer_key: 'hello',
|
|
|
|
|
}, {
|
|
|
|
|
consumer_key: 'hello'
|
|
|
|
|
}).consumer_key).toEqual('hello');
|
|
|
|
|
|
|
|
|
|
// General case, only 1 config, no consumer_key set
|
|
|
|
|
expect(twitter.handleMultipleConfigurations({
|
|
|
|
|
auth_token: 'token',
|
|
|
|
|
}, {
|
|
|
|
|
consumer_key: 'hello'
|
|
|
|
|
}).consumer_key).toEqual('hello');
|
|
|
|
|
});
|
2017-03-28 15:16:47 -07:00
|
|
|
|
|
|
|
|
it("Should fail with missing options", (done) => {
|
|
|
|
|
try {
|
|
|
|
|
twitter.validateAuthData({
|
|
|
|
|
consumer_key: 'key',
|
|
|
|
|
consumer_secret: 'secret',
|
|
|
|
|
auth_token: 'token',
|
|
|
|
|
auth_token_secret: 'secret'
|
|
|
|
|
}, undefined);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
jequal(error.message, 'Twitter auth configuration missing');
|
|
|
|
|
done();
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-12-01 18:45:49 -08:00
|
|
|
});
|