Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #22 from goto-bus-stop/buble
Browse files Browse the repository at this point in the history
Use buble
  • Loading branch information
goto-bus-stop authored Dec 1, 2016
2 parents 38651c1 + cc4aaac commit bae92af
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,22 @@
"bugs": "https://github.com/goto-bus-stop/plug-login/issues",
"author": "René Kooi <rene@kooi.me>",
"engines": {
"node": ">= 0.12"
"node": ">= 4"
},
"dependencies": {
"cookie": "^0.3.1",
"got": "^6.5.0",
"object-assign": "^4.1.0",
"promise-props": "^1.0.0"
},
"devDependencies": {
"babel-cli": "^6.7.7",
"babel-plugin-transform-object-rest-spread": "^6.5.0",
"babel-preset-es2015": "^6.18.0",
"babel-register": "^6.5.0",
"buble": "^0.14.2",
"mocha": "^3.0.2",
"standard": "^8.0.0"
},
"scripts": {
"prepublish": "npm run babel",
"babel": "babel --out-dir lib src",
"test": "mocha --compilers js:babel-register && standard"
"prepublish": "npm run build",
"build": "buble --output lib --target node:4 --objectAssign assign src",
"test": "npm run build && mocha && standard"
}
}
10 changes: 6 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import got from 'got'
import { parse, serialize } from 'cookie'
import props from 'promise-props'
'use strict'
const got = require('got')
const { parse, serialize } = require('cookie')
const props = require('promise-props')
const assign = require('object-assign')

const DEFAULT_HOST = 'https://plug.dj'

Expand Down Expand Up @@ -41,7 +43,7 @@ function makeSessionCookieHeader (session) {

function addCookieToHeaders (opts, session) {
if (!opts.headers || !opts.headers.cookie) {
opts.headers = Object.assign(opts.headers || {}, {
opts.headers = assign(opts.headers || {}, {
cookie: makeSessionCookieHeader(session)
})
}
Expand Down
32 changes: 17 additions & 15 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* global describe, it, before */
import got from 'got'
import { strictEqual as eq, fail, ok } from 'assert'
import login from '../src'
'use strict'

const got = require('got')
const assert = require('assert')
const login = require('../lib')

const host = process.env.PLUG_LOGIN_HOST || 'https://plug.dj'

Expand All @@ -17,8 +19,8 @@ describe('plug-login', function () {
})
)

ok(process.env.PLUG_LOGIN_NAME, 'pass your test email in the PLUG_LOGIN_NAME env var')
ok(process.env.PLUG_LOGIN_PASS, 'pass your test password in the PLUG_LOGIN_PASS env var')
assert.ok(process.env.PLUG_LOGIN_NAME, 'pass your test email in the PLUG_LOGIN_NAME env var')
assert.ok(process.env.PLUG_LOGIN_PASS, 'pass your test password in the PLUG_LOGIN_PASS env var')

const args = {
email: process.env.PLUG_LOGIN_NAME,
Expand All @@ -28,39 +30,39 @@ describe('plug-login', function () {
const INVALID_EMAIL = 'invalid-email@invalid-domain.com'
const INVALID_PASSWORD = 'not_the_password'
it('cannot login with invalid credentials', () =>
login(INVALID_EMAIL, INVALID_PASSWORD, { host }).then(fail, (result) => {
ok(result)
login(INVALID_EMAIL, INVALID_PASSWORD, { host }).then(assert.fail, (result) => {
assert.ok(result)
})
)

it('can login with valid credentials', () =>
login(args.email, args.password, { host }).then((result) => {
ok(result.session)
assert.ok(result.session)
})
)

it('returns a cookie string that can be used for authenticated requests', () =>
login(args.email, args.password, { host }).then((result) => {
ok(result.session)
assert.ok(result.session)
return got(`${host}/_/users/me`, {
headers: { cookie: result.cookie },
json: true
})
}).then(({ body }) => {
ok(body.data[0].id)
}).then((response) => {
assert.ok(response.body.data[0].id)
})
)

it('can optionally retrieve an auth token', () =>
login(args.email, args.password, { host, authToken: true }).then((result) => {
ok(result.session)
eq(typeof result.token, 'string')
assert.ok(result.session)
assert.strictEqual(typeof result.token, 'string')
})
)

it('can retrieve auth tokens for guest users', () =>
login.guest({ host, authToken: true }).then((result) => {
eq(typeof result.token, 'string')
assert.strictEqual(typeof result.token, 'string')
})
)

Expand All @@ -69,6 +71,6 @@ describe('plug-login', function () {
login.user(args.email, args.password, {
host,
_simulateMaintenance: true
}).then(fail, ok)
}).then(assert.fail, assert.ok)
)
})

0 comments on commit bae92af

Please sign in to comment.