|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -var testUser, github, user; |
| 3 | +var testUser; |
4 | 4 |
|
5 | 5 | if (typeof window === 'undefined') { |
6 | | - // Module dependencies |
7 | | - var chai = require('chai'); |
8 | 6 | var Github = require('../'); |
| 7 | + var callbackWithError = require('./helpers.js'); |
9 | 8 |
|
10 | 9 | testUser = require('./user.json'); |
11 | 10 |
|
| 11 | + // Module dependencies |
| 12 | + var chai = require('chai'); |
| 13 | + |
12 | 14 | // Use should flavour for Mocha |
13 | 15 | var should = chai.should(); |
14 | 16 | } |
15 | 17 |
|
16 | | -describe('Github constructor', function() { |
| 18 | +describe('Authentication', function() { |
17 | 19 | before(function() { |
18 | 20 | if (typeof window !== 'undefined') testUser = window.__fixtures__['test/user']; |
| 21 | + }); |
19 | 22 |
|
20 | | - github = new Github({ |
| 23 | + it('should authenticate with valid credentials', function(done) { |
| 24 | + var github = new Github({ |
21 | 25 | username: testUser.USERNAME, |
22 | 26 | password: testUser.PASSWORD, |
23 | 27 | auth: 'basic' |
24 | 28 | }); |
| 29 | + var user = github.getUser(); |
25 | 30 |
|
26 | | - user = github.getUser(); |
27 | | - }); |
28 | | - |
29 | | - it('should authenticate and return no errors', function(done) { |
30 | | - user.notifications(function(err) { |
| 31 | + user.notifications(callbackWithError(done, function(err) { |
31 | 32 | should.not.exist(err); |
32 | 33 | done(); |
33 | | - }); |
| 34 | + })); |
34 | 35 | }); |
35 | | -}); |
36 | | - |
37 | | -describe('Github constructor (failing case)', function() { |
38 | | - before(function() { |
39 | | - if (typeof window !== 'undefined') testUser = window.__fixtures__['test/user']; |
40 | 36 |
|
41 | | - github = new Github({ |
| 37 | + it('should fail authentication with invalid credentials', function(done) { |
| 38 | + var github = new Github({ |
42 | 39 | username: testUser.USERNAME, |
43 | 40 | password: 'fake124', |
44 | 41 | auth: 'basic' |
45 | 42 | }); |
46 | | - user = github.getUser(); |
47 | | - }); |
| 43 | + var user = github.getUser(); |
| 44 | + |
| 45 | + user.notifications(callbackWithError(done, function(err) { |
| 46 | + err.status.should.equal(401, 'Return 401 status for bad auth'); |
| 47 | + err.response.data.message.should.equal('Bad credentials'); |
48 | 48 |
|
49 | | - it('should fail authentication and return err', function(done) { |
50 | | - user.notifications(function(err) { |
51 | | - err.request.status.should.equal(401, 'Return 401 status for bad auth'); |
52 | | - JSON.parse(err.request.responseText).message.should.equal('Bad credentials'); |
53 | 49 | done(); |
54 | | - }); |
| 50 | + })); |
55 | 51 | }); |
56 | 52 | }); |
0 commit comments