1
1
/* global describe, it, before */
2
+ 'use strict'
3
+
2
4
const got = require ( 'got' )
3
- const { strictEqual : eq , fail , ok } = require ( 'assert' )
5
+ const assert = require ( 'assert' )
4
6
const login = require ( '../lib' )
5
7
6
8
const host = process . env . PLUG_LOGIN_HOST || 'https://plug.dj'
@@ -17,8 +19,8 @@ describe('plug-login', function () {
17
19
} )
18
20
)
19
21
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' )
22
24
23
25
const args = {
24
26
email : process . env . PLUG_LOGIN_NAME ,
@@ -28,39 +30,39 @@ describe('plug-login', function () {
28
30
const INVALID_EMAIL = 'invalid-email@invalid-domain.com'
29
31
const INVALID_PASSWORD = 'not_the_password'
30
32
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 )
33
35
} )
34
36
)
35
37
36
38
it ( 'can login with valid credentials' , ( ) =>
37
39
login ( args . email , args . password , { host } ) . then ( ( result ) => {
38
- ok ( result . session )
40
+ assert . ok ( result . session )
39
41
} )
40
42
)
41
43
42
44
it ( 'returns a cookie string that can be used for authenticated requests' , ( ) =>
43
45
login ( args . email , args . password , { host } ) . then ( ( result ) => {
44
- ok ( result . session )
46
+ assert . ok ( result . session )
45
47
return got ( `${ host } /_/users/me` , {
46
48
headers : { cookie : result . cookie } ,
47
49
json : true
48
50
} )
49
- } ) . then ( ( { body } ) => {
50
- ok ( body . data [ 0 ] . id )
51
+ } ) . then ( ( response ) => {
52
+ assert . ok ( response . body . data [ 0 ] . id )
51
53
} )
52
54
)
53
55
54
56
it ( 'can optionally retrieve an auth token' , ( ) =>
55
57
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' )
58
60
} )
59
61
)
60
62
61
63
it ( 'can retrieve auth tokens for guest users' , ( ) =>
62
64
login . guest ( { host, authToken : true } ) . then ( ( result ) => {
63
- eq ( typeof result . token , 'string' )
65
+ assert . strictEqual ( typeof result . token , 'string' )
64
66
} )
65
67
)
66
68
@@ -69,6 +71,6 @@ describe('plug-login', function () {
69
71
login . user ( args . email , args . password , {
70
72
host,
71
73
_simulateMaintenance : true
72
- } ) . then ( fail , ok )
74
+ } ) . then ( assert . fail , assert . ok )
73
75
)
74
76
} )
0 commit comments