<commit_before>import app from '../../../js/app';
import { expect } from 'chai';
import { describe, it, before } from 'mocha';
import Listing from '../../../js/models/listing/Listing';

describe('the Listing model', () => {
  before(function () {
    // creating a dummy polyglot t function, so our
    // model doesn't bomb. It's not critical to these
    // tests that it return an actual translation.
    app.polyglot = {
      t: (str) => str,
    };
  });

  it('throws an error if you attempt to fetcha listing without a guid set.', () => {
    const listing = new Listing({
      slug: 'a-happy-slug',
    });
    let errorThrown = false;

    try {
      listing.fetch();
    } catch (e) {
      errorThrown = true;
    }

    expect(errorThrown).to.equal(true);
  });

  it('throws an error if you attempt to fetch without a slug set' +
      ' on the nested listing model', () => {
    const listing = new Listing({}, { guid: '12345' });

    let errorThrown = false;

    try {
      listing.fetch();
    } catch (e) {
      errorThrown = true;
    }

    expect(errorThrown).to.equal(true);
  });

  it('does not throw an error if you attempt to fetch with a guid and slug both set', () => {
    const listing = new Listing({
      slug: 'a-happy-slug',
    }, { guid: '12345' });

    let errorThrown = false;

    try {
      listing.fetch();
    } catch (e) {
      errorThrown = true;
    }

    expect(errorThrown).to.equal(false);
  });

  it('changes a hash in the response to a listingHash in parse', () => {
    const listing = new Listing({}, { guid: '12345' });
    const parsed = listing.parse({
      hash: 'test',
      listing: {},
    });
    expect(parsed.listingHash).to.equal('test');
  });

  it('converts fiat prices from integer to decimal format in parse', () => {
    const listing = new Listing({}, { guid: '12345' });
    const parsed = listing.parse({
      listing: {
        metadata: {
          pricingCurrency: 'USD',
        },
        item: {
          price: 123,
        },<commit_msg>Update test for hash in listing.<commit_after>import app from '../../../js/app';
import { expect } from 'chai';
import { describe, it, before } from 'mocha';
import Listing from '../../../js/models/listing/Listing';

describe('the Listing model', () => {
  before(function () {
    // creating a dummy polyglot t function, so our
    // model doesn't bomb. It's not critical to these
    // tests that it return an actual translation.
    app.polyglot = {
      t: (str) => str,
    };
  });

  it('throws an error if you attempt to fetcha listing without a guid set.', () => {
    const listing = new Listing({
      slug: 'a-happy-slug',
    });
    let errorThrown = false;

    try {
      listing.fetch();
    } catch (e) {
      errorThrown = true;
    }

    expect(errorThrown).to.equal(true);
  });

  it('throws an error if you attempt to fetch without a slug set' +
      ' on the nested listing model', () => {
    const listing = new Listing({}, { guid: '12345' });

    let errorThrown = false;

    try {
      listing.fetch();
    } catch (e) {
      errorThrown = true;
    }

    expect(errorThrown).to.equal(true);
  });

  it('does not throw an error if you attempt to fetch with a guid and slug both set', () => {
    const listing = new Listing({
      slug: 'a-happy-slug',
    }, { guid: '12345' });

    let errorThrown = false;

    try {
      listing.fetch();
    } catch (e) {
      errorThrown = true;
    }

    expect(errorThrown).to.equal(false);
  });

  it('changes a hash in the response to a hash in parse', () => {
    const listing = new Listing({}, { guid: '12345' });
    const parsed = listing.parse({
      hash: 'test',
      listing: {},
    });
    expect(parsed.hash).to.equal('test');
  });

  it('converts fiat prices from integer to decimal format in parse', () => {
    const listing = new Listing({}, { guid: '12345' });
    const parsed = listing.parse({
      listing: {
        metadata: {
          pricingCurrency: 'USD',
        },
        item: {
          price: 123,
        },
{'fraction_non_alphanumeric': 0.15549005158437731, 'fraction_numerical': 0.011299435028248588, 'mean_word_length': 2.291835084882781, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '5371672', 'n_tokens_mistral': 1317, 'n_tokens_neox': 1245, 'n_words': 397}