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

Commit cc4aaac

Browse files
committed
node v4 tests
1 parent 06b92dd commit cc4aaac

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@
2929
"scripts": {
3030
"prepublish": "npm run build",
3131
"build": "buble --output lib --target node:4 --objectAssign assign src",
32-
"test": "npm run build && mocha --require buble/register && standard"
32+
"test": "npm run build && mocha && standard"
3333
}
3434
}

src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
'use strict'
12
const got = require('got')
23
const { parse, serialize } = require('cookie')
34
const props = require('promise-props')
4-
const assign = require('object-assign') // eslint-disable-line no-unused-vars
5+
const assign = require('object-assign')
56

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

@@ -42,7 +43,7 @@ function makeSessionCookieHeader (session) {
4243

4344
function addCookieToHeaders (opts, session) {
4445
if (!opts.headers || !opts.headers.cookie) {
45-
opts.headers = Object.assign(opts.headers || {}, {
46+
opts.headers = assign(opts.headers || {}, {
4647
cookie: makeSessionCookieHeader(session)
4748
})
4849
}

test/test.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/* global describe, it, before */
2+
'use strict'
3+
24
const got = require('got')
3-
const { strictEqual: eq, fail, ok } = require('assert')
5+
const assert = require('assert')
46
const login = require('../lib')
57

68
const host = process.env.PLUG_LOGIN_HOST || 'https://plug.dj'
@@ -17,8 +19,8 @@ describe('plug-login', function () {
1719
})
1820
)
1921

20-
ok(process.env.PLUG_LOGIN_NAME, 'pass your test email in the PLUG_LOGIN_NAME env var')
21-
ok(process.env.PLUG_LOGIN_PASS, 'pass your test password in the PLUG_LOGIN_PASS env var')
22+
assert.ok(process.env.PLUG_LOGIN_NAME, 'pass your test email in the PLUG_LOGIN_NAME env var')
23+
assert.ok(process.env.PLUG_LOGIN_PASS, 'pass your test password in the PLUG_LOGIN_PASS env var')
2224

2325
const args = {
2426
email: process.env.PLUG_LOGIN_NAME,
@@ -28,39 +30,39 @@ describe('plug-login', function () {
2830
const INVALID_EMAIL = 'invalid-email@invalid-domain.com'
2931
const INVALID_PASSWORD = 'not_the_password'
3032
it('cannot login with invalid credentials', () =>
31-
login(INVALID_EMAIL, INVALID_PASSWORD, { host }).then(fail, (result) => {
32-
ok(result)
33+
login(INVALID_EMAIL, INVALID_PASSWORD, { host }).then(assert.fail, (result) => {
34+
assert.ok(result)
3335
})
3436
)
3537

3638
it('can login with valid credentials', () =>
3739
login(args.email, args.password, { host }).then((result) => {
38-
ok(result.session)
40+
assert.ok(result.session)
3941
})
4042
)
4143

4244
it('returns a cookie string that can be used for authenticated requests', () =>
4345
login(args.email, args.password, { host }).then((result) => {
44-
ok(result.session)
46+
assert.ok(result.session)
4547
return got(`${host}/_/users/me`, {
4648
headers: { cookie: result.cookie },
4749
json: true
4850
})
49-
}).then(({ body }) => {
50-
ok(body.data[0].id)
51+
}).then((response) => {
52+
assert.ok(response.body.data[0].id)
5153
})
5254
)
5355

5456
it('can optionally retrieve an auth token', () =>
5557
login(args.email, args.password, { host, authToken: true }).then((result) => {
56-
ok(result.session)
57-
eq(typeof result.token, 'string')
58+
assert.ok(result.session)
59+
assert.strictEqual(typeof result.token, 'string')
5860
})
5961
)
6062

6163
it('can retrieve auth tokens for guest users', () =>
6264
login.guest({ host, authToken: true }).then((result) => {
63-
eq(typeof result.token, 'string')
65+
assert.strictEqual(typeof result.token, 'string')
6466
})
6567
)
6668

@@ -69,6 +71,6 @@ describe('plug-login', function () {
6971
login.user(args.email, args.password, {
7072
host,
7173
_simulateMaintenance: true
72-
}).then(fail, ok)
74+
}).then(assert.fail, assert.ok)
7375
)
7476
})

0 commit comments

Comments
 (0)