<commit_before>"use strict";

var should = require('should')
  , server = require('../lib/server')
  , express = require('express')
  , request = require('supertest');

describe("The server", function () {
  var fakeStarling, app;

  beforeEach(function () {
    app = express();
    fakeStarling = {
      push: function (queue, message, callback) {
        this.received.push([queue, message]);
        callback();
      },
      received: []
    };

    server(app, fakeStarling)
    app.now = function(){
      return "the-current-time";
    };
  });

  describe("default responses", function () {
    it("responds with a 200", function (done) {
      request(app).get("/reevoomark/track/impression?product_id=bar").expect(200, done);
    });

    it("responds with a gif file", function (done) {
      request(app)
        .get("/reevoomark/track/impression?product_id=bar")
        .expect("Content-Type", 'image/gif', done);
    });

    it("queues a message on the super_poller", function (done) {
      request(app)
        .get("/reevoomark/track/impression?product_id=bar")
        .end(function (val) {
          fakeStarling.received.length.should.equal(1);
          fakeStarling.received[0][0].should.equal('super_poller');
          JSON.stringify(fakeStarling.received[0][1]).should.equal(
            JSON.stringify({name: 'impression', body: {requested_at: "the-current-time", product_id: 'bar'}})
          );
          done(val);
        });
    });

    it("responds with a gif file", function (done) {
      request(app)
        .get("/reevoomark/track/impression?product_id=bar")
        .expect("Content-Type", 'image/gif')
        .end(done);
    });
  });

  function theMessage () {
    return fakeStarling.received[0][1];
  }

  describe("GET /reevoomark/track/miss", function () {
    it("Pushes a message onto the queue", function (done) {
      request(app)
        .get("/reevoomark/track/miss?sku=SKU&retailer_id=1&badge_type=BADGE_TYPE&badge_variant=BADGE_VARIANT")
        .end(function (val) {
          theMessage().should.eql({
            name: 'miss',
            body: {
              requested_at: 'the-current-time',<commit_msg>[+MM] Added test for pushing large amounts of data.<commit_after>"use strict";

var should = require('should')
  , server = require('../lib/server')
  , express = require('express')
  , request = require('supertest');

describe("The server", function () {
  var fakeStarling, app;

  beforeEach(function () {
    app = express();
    fakeStarling = {
      push: function (queue, message, callback) {
        this.received.push([queue, message]);
        callback();
      },
      received: []
    };

    server(app, fakeStarling)
    app.now = function(){
      return "the-current-time";
    };
  });

  describe("default responses", function () {
    it("responds with a 200", function (done) {
      request(app).get("/reevoomark/track/impression?product_id=bar").expect(200, done);
    });

    it("responds with a gif file", function (done) {
      request(app)
        .get("/reevoomark/track/impression?product_id=bar")
        .expect("Content-Type", 'image/gif', done);
    });

    it("queues a message on the super_poller", function (done) {
      request(app)
        .get("/reevoomark/track/impression?product_id=bar")
        .end(function (val) {
          fakeStarling.received.length.should.equal(1);
          fakeStarling.received[0][0].should.equal('super_poller');
          JSON.stringify(fakeStarling.received[0][1]).should.equal(
            JSON.stringify({name: 'impression', body: {requested_at: "the-current-time", product_id: 'bar'}})
          );
          done(val);
        });
    });

    it("queues every message super_poller", function (done) {
      var i = 0;

      function repeated() {
        if (i < 500) {
          i += 1;
          request(app)
            .get("/reevoomark/track/impression?product_id=bar")
            .end(repeated);
        } else {
          fakeStarling.received.length.should.equal(500);
          done();
        }
      }

      repeated();
    });

    it("responds with a gif file", function (done) {
      request(app)
        .get("/reevoomark/track/impression?product_id=bar")
        .expect("Content-Type", 'image/gif')
        .end(done);
    });
  });

  function theMessage () {
    return fakeStarling.received[0][1];
  }

  describe("GET /reevoomark/track/miss", function () {
    it("Pushes a message onto the queue", function (done) {
      request(app)
        .get("/reevoomark/track/miss?sku=SKU&retailer_id=1&badge_type=BADGE_TYPE&badge_variant=BADGE_VARIANT")
        .end(function (val) {
          theMessage().should.eql({
            name: 'miss',
            body: {
              requested_at: 'the-current-time',
{'fraction_non_alphanumeric': 0.16112852664576802, 'fraction_numerical': 0.007523510971786834, 'mean_word_length': 2.593093093093093, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, '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': '4634152', 'n_tokens_mistral': 1541, 'n_tokens_neox': 1492, 'n_words': 268}