<commit_before>/**
 * Copyright (c) 2015 <NAME> (@localnerve), LocalNerve LLC
 * Copyrights licensed under the BSD License. See the accompanying LICENSE file for terms.
 */
/* global describe, it, before, beforeEach */
'use strict';
var expect = require('chai').expect;
var createMockActionContext = require('fluxible/utils').createMockActionContext;
// var MockService = require('fluxible-plugin-fetchr/utils/MockServiceManager');
var ApplicationStore = require('../../../stores/ApplicationStore');
var routes = require('../../../actions/routes');
var routesResponse = require('../../fixtures/routes-response');
var jsonToFluxible = require('../../../utils/transformers').jsonToFluxible;

describe('routes action', function () {
  var context;
  var response;

  before(function() {
    // clone the routesResponse so we don't disrupt it.
    var clone = JSON.parse(JSON.stringify(routesResponse));
    response = jsonToFluxible(clone);
  });

  beforeEach(function () {
    context = createMockActionContext({
      stores: [ApplicationStore]
    });
/*    
    context.service = new MockService();
    context.service.setService('routes', function (method, params, config, callback) {
      if (params.emulateError) {
        return callback(new Error('Things went sour.'));
      }

      callback(null, routesResponse);
    });
*/
  });

  it('should update the ApplicationStore', function (done) {
    var testPage = 'home';
    var params = {
      routes: response
    };

    context.executeAction(routes, params, function (err) {
      if (err) {
        return done(err);
      }

      var pages = context.getStore(ApplicationStore).getPages();

      expect(pages).to.be.an('object');
      expect(pages).to.not.be.empty;
      expect(pages[testPage]).to.be.an('object');

      done();
    });
  });
});<commit_msg>add routes action tests<commit_after>/**
 * Copyright (c) 2015 <NAME> (@localnerve), LocalNerve LLC
 * Copyrights licensed under the BSD License. See the accompanying LICENSE file for terms.
 */
/* global describe, it, beforeEach */
'use strict';

var expect = require('chai').expect;

var createMockActionContext = require('fluxible/utils').createMockActionContext;
var MockService = require('fluxible-plugin-fetchr/utils/MockServiceManager');

var ApplicationStore = require('../../../stores/ApplicationStore');
var routes = require('../../../actions/routes');
var routesResponse = require('../../fixtures/routes-response');
var jsonToFluxible = require('../../../utils/transformers').jsonToFluxible;
var testUtils = require('../../utils/tests');

describe('routes action', function () {
  var context;
  var response;
  var testPage = 'home';

  function checkTestPage() {
    var pages = context.getStore(ApplicationStore).getPages();

    expect(pages).to.be.an('object');
    expect(pages).to.not.be.empty;
    expect(pages[testPage]).to.be.an('object');
  }
  
  // create the action context wired to ApplicationStore
  beforeEach(function () {    
    context = createMockActionContext({
      stores: [ApplicationStore]
    });
  });

  describe('with routes payload', function () {
    var params = {
      routes: null
    };

    // clone the response fixture, set it to a fluxible state.
    beforeEach(function () {      
      response = jsonToFluxible(JSON.parse(JSON.stringify(routesResponse)));
      params.routes = response;
    });

    it('should update the ApplicationStore', function (done) {
      context.executeAction(routes, params, function (err) {
        if (err) {
          return done(err);
        }

        checkTestPage();
        done();
      });
    });

    it('should use a custom transformer if supplied', function (done) {
      var custom;
      
      params.transform = function (input) {
        custom = input;
        return custom;
      };
      
      context.executeAction(routes, params, function (err) {
        if (err) {
          done(err);
        }

        expect(custom).to.be.an('object');
        checkTestPage();
        done();
      });
    });
  });

  describe('without routes payload', function () {
    var fluxibleRoutesFixture;

    // Setup the context.service
    // clone the response fixture, set it to a wire state.
    beforeEach(function () {
      response = JSON.parse(JSON.stringify(routesResponse));
      fluxibleRoutesFixture = jsonToFluxible(response);

      context.service = new MockService();
      context.service.setService('routes', function (method, params, config, callback) {
        if (params.emulateError) {
          return callback(new Error('mock'));
        }
        callback(null, response);
      });
    });

    it('should update the ApplicationStore', function (done) {
      context.executeAction(routes, {}, function (err, fluxibleRoutes) {
        if (err) {
          return done(err);
        }

        testUtils.testTransform(expect, fluxibleRoutes, fluxibleRoutesFixture);
        checkTestPage();
        done();
      });
    });

    it('should throw an error if the service does', function (done) {
      context.executeAction(routes, { emulateError: true }, function (err) {
        expect(err).to.be.instanceof(Error);
        done();
      });
    });
  });
});
{'fraction_non_alphanumeric': 0.1472110408280621, 'fraction_numerical': 0.0015334483419589802, 'mean_word_length': 2.944066515495087, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6174227', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1444, 'n_words': 348}