UNPKG

ngrid-electric-login

Version:

Login to the NGrid Electric website using curl

47 lines (45 loc) 1.76 kB
var assert = require('assert') var fs = require('fs') var path = require('path') var should = require('should'); var argv = require('optimist').demand(['username', 'password']).argv var username = argv.username var password = argv.password var currentLogin = { username: username, password: password } var performLogin = require('../../index') describe('Perform Login Integration', function () { this.timeout('400s') this.slow('20s') it('should submit login form and save cookies to a file on disk', function (done) { performLogin(currentLogin, function (err, cookieFilePath) { should.not.exist(err) should.exist(cookieFilePath) assert.ok(fs.existsSync(cookieFilePath), 'cookie file should exist on disk') var cookieFileData = fs.readFileSync(cookieFilePath,'utf8') var pattern = /\.RETAILWEBAUTH/; assert.ok(pattern.test(cookieFileData), 'RETAILWEBAUTH cookie not found, this means the login failed') fs.unlinkSync(cookieFilePath) var outputPath = path.join(__dirname, '../data/cookie.txt') fs.writeFileSync(outputPath, cookieFileData) done() }) }) it('should give error when invalid credentials are used', function (done) { var dummyLogin = { username: 'foo', password: 'bar' } performLogin(dummyLogin, function (err, cookieFilePath) { should.exist(err) should.exist(cookieFilePath) assert.ok(fs.existsSync(cookieFilePath), 'cookie file should exist on disk') var cookieFileData = fs.readFileSync(cookieFilePath,'utf8') var pattern = /\.RETAILWEBAUTH/; assert.ok(!pattern.test(cookieFileData), 'RETAILWEBAUTH cookie found, this means the login succeeded when it should have failed') done() }) }) })