<commit_before>should = require 'should'
nock = require 'nock'
moment = require 'moment'

connector = require '../server/konnectors/rescuetime'

basepath = '/anapi/data?key=testkey&format=json&perspective=interval&' + \
           'resolution_time=day'

start = moment().subtract('years', 10).format 'YYYY-MM-DD'
end = moment().add('days', 1).format 'YYYY-MM-DD'


# Mock rescue time server.
mock = nock('https://www.rescuetime.com')
    .get(basepath + "&restrict_begin=#{start}&restrict_end=#{end}")
    .reply(200,
        rows: [
          [ '2013-12-21T00:00:00', 7, 1, 'npmjs.org', 'Marketing', 2 ]
          [ '2013-12-21T00:00:00', 3, 1, 'Firefox', 'Browsers', 0 ],
        ]
    )
    .get(basepath + "&restrict_begin=2013-12-21&restrict_end=#{end}")
    .reply 200,
        rows: [
          [ '2013-12-22T00:00:00', 7, 1, 'npmjs.org', 'Marketing', 2 ]
        ]


describe "When I fetch rescuetime data", ->
    before (done) ->
        connector.init (err) =>
            connector.models.activities.destroyAll (err) =>
                should.not.exist err
                done()

    it "It should store two activities", (done) =>
        connector.fetch apikey: 'testkey', (err) =>
            should.not.exist err

            connector.models.activities.all (err, activities) =>
                should.not.exist err
                activities.length.should.equal 2
                done()

    it "The second time it should store one more activity", (done) =>
        connector.fetch apikey: 'testkey', (err) =>
            should.not.exist err

            connector.models.activities.all (err, activities) =>
                should.not.exist err
                activities.length.should.equal 3
                done()<commit_msg>update tests<commit_after>should = require 'should'
nock = require 'nock'
moment = require 'moment'

connector = require '../server/konnectors/rescuetime'

basepath = '/anapi/data?key=testkey&format=json&perspective=interval&' + \
           'resolution_time=day'

start = moment().subtract('years', 10).format 'YYYY-MM-DD'
end = moment().add('days', 1).format 'YYYY-MM-DD'
now = moment().format 'YYYY-MM-DD'


# Mock rescue time server.
mock = nock('https://www.rescuetime.com')
    .get(basepath + "&restrict_begin=#{start}&restrict_end=#{end}")
    .reply(200,
        rows: [
          [ '2013-12-21T00:00:00', 7, 1, 'npmjs.org', 'Marketing', 2 ]
          [ '2013-12-21T00:00:00', 3, 1, 'Firefox', 'Browsers', 0 ],
        ]
    )
    .get(basepath + "&restrict_begin=2013-12-21&restrict_end=#{end}")
    .reply 200,
        rows: [
          [ '2013-12-22T00:00:00', 7, 1, 'npmjs.org', 'Marketing', 2 ]
          [ "#{now}T00:00:00", 7, 1, 'npmjs.org', 'Marketing', 2 ]
        ]
    .get(basepath + "&restrict_begin=#{now}&restrict_end=#{end}")
    .reply 200,
        rows: [
          [ "#{now}T00:00:00", 7, 1, 'npmjs.org', 'Marketing', 2 ]
        ]

describe "When I fetch rescuetime data", ->
    before (done) ->
        connector.init (err) =>
            connector.models.activities.destroyAll (err) =>
                should.not.exist err
                done()

    it "It should store two activities", (done) =>
        connector.fetch apikey: 'testkey', (err) =>
            should.not.exist err

            connector.models.activities.all (err, activities) =>
                should.not.exist err
                activities.length.should.equal 2
                done()

    it "The second time it should store two more activities", (done) =>
        connector.fetch apikey: 'testkey', (err) =>
            should.not.exist err

            connector.models.activities.all (err, activities) =>
                should.not.exist err
                activities.length.should.equal 4
                done()

    it "The third time it should not store any new activities", (done) =>
        connector.fetch apikey: 'testkey', (err) =>
            should.not.exist err

            connector.models.activities.all (err, activities) =>
                should.not.exist err
                activities.length.should.equal 4
                done()
{'fraction_non_alphanumeric': 0.15350877192982457, 'fraction_numerical': 0.039473684210526314, 'mean_word_length': 2.1772445820433437, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '5865909', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1286, 'n_words': 280}