<commit_before>/* global describe */
/* global it */
/* global beforeEach */
/* global afterEach */

var nock = require('nock');
var assert = require('assert');
var Timeline = require('../lib/timeline');

describe('Timeline', function () {
  'use strict';

  var timeline = null;
  var fakePinData = {
    id: '1234',
    time: new Date(),
    layout: new Timeline.Pin.Layout({
      type: 'genericPin',
      title: 'Title',
      tinyIcon: Timeline.Pin.Icon.PIN
    })
  };
  var fakePin = new Timeline.Pin(fakePinData);

  beforeEach(function (done) {
    timeline = new Timeline({ apiRoot: 'http://timeline_api', apiKey: 'API_KEY' });
    done();
  });

  afterEach(function (done) {
    nock.cleanAll();
    done();
  });

  describe('#sendUserPin', function () {

    it('should respond with an error if userToken is not a string', function (done) {
      timeline.sendUserPin(5, fakePin, function (err) {
        assert.ok(err instanceof Error);
        assert.equal(err.message, 'Expected userToken to be a string.');
        done();
      });
    });

    it('should convert the pin argument to a Pin object', function (done) {
      var timelineApi = nock('http://timeline_api', {
        reqheaders: {
          'X-User-Token': 'USER_TOKEN'
        }
      }).put('/v1/user/pins/1234').reply(200);

      timeline.sendUserPin('USER_TOKEN', fakePinData, function (err) {
        assert.equal(err, null);
        timelineApi.done();
        done();
      });
    });

    it('should throw an an error if callback is not a function', function (done) {
      assert.throws(function () { timeline.sendUserPin('USER_TOKEN', fakePin, 5); });<commit_msg>Add some tests for the Timeline constructor.<commit_after>/* global describe */
/* global it */
/* global beforeEach */
/* global afterEach */

var nock = require('nock');
var assert = require('assert');
var Timeline = require('../lib/timeline');

describe('Timeline', function () {
  'use strict';

  var timeline = null;
  var fakePinData = {
    id: '1234',
    time: new Date(),
    layout: new Timeline.Pin.Layout({
      type: 'genericPin',
      title: 'Title',
      tinyIcon: Timeline.Pin.Icon.PIN
    })
  };
  var fakePin = new Timeline.Pin(fakePinData);

  beforeEach(function (done) {
    timeline = new Timeline({ apiRoot: 'http://timeline_api', apiKey: 'API_KEY' });
    done();
  });

  afterEach(function (done) {
    nock.cleanAll();
    done();
  });

  it('should create with no opts passed', function (done) {
    timeline = new Timeline();
    done();
  });

  it('should set the api key', function (done) {
    timeline = new Timeline({ apiKey: 'TEST_KEY' });
    assert.equal(timeline._apiKey, 'TEST_KEY');
    done();
  });

  it('should use the api key env var as a fallback', function (done) {
    process.env.PEBBLE_TIMELINE_API_KEY = 'TEST_KEY';
    timeline = new Timeline();
    assert.equal(timeline._apiKey, 'TEST_KEY');
    delete process.env.PEBBLE_TIMELINE_API_KEY;
    done();
  });

  it('should set the api root', function (done) {
    timeline = new Timeline({ apiRoot: 'TEST_URL' });
    assert.equal(timeline._apiRoot, 'TEST_URL');
    done();
  });

  it('should use the api root env var as a fallback', function (done) {
    process.env.PEBBLE_TIMELINE_API_ROOT = 'TEST_URL';
    timeline = new Timeline();
    assert.equal(timeline._apiRoot, 'TEST_URL');
    delete process.env.PEBBLE_TIMELINE_API_ROOT;
    done();
  });

  it('should use default api root', function (done) {
    timeline = new Timeline();
    assert.equal(timeline._apiRoot, 'https://timeline-api.getpebble.com');
    done();
  });

  describe('#sendUserPin', function () {

    it('should respond with an error if userToken is not a string', function (done) {
      timeline.sendUserPin(5, fakePin, function (err) {
        assert.ok(err instanceof Error);
        assert.equal(err.message, 'Expected userToken to be a string.');
        done();
      });
    });

    it('should convert the pin argument to a Pin object', function (done) {
      var timelineApi = nock('http://timeline_api', {
        reqheaders: {
          'X-User-Token': 'USER_TOKEN'
        }
      }).put('/v1/user/pins/1234').reply(200);

      timeline.sendUserPin('USER_TOKEN', fakePinData, function (err) {
        assert.equal(err, null);
        timelineApi.done();
        done();
      });
    });

    it('should throw an an error if callback is not a function', function (done) {
      assert.throws(function () { timeline.sendUserPin('USER_TOKEN', fakePin, 5); });
{'fraction_non_alphanumeric': 0.15593895155938953, 'fraction_numerical': 0.0061933200619332, 'mean_word_length': 3.015985790408526, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '3257689', 'n_tokens_mistral': 1456, 'n_tokens_neox': 1417, 'n_words': 369}