<commit_before>'use strict'; // eslint-disable-line semi

const chai = require('chai')
const chaiAsPromised = require('chai-as-promised')
chai.use(chaiAsPromised)
const expect = chai.expect

const db = require('APP/db')
const Product = require('./product')
const User = require('./user')

describe('Product', () => {
  before('wait for the db', () => db.didSync)

  var frankenstein, dracula, happyUser, grumpyUser
  beforeEach(function(){

    frankenstein = Product.build({
      name: 'Frankenstein',
      imageURLs: ['one', 'two'],
      price: 100.00,
      description: 'Here is a description of Frankenstein. Highly modular monster. Will stalk you to the ends of the earth. Technically his name is Frankensteins monster. Here is a description of Frankenstein. Highly modular monster. Will stalk you to the ends of the earth. Technically his name is Frankensteins monster. Here is a description of Frankenstein. Highly modular monster. Will stalk you to the ends of the earth. Technically his name is Frankensteins monster.',
      stock: 1
    })

    dracula = Product.build({
      name: 'Dracula',
      imageURLs: ['one', 'two'],
      price: 200.00,
      description: 'dracula description.',
      stock: 0
    })

    let creatingFirstUser = User.create({
      firstName: 'Happy',
      lastName: 'GoLucky',
      email: '<EMAIL>'
    })

    let creatingSecondUser = User.create({
      firstName: 'Grumpy',
      lastName: 'McGrumps',
      email: '<EMAIL>'
    })

    return Promise.all([creatingFirstUser, creatingSecondUser])
    .then(([firstUser, secondUser]) => {
      happyUser = firstUser
      grumpyUser = secondUser
    })
  })

  afterEach(function(){
    return Promise.all([
      Product.truncate({cascade: true}),
      User.truncate({cascade: true})
    ])
  })

  describe('price attribute', () => {
    it('cannot be null', () => {
      frankenstein.price = null
      return frankenstein.validate().then(result => {
        expect(result).to.be.an.instanceOf(Error)
        expect(result.message).to.contain('notNull Violation')
      })
    })
    it('has a getter method that trims the decimal to two places', () => {
      frankenstein.price = 12
      return frankenstein.save().then(result => {
        expect(result.price).to.equal(12)
      })
    })
  })

  describe('instance methods', () => {

    describe('addPicture', () => {
        it('adds a new picture', () => {
          return frankenstein.addPicture('three').then(function(updatedFrank){
            expect(updatedFrank.imageURLs[2]).to.equal('three')
          })
        })
      })

    describe('setDefaultPicture', () => {
      it('moves the nth picture to the front', () => {
        return frankenstein.setDefaultPicture(1).then(function(updatedFrank){
          expect(updatedFrank.imageURLs[0]).to.equal('two')
        })
      })
    })

    describe('getAverageRating', () => {
      it('returns the average rating of all reviews on the product', () => {
        return frankenstein.save()
        .then(() => {
          return happyUser.addProductReview(frankenstein, { rating: 5, description: 'it was the best' })
        })
        .then(() => {
          return grumpyUser.addProductReview(frankenstein, { rating: 1, description: 'it was the worst' })
        })
        .then(() => {
          expect(frankenstein.getAverageRating()).to.eventually.equal(3)<commit_msg>fixed merge conflict<commit_after>'use strict'; // eslint-disable-line semi

const chai = require('chai')
const chaiAsPromised = require('chai-as-promised')
chai.use(chaiAsPromised)
const expect = chai.expect

const db = require('APP/db')
const Product = require('./product')
const User = require('./user')

describe('Product', () => {
  before('wait for the db', () => db.didSync)

  var frankenstein, dracula, happyUser, grumpyUser
  beforeEach(function(){

    frankenstein = Product.build({
      name: 'Frankenstein',
      imageURLs: ['one', 'two'],
      price: 100.00,
      description: 'Here is a description of Frankenstein. Highly modular monster. Will stalk you to the ends of the earth. Technically his name is Frankensteins monster. Here is a description of Frankenstein. Highly modular monster. Will stalk you to the ends of the earth. Technically his name is Frankensteins monster. Here is a description of Frankenstein. Highly modular monster. Will stalk you to the ends of the earth. Technically his name is Frankensteins monster.',
      stock: 1
    })

    dracula = Product.build({
      name: 'Dracula',
      imageURLs: ['one', 'two'],
      price: 200.00,
      description: 'dracula description.',
      stock: 0
    })

    let creatingFirstUser = User.create({
      firstName: 'Happy',
      lastName: 'GoLucky',
      email: '<EMAIL>'
    })

    let creatingSecondUser = User.create({
      firstName: 'Grumpy',
      lastName: 'McGrumps',
      email: '<EMAIL>'
    })

    return Promise.all([creatingFirstUser, creatingSecondUser])
    .then(([firstUser, secondUser]) => {
      happyUser = firstUser
      grumpyUser = secondUser
    })
  })

  afterEach(function(){
    return Promise.all([
      Product.truncate({cascade: true}),
      User.truncate({cascade: true})
    ])
  })

  describe('price attribute', () => {
    it('cannot be null', () => {
      frankenstein.price = null
      return frankenstein.validate().then(result => {
        expect(result).to.be.an.instanceOf(Error)
        expect(result.message).to.contain('notNull Violation')
      })
    })
    it('has a getter method that trims the decimal to two places', () => {
      frankenstein.price = 12
      return frankenstein.save().then(result => {
        expect(result.price).to.equal(12)
      })
    })
  })

  describe('instance methods', () => {

    describe('addPicture', () => {
        it('adds a new picture', () => {
          return frankenstein.addPicture('three').then(function(updatedFrank){
            expect(updatedFrank.imageURLs[2]).to.equal('three')
          })
        })
      })

    describe('setDefaultPicture', () => {
      it('moves the nth picture to the front', () => {
        return frankenstein.setDefaultPicture(1).then(function(updatedFrank){
          expect(updatedFrank.imageURLs[0]).to.equal('two')
        })
      })
    })

    describe('getAverageRating', () => {
      it('returns the average rating of all reviews on the product', () => {
        return frankenstein.save()
        .then(() => {
          return happyUser.addProductReview(frankenstein, { rating: 5, description: 'loved it' })
        })
        .then(() => {
          return grumpyUser.addProductReview(frankenstein, { rating: 1, description: 'hated it' })
        })
        .then(() => {
          expect(frankenstein.getAverageRating()).to.eventually.equal(3)
{'fraction_non_alphanumeric': 0.14142604596346495, 'fraction_numerical': 0.00648202710665881, 'mean_word_length': 2.8421052631578947, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 43, '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': '4300240', 'n_tokens_mistral': 2075, 'n_tokens_neox': 1949, 'n_words': 499}