<commit_before>const app = require('../../app');
const request = require('supertest')(app);
const assert = require('assert');
const equal = assert.equal;
const monk = require('monk');
const mongo_config = require('config').get('mongo');

const db = monk(`${mongo_config.hostname}:${mongo_config.port}/${mongo_config.database}`);
const tags_collection = db.get('tags');

describe('With Tag', () => {
  expect_404('no tag query param');
  expect_404('empty tag query param', '?tag=');
  expect_404('unknown tag', '?tag=monkeypunks');
  expect_404('multiple tags found', '?tag=ambiguity');

  expect_redirect('ignore keywords', '?tag=farmers', '?section=farmers');
  expect_redirect('to typed url', '?tag=trout', '?article=trout');

  /////////////////////////////////////////
  before(() => {
    tags_collection.insert(test_tag_data);
  });

  after(() => {
    tags_collection.remove({});
  });
});

const test_tag_data = [
  // ambiguous tag
  {
    'title': 'Ambiguity',
    'tag_type': 'section',
    'tag_id': 'ambiguity'
  },
  {
    'title': 'Ambiguity',
    'tag_type': 'article',
    'tag_id': 'ambiguity'
  },

  // unambiguous, keywords are ignored
  {
    'title': 'Farmers',
    'tag_type': 'section',
    'tag_id': 'farmers'
  },
  {
    'title': 'Farmers',
    'tag_type': 'keyword',
    'tag_id': 'farmers'
  },

  {
    'title': 'Trout',
    'tag_type': 'article',
    'tag_id': 'trout'
  }
];

////////////////////////////////////////
function expect_404(label, query = '') {
  it(`404 when ${label}`, done => {
    request.
      get(`/with_tag.json${query}`).
      expect(404).
      end(done);
  });
} // expect_404

function expect_redirect(label, query, location) {
  it(`redirect when ${label}`, done => {
    request.
      get(`/with_tag.json${query}`).
      expect(302).
      expect('Location', `http://example.org/with_tag.json${location}`).
      end(done);
  });
} // expect redirect
<commit_msg>tweak test labels<commit_after>const app = require('../../app');
const request = require('supertest')(app);
const assert = require('assert');
const equal = assert.equal;
const monk = require('monk');
const mongo_config = require('config').get('mongo');

const db = monk(`${mongo_config.hostname}:${mongo_config.port}/${mongo_config.database}`);
const tags_collection = db.get('tags');

describe('With Tag', () => {
  expect_404('no tag query param');
  expect_404('empty tag query param', '?tag=');
  expect_404('unknown tag', '?tag=monkeypunks');
  expect_404('multiple tag instances found', '?tag=ambiguity');

  expect_redirect('to typed url', '?tag=trout', '?article=trout');
  expect_redirect('to typed url, ignoring keywords', '?tag=farmers', '?section=farmers');
  expect_redirect('to typed url with sort', '?tag=trout&sort=date', '?article=trout&sort=date');
  expect_redirect('to typed url with order by', '?tag=trout&order_by=date', '?article=trout&order_by=date');
  expect_redirect('to typed url with author', '?tag=trout&author=jez', '?article=trout&author=jez');
  expect_redirect('to content type', '?tag=job', '?type=job');

  /////////////////////////////////////////
  before(() => {
    tags_collection.insert(test_tag_data);
  });

  after(() => {
    tags_collection.remove({});
  });
});

const test_tag_data = [
  // ambiguous tag
  {
    'title': 'Ambiguity',
    'tag_type': 'section',
    'tag_id': 'ambiguity'
  },
  {
    'title': 'Ambiguity',
    'tag_type': 'article',
    'tag_id': 'ambiguity'
  },

  // unambiguous, keywords are ignored
  {
    'title': 'Farmers',
    'tag_type': 'section',
    'tag_id': 'farmers'
  },
  {
    'title': 'Farmers',
    'tag_type': 'keyword',
    'tag_id': 'farmers'
  },

  {
    'title': 'Trout',
    'tag_type': 'article',
    'tag_id': 'trout'
  }
];

////////////////////////////////////////
function expect_404(label, query = '') {
  it(`404 when ${label}`, done => {
    request.
      get(`/with_tag.json${query}`).
      expect(404).
      end(done);
  });
} // expect_404

function expect_redirect(label, query, location) {
  it(`redirect ${label}`, done => {
    request.
      get(`/with_tag.json${query}`).
      expect(302).
      expect('Location', `http://example.org/with_tag.json${location}`).
      end(done);
  });
} // expect redirect

{'fraction_non_alphanumeric': 0.236, 'fraction_numerical': 0.012705882352941176, 'mean_word_length': 3.315736040609137, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '3802510', 'n_tokens_mistral': 1495, 'n_tokens_neox': 1440, 'n_words': 274}