<commit_before>import assert from 'assert';

import constants from '../../lib/constants';
import Soundcast from '../../lib/Soundcast';


const CLIENT_ID = constants.CLIENT_ID;
const USER_ID = 'hannah_wants';
const QUERY = {
  title: 'Hannah Wants - Mixtape',
  userId: 'hannah_wants',
  regexString: 'mixtape'
};
const REQ = {
  protocol: 'http',
  get: () => 'localhost:3000', // hack so that req.get('host') works during the test
  path: '/soundcast',
  query: QUERY
};


describe("Soundcast", () => {

  describe("#constructor()", () => {
    it("should create an instance", () => {
      var sc = _sc();
      assert.equal(sc.title, QUERY.title);
      assert.equal(sc.userId, QUERY.userId);
      assert.equal(sc.regexString, QUERY.regexString);
    });

    it("should have the right regexString default", () => {
      var noRegexStringQuery = Object.assign({}, QUERY);
      delete noRegexStringQuery.regexString;
      var noRegexStringRequest = Object.assign({}, REQ);
      noRegexStringRequest.query = noRegexStringQuery;
      var sc = new Soundcast(noRegexStringRequest);
      assert.equal(sc.title, QUERY.title);
      assert.equal(sc.userId, QUERY.userId);
      assert.equal(sc.regexString, '.*');
    });
  });

  describe("#getChannelData()", () => {
    it("should get the right channel data", async () => {
      var sc = _sc();

      var channel = await sc.getChannelData();
      assert.equal(channel.title, QUERY.title);
      assert.equal(channel.author, 'Hannah Wants');
      assert.equal(channel.link, 'http://soundcloud.com/hannah_wants');
      assert(channel.description.match(/Hannah Wants/));
      assert.equal(channel.image, 'https://i1.sndcdn.com/avatars-000153476543-el6fm5-t200x200.jpg');

      var track = channel.tracks[channel.tracks.length - 1];
      assert.equal(track.title, 'Hannah Wants: Mixtape 0212');
      assert(track.description.match(/FEBRUARY 2012/));
      assert.equal(track.duration, '01:19:54');
      assert.equal(track.url, 'https://api.soundcloud.com/tracks/36589477/download?client_id=83d37608cef935bb382915730917bb7d');
      assert.equal(track.size, 191695933);
      assert.equal(track.fileFormat, 'mp3');
      assert.equal(track.httpFormat, 'audio/mpeg');
      assert.equal(track.published, 'Tue, 14 Feb 2012 13:56:32 +0000');
    });
  });

  describe("#toXml()", () => {
    it("should output lots of XML", async () => {
      var sc = _sc();
      await sc.getChannelData();

      var xml = sc.toXml();
      assert(xml.length > 1000);
    });<commit_msg>updated tests for streaming urls<commit_after>import assert from 'assert';

import constants from '../../lib/constants';
import Soundcast from '../../lib/Soundcast';


const CLIENT_ID = constants.CLIENT_ID;
const USER_ID = 'hannah_wants';
const QUERY = {
  title: 'H<NAME> - Mixtape',
  userId: 'hannah_wants',
  regexString: 'mixtape'
};
const REQ = {
  protocol: 'http',
  get: () => 'localhost:3000', // hack so that req.get('host') works during the test
  path: '/soundcast',
  query: QUERY
};


describe("Soundcast", () => {

  describe("#constructor()", () => {
    it("should create an instance", () => {
      var sc = _sc();
      assert.equal(sc.title, QUERY.title);
      assert.equal(sc.userId, QUERY.userId);
      assert.equal(sc.regexString, QUERY.regexString);
    });

    it("should have the right regexString default", () => {
      var noRegexStringQuery = Object.assign({}, QUERY);
      delete noRegexStringQuery.regexString;
      var noRegexStringRequest = Object.assign({}, REQ);
      noRegexStringRequest.query = noRegexStringQuery;
      var sc = new Soundcast(noRegexStringRequest);
      assert.equal(sc.title, QUERY.title);
      assert.equal(sc.userId, QUERY.userId);
      assert.equal(sc.regexString, '.*');
    });
  });

  describe("#getChannelData()", () => {
    it("should get the right channel data", async () => {
      var sc = _sc();

      var channel = await sc.getChannelData();
      assert.equal(channel.title, QUERY.title);
      assert.equal(channel.author, '<NAME>');
      assert.equal(channel.link, 'http://soundcloud.com/hannah_wants');
      assert(channel.description.match(/<NAME>/));
      assert.equal(channel.image, 'http://i1.sndcdn.com/avatars-000153476543-el6fm5-t200x200.jpg');

      var track = channel.tracks[channel.tracks.length - 1];
      assert.equal(track.title, 'Hannah Wants: Mixtape 0212');
      assert(track.description.match(/FEBRUARY 2012/));
      assert.equal(track.duration, '01:19:54');
      assert.equal(track.url, 'https://api.soundcloud.com/tracks/36589477/stream?client_id=83d37608cef935bb382915730917bb7d');
      assert.equal(track.size, 1);
      assert.equal(track.fileFormat, 'mp3');
      assert.equal(track.httpFormat, 'audio/mpeg');
      assert.equal(track.published, 'Tue, 14 Feb 2012 13:56:32 +0000');
    });
  });

  describe("#toXml()", () => {
    it("should output lots of XML", async () => {
      var sc = _sc();
      await sc.getChannelData();

      var xml = sc.toXml();
      assert(xml.length > 1000);
    });
{'fraction_non_alphanumeric': 0.16861270532357014, 'fraction_numerical': 0.038393033841282405, 'mean_word_length': 3.3871527777777777, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 26, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1966191', 'n_tokens_mistral': 1809, 'n_tokens_neox': 1639, 'n_words': 319}