<commit_before>'use strict'

const request = require('supertest')
  , { expect } = require('chai')
  , Promise = require('bluebird')
  , db = require('APP/db')
  , { Order, Product, LineItem } = db
  , app = require('APP/server/start')

/* global describe it before beforeEach after afterEach priceAtOrderTime */

describe('Product API', () => {
  before('Await database sync', () => db.didSync)
  after('Sync the tables', () => db.sync({force: true}))

  const blueShoes = {
      name: 'Blue Suede Shoes',
      price: 3500,
      photos: ['http://placehold.it/500x500']
    },
    redShoes = {
      name: 'Red Canvas Shoes',
      price: 4400
    },
    greenTrunks = {
      name: 'Green Trunks',
      price: 100000,
    }

  beforeEach('Add dummy data to tables', () => {
    // Use promise chaining to ensure blueShoes is created before redShoes.
    Product.create(blueShoes)
    .then(() => Product.create(redShoes))
  })

  describe('/api/products', () => {

    it('can GET all products', done => {
      request(app)
      .get('/api/products/')
      .then(res => {
        expect(res.body[0].id).to.equal(1)
        expect(res.body.length).to.equal(2)
        expect(res.status).to.equal(200)
        done()
      })
      .catch(done)
    })

    it('can POST a new product', done => {
      request(app)
      .post('/api/products/')
      .send(greenTrunks)
      .then(res => {
        expect(res.body.name).to.equal('Green Trunks')
        expect(res.status).to.equal(201)
        done()
      })
      .catch(done)
    })

  })

  describe('/api/products/:id', () => {

    it('can GET a specific product by id', done => {
      request(app)
      .get('/api/products/1')
      .then(res => {
        expect(res.body.name).to.equal('Blue Suede Shoes')
        expect(res.body.available).to.be.true
        done()
      })
      .catch(done)
    })

    it('can PUT to update a specific product...', done => {
      request(app)
      .put('/api/products/1')
      .send({
        name: 'Blue Suede Pants'
      })
      .then(res => {
        expect(res.body.name).to.equal('Blue Suede Pants')
        done()
      })
      .catch(done)
    })

    it('...and it can PUT to update that product again', done => {
      request(app)
      .put('/api/products/1')
      .send({
        name: 'Blue Suede Shoes'
      })
      .then(res => {
        expect(res.body.name).to.equal('Blue Suede Shoes')
        done()
      })
      .catch(done)
    })

  })

})
<commit_msg>fix: test suites in common style<commit_after>'use strict'

const request = require('supertest')
  , { expect } = require('chai')
  , Promise = require('bluebird')
  , db = require('APP/db')
  , { Order, Product, LineItem } = db
  , app = require('APP/server/start')

/* global describe it before beforeEach after afterEach priceAtOrderTime */

describe('Product API', () => {
  before('Await database sync', () => db.didSync)
  after('Sync the tables', () => db.sync({force: true}))

  const blueShoes = {
      name: 'Blue Suede Shoes',
      price: 3500,
      photos: ['http://placehold.it/500x500']
    },
    redShoes = {
      name: 'Red Canvas Shoes',
      price: 4400
    },
    greenTrunks = {
      name: 'Green Trunks',
      price: 100000,
    }

  beforeEach('Add dummy data to tables', () => {
    // Use promise chaining to ensure blueShoes is created before redShoes.
    Product.create(blueShoes)
    .then(() => Product.create(redShoes))
  })

  describe('/api/products', () => {

    it('can GET all products', done => {
      request(app)
      .get('/api/products/')
      .then(res => {
        expect(res.body[0].id).to.equal(1)
        expect(res.body.length).to.equal(2)
        expect(res.status).to.equal(200)
        done()
      })
      .catch(done)
    })

    it('can POST a new product', done => {
      request(app)
      .post('/api/products/')
      .send(greenTrunks)
      .then(res => {
        expect(res.body.name).to.equal('Green Trunks')
        expect(res.status).to.equal(201)
        done()
      })
      .catch(done)
    })
  })

  describe('/api/products/:id', () => {

    it('can GET a specific product by id', done => {
      request(app)
      .get('/api/products/1')
      .then(res => {
        expect(res.body.name).to.equal('Blue Suede Shoes')
        expect(res.body.available).to.be.true
        done()
      })
      .catch(done)
    })

    it('can PUT to update a specific product...', done => {
      request(app)
      .put('/api/products/1')
      .send({
        name: 'Blue Suede Pants'
      })
      .then(res => {
        expect(res.body.name).to.equal('Blue Suede Pants')
        done()
      })
      .catch(done)
    })

    it('...and it can PUT to update that product again', done => {
      request(app)
      .put('/api/products/1')
      .send({
        name: 'Blue Suede Shoes'
      })
      .then(res => {
        expect(res.body.name).to.equal('Blue Suede Shoes')
        done()
      })
      .catch(done)
    })
  })
})

{'fraction_non_alphanumeric': 0.17514011208967173, 'fraction_numerical': 0.012810248198558846, 'mean_word_length': 2.0826650215916103, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, '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': '5000033', 'n_tokens_mistral': 1727, 'n_tokens_neox': 1655, 'n_words': 341}