<commit_before>// Test dependencies are required and exposed in common/bootstrap.js
require('../common/bootstrap');

var builds = [{
  sha: 'ac4d8d8a5bfd671f7f174c2eaa258856bd82fe29',
  released: '2017-05-18T02:21:57.856Z',
  version: '0.0.0'
}, {
  sha: '9a85c84f5a03c715908921baaaa9e7397985bc7f',
  released: '2017-08-12T03:01:57.856Z',
  version: '0.0.1'
}];

exports['controller.update'] = {
  setUp: function(done) {
    this.sandbox = sinon.sandbox.create();
    this.spinnerStart = this.sandbox.stub(log.spinner, 'start');
    this.spinnerStop = this.sandbox.stub(log.spinner, 'stop');
    this.warn = this.sandbox.stub(log, 'warn');
    this.info = this.sandbox.stub(log, 'info');
    this.basic = this.sandbox.stub(log, 'basic');

    this.tessel = TesselSimulator();

    this.getTessel = this.sandbox.stub(Tessel, 'get', (opts) => {
      this.tessel.setLANConnectionPreference(opts.lanPrefer);
      return Promise.resolve(this.tessel);
    });

    this.update = this.sandbox.stub(Tessel.prototype, 'update', () => Promise.resolve());

    this.fetchCurrentBuildInfo = this.sandbox.stub(Tessel.prototype, 'fetchCurrentBuildInfo', () => {
      return Promise.resolve('9a85c84f5a03c715908921baaaa9e7397985bc7f');
    });

    this.requestBuildList = this.sandbox.stub(updates, 'requestBuildList', () => Promise.resolve(builds));

    this.updateTesselWithVersion = this.sandbox.spy(controller, 'updateTesselWithVersion');
    this.closeTesselConnections = this.sandbox.spy(controller, 'closeTesselConnections');

    done();
  },

  tearDown: function(done) {
    this.sandbox.restore();
    this.tessel.mockClose();

    // If builds were reversed, fix them.
    if (builds[0].version === '0.0.1') {
      builds.reverse();
    }
    done();
  },

  listBuilds: function(test) {
    test.expect(5);

    controller.printAvailableUpdates()
      .then(() => {
        test.equal(this.requestBuildList.callCount, 1);
        // Print info that these are log
        // 'Latest builds:'
        test.equal(this.info.callCount, 1);
        // Print each version out
        // `Version: ${build.version}\nPublished: ${published}\n${build.sha}\n`
        test.equal(this.basic.callCount, 2);

        test.equal(
          this.basic.getCall(0).args[0],
          'Version: 0.0.1\nPublished: 8/11/2017, 11:01:57 PM\n9a85c84f5a03c715908921baaaa9e7397985bc7f\n'
        );
        test.equal(
          this.basic.getCall(1).args[0],
          'Version: 0.0.0\nPublished: 5/17/2017, 10:21:57 PM\nac4d8d8a5bfd671f7f174c2eaa258856bd82fe29\n'
        );
        // Finish
        test.done();
      })
      .catch(error => {
        test.ok(false, `printAvailableUpdates failed: ${error.toString()}`);
        test.done();
      });
  },

  listBuildFetchError: function(test) {
    test.expect(2);
<commit_msg>test(update): check version and sha specifically, instead of whole string<commit_after>// Test dependencies are required and exposed in common/bootstrap.js
require('../common/bootstrap');

var builds = [{
  sha: 'ac4d8d8a5bfd671f7f174c2eaa258856bd82fe29',
  released: '2017-05-18T02:21:57.856Z',
  version: '0.0.0'
}, {
  sha: '9a85c84f5a03c715908921baaaa9e7397985bc7f',
  released: '2017-08-12T03:01:57.856Z',
  version: '0.0.1'
}];

exports['controller.update'] = {
  setUp: function(done) {
    this.sandbox = sinon.sandbox.create();
    this.spinnerStart = this.sandbox.stub(log.spinner, 'start');
    this.spinnerStop = this.sandbox.stub(log.spinner, 'stop');
    this.warn = this.sandbox.stub(log, 'warn');
    this.info = this.sandbox.stub(log, 'info');
    this.basic = this.sandbox.stub(log, 'basic');

    this.tessel = TesselSimulator();

    this.getTessel = this.sandbox.stub(Tessel, 'get', (opts) => {
      this.tessel.setLANConnectionPreference(opts.lanPrefer);
      return Promise.resolve(this.tessel);
    });

    this.update = this.sandbox.stub(Tessel.prototype, 'update', () => Promise.resolve());

    this.fetchCurrentBuildInfo = this.sandbox.stub(Tessel.prototype, 'fetchCurrentBuildInfo', () => {
      return Promise.resolve('9a85c84f5a03c715908921baaaa9e7397985bc7f');
    });

    // resolve requestBuildList with a copy of the stubbed data, otherwise the original stub is mutated when sorted
    this.requestBuildList = this.sandbox.stub(updates, 'requestBuildList', () => Promise.resolve(builds.slice()));

    this.updateTesselWithVersion = this.sandbox.spy(controller, 'updateTesselWithVersion');
    this.closeTesselConnections = this.sandbox.spy(controller, 'closeTesselConnections');

    done();
  },

  tearDown: function(done) {
    this.sandbox.restore();
    this.tessel.mockClose();

    // If builds were reversed, fix them.
    if (builds[0].version === '0.0.1') {
      builds.reverse();
    }
    done();
  },

  listBuilds: function(test) {
    test.expect(7);

    controller.printAvailableUpdates()
      .then(() => {
        test.equal(this.requestBuildList.callCount, 1);
        // Print info that these are log
        // 'Latest builds:'
        test.equal(this.info.callCount, 1);
        // Print each version out
        // `Version: ${build.version}\nPublished: ${published}\n${build.sha}\n`
        test.equal(this.basic.callCount, 2);

        const firstCallArgs = this.basic.getCall(0).args[0];
        test.equal(firstCallArgs.startsWith('Version: 0.0.1'), true);
        test.equal(firstCallArgs.includes(builds[1].sha), true);

        const secondCallArgs = this.basic.getCall(1).args[0];
        test.equal(secondCallArgs.startsWith('Version: 0.0.0'), true);
        test.equal(secondCallArgs.includes(builds[0].sha), true);

        // Finish
        test.done();
      })
      .catch(error => {
        test.ok(false, `printAvailableUpdates failed: ${error.toString()}`);
        test.done();
      });
  },

  listBuildFetchError: function(test) {
    test.expect(2);

{'fraction_non_alphanumeric': 0.15952177625960717, 'fraction_numerical': 0.058411614005123826, 'mean_word_length': 3.2838332114118507, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '5069133', 'n_tokens_mistral': 2257, 'n_tokens_neox': 2040, 'n_words': 306}