'use strict';

require('babel-core/register');
require('babel-polyfill');

const chai = require('chai');
const {expect} = chai;
const assert = require('power-assert');
const {sandbox} = require('sinon');
chai.use(require('sinon-chai'));

describe('CommentAction', () => {
  let NicoAction, NicoStore, CommentAction, CommentStore = null;

  before(() => {
    sandbox.create();
    CommentAction = require('../../app/actions/CommentAction');
    NicoAction = require('../../app/actions/NicoAction');
    NicoStore = require('../../app/stores/NicoStore');
  });

  beforeEach(() => {
    delete require.cache[require.resolve('../../app/stores/CommentStore')];
    CommentStore = require('../../app/stores/CommentStore');
  });

  it('reset all comment', (done) => {
    CommentAction.resetAllComment();
    let comments = CommentStore.getAllComments();
    assert(comments, []);
    done();
  });

  it('get and post comment', (done) => {
    let user = {
      email: process.env.USER_EMAIL,
      password: process.env.PASSWORD
    }
    NicoAction.login(user);
    let login = setInterval(() => {
      if (NicoStore.isLogin()) clearInterval(login);
      NicoAction.fetchLoginStatus();
    }, 300);
    assert(NicoStore.isLogin(), true);
    let viewer = null;
    NicoAction.connect('nsen/hotaru');
    let connect = setInterval(() => {
      if (viewer !== null) {
        CommentAction.postComment(`test${Math.random()}`, {mail: '184'});
        CommentAction.getComment(viewer);
        let comments = CommentStore.getAllComment();
        expect(comments).to.not.equal([]);
        clearInterval(connect);
      }
      viewer = NicoStore.getViewer();
    }, 100);
    done();
  });

  after(() => {
    sandbox.restore();
  });

});

@@ -321,16 +321,27 @@
 entStore
+, Immutable
  = null;
@@ -377,24 +377,62 @@
 x.create();%0A
+    Immutable = require('immutable');%0A
     CommentA
@@ -1175,84 +1175,18 @@
 ()) 
-clearInterval(login);%0A      NicoAction.fetchLoginStatus();%0A    %7D, 300);%0A
+%7B%0A     
    
- 
 asse
@@ -1216,16 +1216,20 @@
  true);%0A
+    
     let 
@@ -1243,16 +1243,20 @@
 = null;%0A
+    
     Nico
@@ -1282,24 +1282,28 @@
 n/hotaru');%0A
+    
     let conn
@@ -1320,32 +1320,36 @@
 nterval(() =%3E %7B%0A
+    
       if (viewer
@@ -1361,32 +1361,36 @@
 null) %7B%0A        
+    
 CommentAction.po
@@ -1439,32 +1439,36 @@
 184'%7D);%0A        
+    
 CommentAction.ge
@@ -1489,24 +1489,28 @@
 r);%0A        
+ 
+   
 let comments
@@ -1550,16 +1550,20 @@
         
+    
 expect(c
@@ -1585,24 +1585,358 @@
 .equal(%5B%5D);%0A
+            CommentAction.fetchNickname(comments%5B0%5D);%0A            let sampleComment = Immutable.fromJS(%7B attr: %7B user_id: 4197870 %7D %7D);%0A            CommentAction.fetchNickname(sampleComment);%0A            let nickname = CommentStore.getNickname(sampleComment.getIn(%5B'attr', 'user_id'%5D));%0A            assert(nickname, 'MaxMEllon');%0A    
         clea
@@ -1957,26 +1957,34 @@
 ect);%0A      
+ 
-%7D%0A
+   %7D%0A    
       viewer
@@ -2017,12 +2017,104 @@
     
-%7D, 1
+    %7D, 100);%0A        clearInterval(login);%0A      %7D%0A      NicoAction.fetchLoginStatus();%0A    %7D, 3
 00);

Fix test