dotfiles/node_modules/googleclientlogin/tests/test.js

58 lines
1.9 KiB
JavaScript

/*global console:true, require:true*/
/*jslint indent:2*/
var assert = require('assert');
var IniReader = require('inireader').IniReader;
var GoogleClientLogin = require('../index').GoogleClientLogin;
var userini = new IniReader('/home/ajnasz/.google.ini');
var finishedTests = 0;
userini.on('fileParse', function () {
var account = this.param('account1'), googleAuth;
googleAuth = new GoogleClientLogin({
email: account.email,
password: account.password,
service: 'contacts',
accountType: account.type
});
googleAuth.on(GoogleClientLogin.events.login, function () {
assert.equal(this.getSID().length, 267, 'Something wrong with the SID length');
assert.equal(this.getLSID().length, 267, 'Something wrong with the LSID length');
assert.equal(this.getAuthId().length, 267, 'Something wrong with the AuthId length');
console.log('test 1 finished');
finishedTests++;
// do things with google services
});
googleAuth.on(GoogleClientLogin.events.error, function (e) {
assert.ok(false, 'Login failed!');
console.log('on error: ', e.message);
// damn..
});
googleAuth.login();
});
userini.load();
var googleAuth = new GoogleClientLogin({
email: 'ajnasz@gmail.com',
password: 'foobar',
service: 'contacts',
accountType: GoogleClientLogin.accountTypes.google
});
googleAuth.on(GoogleClientLogin.events.login, function () {
assert.ok(false, 'Login were success, however it should fail!');
console.log('login success');
});
googleAuth.on(GoogleClientLogin.events.error, function (e) {
assert.equal(e.message, GoogleClientLogin.errors.loginFailed);
assert.equal(this.getError(), 'BadAuthentication', 'Wrong error returned');
console.log('test 2 finished');
finishedTests++;
// damn..
});
googleAuth.login();
process.on('exit', function () {
assert.deepEqual(finishedTests, 2, 'finished tests num differs');
});