'use strict';

import assert from 'power-assert';
import nock from 'nock';

import GitHubAPI from 'github';
import {GitHubClient} from '../lib/github_client';

let sut;
describe('GitHubClient', () => {

  beforeEach(() => {
    const api = new GitHubAPI();

    api.authenticate({
      type: 'token',
      token: 'GITHUB_TOKEN'
    });

    sut = new GitHubClient(api);
  });

  it('set auth info', () => {
    assert(sut.client.auth.type === 'token');
    assert(sut.client.auth.token === 'GITHUB_TOKEN');
  });

  describe('#getCommitsFromPullRequest', () => {

    nock('https://api.github.com/').
      get('/repos/kompiro/awesome-app/pulls/3/commits').
      reply(200, [
        { sha: 'sha0' },
        { sha: 'sha1' }
      ]);

    it ('returns commits', (done) => {
      sut.getCommitsFromPullRequest('kompiro', 'awesome-app', 3).then((commits) => {
        assert(commits.length === 2);
        assert(commits[0].sha === 'sha0');
        done();
      }).catch(done);
    });
  });

});
@@ -4,24 +4,68 @@
 e strict';%0A%0A
+const context = require('mocha').describe;%0A%0A
 import asser
@@ -611,67 +611,369 @@
     
-nock('https://api.github.com/').%0A      get('/repos/
+const ENTRY_POINT_OF_PR_COMMITS = '/repos/kompiro/awesome-app/pulls/3/commits';%0A%0A    context('no paging', () =%3E %7B%0A      nock('https://api.github.com/').%0A      get(ENTRY_POINT_OF_PR_COMMITS).%0A      reply(200, %5B%0A        %7B sha: 'sha0' %7D,%0A        %7B sha: 'sha1' %7D%0A      %5D);%0A%0A      it ('returns commits', (done) =%3E %7B%0A        sut.getCommitsFromPullRequest('
 kompiro
-/
+', '
 awes
@@ -979,33 +979,620 @@
 some-app
-/pulls/3/commits'
+', 3).then((commits) =%3E %7B%0A          assert(commits.length === 2);%0A          assert(commits%5B0%5D.sha === 'sha0');%0A          done();%0A        %7D).catch(done);%0A      %7D);%0A    %7D);%0A%0A    context('have paging', () =%3E %7B%0A      nock('https://api.github.com/').%0A      get(ENTRY_POINT_OF_PR_COMMITS).%0A      reply(200, %5B%0A        %7B sha: 'sha0' %7D,%0A        %7B sha: 'sha1' %7D%0A      %5D,%7B%0A        Link: %60%3Chttps://api.github.com$%7BENTRY_POINT_OF_PR_COMMITS%7D?page=2%3E; rel=%22next%22,%60 +%0A        %60%3Chttps://api.github.com$%7BENTRY_POINT_OF_PR_COMMITS%7D?page=2%3E; rel=%22last%22%60%0A      %7D).%0A      get(ENTRY_POINT_OF_PR_COMMITS).%0A      query(%7Bpage: 2%7D
 ).%0A     
@@ -1616,33 +1616,33 @@
      %7B sha: 'sha
-0
+2
 ' %7D,%0A        %7B s
@@ -1641,33 +1641,33 @@
      %7B sha: 'sha
-1
+3
 ' %7D%0A      %5D);%0A%0A 
@@ -1665,24 +1665,26 @@
    %5D);%0A%0A    
+  
 it ('returns
@@ -1702,24 +1702,26 @@
 (done) =%3E %7B%0A
+  
       sut.ge
@@ -1793,32 +1793,34 @@
 s) =%3E %7B%0A        
+  
 assert(commits.l
@@ -1821,33 +1821,33 @@
 mits.length === 
-2
+4
 );%0A        asser
@@ -1833,32 +1833,34 @@
 === 4);%0A        
+  
 assert(commits%5B0
@@ -1850,33 +1850,33 @@
  assert(commits%5B
-0
+2
 %5D.sha === 'sha0'
@@ -1865,33 +1865,33 @@
 %5B2%5D.sha === 'sha
-0
+2
 ');%0A        done
@@ -1882,32 +1882,34 @@
 ');%0A        
+ 
+ 
 done();%0A
       %7D).cat
@@ -1892,24 +1892,26 @@
     done();%0A
+  
       %7D).cat
@@ -1924,20 +1924,31 @@
 e);%0A    
+  
 %7D);%0A
+    %7D);%0A%0A
   %7D);%0A%0A%7D

Define spec of paging