<commit_before>"use strict";

var twitter = require("../model/twitter.js");
var config = require('../config.js');
var path = require('path');
var fs = require('fs');
var sinon = require('sinon');
var nock = require('nock');
var should = require('should');


describe("model/twitter",function() {
  var oldGetFunction;
  before(function (bddone){
    config.initialise();
    oldGetFunction = twitter.for_debug_only.twitterClient.get;
    twitter.for_debug_only.twitterClient.get = sinon.spy(function (param,cb){
      if (param.substring(0,15)==="/statuses/show/") {
        var id = param.substring(15,999);
        var r = fs.readFileSync(path.join(__dirname,"data","TwitterStatus-"+id+".json"));
        r = JSON.parse(r);
        return cb(null,r);
      }
      return cb(new Error("API not simulated"));
    });
    bddone();
  });
  after(function (bddone){
    twitter.for_debug_only.twitterClient.get = oldGetFunction;
    bddone();
  });
  it('should expand a twitter collection url with no url in tweet',function (bddone){
    twitter.expandTwitterUrl("https://twitter.com/simonecortesi/status/692635300867092480",function(err,result){
      should.not.exist(err);
      should(result).eql("https://twitter.com/simonecortesi/status/692635300867092480\n\nTweet by <NAME>\nStarting today @WikimediaItalia is the official Local Chapter for Italy for @openstreetmap. Long live OSM!\n(Retweets: 22 Favs: 24)\n");
      bddone();
    });
  });
  it('should expand a twitter collection url with url in tweet',function (bddone){
    nock('http://bit.ly')
      .intercept("/1Ghc7dI","HEAD")
      .reply(301,undefined,{location:"http://discoverspatial.com/courses/qgis-for-beginners"});

    nock('http://discoverspatial.com')
      .intercept("/courses/qgis-for-beginners", "HEAD")
      .reply(200,"OK");

    twitter.expandTwitterUrl("https://twitter.com/mangomap/status/695426961548574722",function(err,result){
      should.not.exist(err);
      should(result).eql("https://twitter.com/mangomap/status/695426961548574722\n\nTweet by MangoMap\nHave you enrolled in our #QGIS for Beginners course on @discoverspatial? It's free! http://discoverspatial.com/courses/qgis-for-beginners\n(Retweets: 10 Favs: 5)\n");
      bddone();
    });
  });
  it('should expand a twitter collection url with no twitter reference',function (bddone){
    twitter.expandTwitterUrl("https://twitter.com/OSMBuildings/status/669252548600139776",function(err,result){
      should.not.exist(err);
      should(result).eql("https://twitter.com/OSMBuildings/status/669252548600139776\n\nTweet by OSM Buildings\nJust saw the ArcGIS city viewer at #ddj meetup. How many working hours were spent for that slow thing?\n(Retweets: 2 Favs: 3)\n");<commit_msg>Fixed issue with markdown test in twitter. Changed tests for #405.<commit_after>"use strict";

var twitter = require("../model/twitter.js");
var config = require('../config.js');
var path = require('path');
var fs = require('fs');
var sinon = require('sinon');
var nock = require('nock');
var should = require('should');


describe("model/twitter",function() {
  var oldGetFunction;
  before(function (bddone){
    config.initialise();
    oldGetFunction = twitter.for_debug_only.twitterClient.get;
    twitter.for_debug_only.twitterClient.get = sinon.spy(function (param,cb){
      if (param.substring(0,15)==="/statuses/show/") {
        var id = param.substring(15,999);
        var r = fs.readFileSync(path.join(__dirname,"data","TwitterStatus-"+id+".json"));
        r = JSON.parse(r);
        return cb(null,r);
      }
      return cb(new Error("API not simulated"));
    });
    bddone();
  });
  after(function (bddone){
    twitter.for_debug_only.twitterClient.get = oldGetFunction;
    bddone();
  });
  it('should expand a twitter collection url with no url in tweet',function (bddone){
    twitter.expandTwitterUrl("https://twitter.com/simonecortesi/status/692635300867092480",function(err,result){
      should.not.exist(err);
      should(result).eql("https://twitter.com/simonecortesi/status/692635300867092480\n\n\nTweet by **<NAME>**\nStarting today @WikimediaItalia is the official Local Chapter for Italy for @openstreetmap. Long live OSM!\n(Retweets: **22** Favs: **24**)\n");
      bddone();
    });
  });
  it('should expand a twitter collection url with url in tweet',function (bddone){
    nock('http://bit.ly')
      .intercept("/1Ghc7dI","HEAD")
      .reply(301,undefined,{location:"http://discoverspatial.com/courses/qgis-for-beginners"});

    nock('http://discoverspatial.com')
      .intercept("/courses/qgis-for-beginners", "HEAD")
      .reply(200,"OK");

    twitter.expandTwitterUrl("https://twitter.com/mangomap/status/695426961548574722",function(err,result){
      should.not.exist(err);
      should(result).eql("https://twitter.com/mangomap/status/695426961548574722\n\n\nTweet by **MangoMap**\nHave you enrolled in our #QGIS for Beginners course on @discoverspatial? It's free! http://discoverspatial.com/courses/qgis-for-beginners\n(Retweets: **10** Favs: **5**)\n");
      bddone();
    });
  });
  it('should expand a twitter collection url with no twitter reference',function (bddone){
    twitter.expandTwitterUrl("https://twitter.com/OSMBuildings/status/669252548600139776",function(err,result){
      should.not.exist(err);
      should(result).eql("https://twitter.com/OSMBuildings/status/669252548600139776\n\n\nTweet by **OSM Buildings**\nJust saw the ArcGIS city viewer at #ddj meetup. How many working hours were spent for that slow thing?\n(Retweets: **2** Favs: **3**)\n");
{'fraction_non_alphanumeric': 0.16214272874348373, 'fraction_numerical': 0.04835520402660435, 'mean_word_length': 4.268939393939394, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 12, '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': '91323', 'n_tokens_mistral': 2069, 'n_tokens_neox': 1852, 'n_words': 349}