import { expect } from 'chai';
import '../../../config/chai/chai.config';

import Immutable from 'immutable';
import * as PSActionFactory from './PermissionsSummaryActionFactory';
import reducer from './PermissionsSummaryReducer';

describe('PermissionsSummaryReducer', function() {
  let INITIAL_STATE;

  beforeEach(function() {
    INITIAL_STATE = reducer(undefined, { type: 'init' }); // QUESTION: Does this jive w/ actual inItial state?
  });

  it('should update isGettingUsersRoles to true', function() {
    const entitySet = {};
    const action = PSActionFactory.getAllUsersAndRolesRequest(entitySet);
    const state = reducer(INITIAL_STATE, action);

    expect(state).to.have.property('isGettingUsersRoles').equal(true);
  });

  it('should update isGettingUsersRoles to false (success case)', function() {
    const users = {};
    const roles = [];
    const action = PSActionFactory.getAllUsersAndRolesSuccess(users, roles);
    const state = reducer(INITIAL_STATE, action);

    expect(state).to.have.property('isGettingUsersRoles').equal(false);
  });

  it('should update allUsersById', function() {
    const users = Immutable.fromJS([{test: 'user1'}, {test: 'user2'}]);
    const roles = Immutable.fromJS([{test: 'role1'}, {test: 'role2'}]);
    const action = PSActionFactory.getAllUsersAndRolesSuccess(users, roles);
    const state = reducer(INITIAL_STATE, action);

    expect(state).to.have.property('allUsersById').equal(users);
  });

  it('should update allRolesList', function() {
    const users = Immutable.fromJS([{test: 'user1'}, {test: 'user2'}]);
    const roles = Immutable.fromJS([{test: 'role1'}, {test: 'role2'}]);
    const action = PSActionFactory.getAllUsersAndRolesSuccess(users, roles);
    const state = reducer(INITIAL_STATE, action);

    expect(state).to.have.property('allRolesList').equal(roles);
  });

  it('should update isGettingUsersRoles to false (failure case)', function() {
    const action = PSActionFactory.getAllUsersAndRolesFailure();
    const state = reducer(INITIAL_STATE, action);

    expect(state).to.have.property('isGettingUsersRoles').equal(false);
  });

  it('should update isGettingAcls to true', function() {
    const entitySet = {};
    const action = PSActionFactory.getAcls(entitySet);
    const state = reducer(INITIAL_STATE, action);

    expect(state).to.have.property('isGettingAcls').equal(true);
  });

  it('should update isGettingAcls to false', function() {
    const entitySetId = '';
    const property = {};
    const action = PSActionFactory.getUserRolePermissionsRequest(entitySetId, property);
    const state = reducer(INITIAL_STATE, action);

    expect(state).to.have.property('isGettingAcls').equal(false);
  });

  it('should update isGettingPermissions to true', function() {
    const entitySetId = '';
    const property = {};
    const action = PSActionFactory.getUserRolePermissionsRequest(entitySetId, property);
    const state = reducer(INITIAL_STATE, action);

    expect(state).to.have.property('isGettingPermissions').equal(true);
  });

  it('should update isGettingPermissions to false (success case)', function() {
    const action = PSActionFactory.getUserRolePermissionsSuccess();
    const state = reducer(INITIAL_STATE, action);

    expect(state).to.have.property('isGettingPermissions').equal(false);
  });

  it('should update isGettingPermissions to false (failure case)', function() {
    const action = PSActionFactory.getUserRolePermissionsFailure();
    const state = reducer(INITIAL_STATE, action);

    expect(state).to.have.property('isGettingPermissions').equal(false);
  });

  // it('should get role permissions', function() {
  //   const property = {title: 'title'};
  //   const data = {};
  //   const action = PSActionFactory.setRolePermissions(property, data);
  //   const permissions = getRolePermissions(action); // TODO: import function
  //   const result = {};
  //
  //   expect(permissions).to.equal(result);
  // })

  // it('should update property role permissions', function() {
  //   const property = {title: 'title'};
  //   const data = {};
  //   const action = PSActionFactory.setRolePermissions(property, data);
  //   const permissions = getRolePermissions(action); // TODO: import function
  //   const state = reducer(INITIAL_STATE, action);
  //
    // expect(state).to.have.deep.property(`propertyPermissions.${property.title}`).equal(permissions);
  // });

  // it('should update entity role permissions', function() {
  //   const property = undefined;
  //   const data = {};
  //   const action = PSActionFactory.setRolePermissions(property, data);
  //   const permissions = getRolePermissions(action); // TODO: import function
  //   const state = reducer(INITIAL_STATE, action);
  //
  //   expect(state).to.have.property('entityRolePermissions').equal(permissions);
  // });

  // TODO: COPY ABOVE TESTS FOR SET USER PERMISSIONS

  it('should reset permissions', function() {
    const action = PSActionFactory.resetPermissions();
    const state = reducer(INITIAL_STATE, action);

    expect(state).to.equal(INITIAL_STATE);
  });
});

@@ -223,16 +223,102 @@
 educer';
+%0Aimport %7B getRolePermissions, getUserPermissions %7D from './PermissionsSummaryHelpers';
 %0A%0Adescri
@@ -3684,27 +3684,24 @@
 e);%0A  %7D);%0A%0A 
- //
  it('should 
@@ -3729,35 +3729,32 @@
 , function() %7B%0A 
- //
    const propert
@@ -3750,32 +3750,39 @@
 nst property = %7B
+%0A      
 title: 'title'%7D;
@@ -3771,39 +3771,41 @@
   title: 'title'
+%0A    
 %7D;%0A 
- //
    const data = 
@@ -3797,39 +3797,316 @@
   const data = %7B
+%0A      authenticatedUserPermissions: %5B%5D,%0A      roleAcls: %7B%0A        Discover: %5B%5D,%0A        Link: %5B'foo'%5D,%0A        Read: %5B%5D,%0A        Write: %5B%5D%0A      %7D,%0A      userAcls: %7B%0A        Discover: %5B%5D,%0A        Link: %5B%5D,%0A        Read: %5B%5D,%0A        Write: %5B'bar'%5D,%0A        Ownder: %5B%5D%0A      %7D%0A    
 %7D;%0A 
- //
    const action 
@@ -4152,35 +4152,32 @@
 operty, data);%0A 
- //
    const permiss
@@ -4214,69 +4214,94 @@
 on);
- // TODO: import function%0A  //   const result = %7B%7D;%0A  //%0A  //
+%0A    const result = %7B%0A      AuthenticatedUser: %5B'None'%5D,%0A      foo: %5B'Link'%5D%0A    %7D;%0A%0A 
    e
@@ -4324,18 +4324,16 @@
 s).to.eq
-ua
 l(result
@@ -4336,22 +4336,20 @@
 sult);%0A 
- //
  %7D)
+;
 %0A%0A  // i

Implement 'should get role permissions' test