<commit_before>const { expect } = require('chai')
const { getScope } = require('../util')

const payload = {
  id: `${Date.now()}`,
  status: 'open',
  type: 'stand-alone',
  description: 'A purchase order for 100 items',
  issueDate: '2019-09-13',
  parties: [
    { id: 'gs1:414:943234', type: 'supplier' },
    { id: 'gs1:414:01251', type: 'ship-from' },
    { id: 'gs1:414:NA0193', type: 'ship-to' }
  ],
  lines: [
    {
      id: '00010',
      quantity: 100,
      product: 'gs1:01:00000123456789',
      exportDate: '2019-02-17',
      deliveryDate: '2019-02-20'
    }
  ]
}

module.exports = (scopeType) => {
  describe('Purchase Orders', () => {
    let scope, purchaseOrder

    before(() => {
      scope = getScope(scopeType)
    })

    it('should read all purchase orders', async () => {
      const res = await scope.purchaseOrder().read()

      expect(res).to.be.an('array')
      expect(res).to.have.length.gte(0)
    })

    if (scopeType === 'operator') {
      it('should create a purchase order', async () => {
        purchaseOrder = await scope.purchaseOrder().create(payload)

        expect(purchaseOrder).to.be.an('object')
      })

      it('should read a purchase order', async () => {
        const res = await scope.purchaseOrder(purchaseOrder.id).read()

        expect(res).to.be.an('object')
        expect(res.id).to.equal(purchaseOrder.id)
      })

      it('should update a purchase order', async () => {
        payload.lines[0].quantity = 150
        const res = await scope.purchaseOrder(purchaseOrder.id).update(payload)

        expect(res).to.be.an('object')
        expect(res.tags).to.deep.equal(payload.tags)
      })

      it('should delete a purchaseOrder', async () => {
        await scope.purchaseOrder(purchaseOrder.id).delete()
      })
    }
  })
}<commit_msg>Update entity/purchaseOrders.spec.js<commit_after>const { expect } = require('chai')
const { getScope, mockApi } = require('../util')

const payload = {
  id: `${Date.now()}`,
  status: 'open',
  type: 'stand-alone',
  description: 'A purchase order for 100 items',
  issueDate: '2019-09-13',
  parties: [
    { id: 'gs1:414:943234', type: 'supplier' },
    { id: 'gs1:414:01251', type: 'ship-from' },
    { id: 'gs1:414:NA0193', type: 'ship-to' }
  ],
  lines: [
    {
      id: '00010',
      quantity: 100,
      product: 'gs1:01:00000123456789',
      exportDate: '2019-02-17',
      deliveryDate: '2019-02-20'
    }
  ]
}

module.exports = (scopeType) => {
  describe('Purchase Orders', () => {
    let scope

    before(() => {
      scope = getScope(scopeType)
    })

    it('should read all purchase orders', async () => {
      mockApi().get('/purchaseOrders')
        .reply(200, [payload])

      const res = await scope.purchaseOrder().read()

      expect(res).to.be.an('array')
      expect(res).to.have.length.gte(1)
    })

    if (scopeType === 'operator') {
      it('should create a purchase order', async () => {
        mockApi().post('/purchaseOrders', payload)
          .reply(201, payload)

        const res = await scope.purchaseOrder().create(payload)

        expect(res).to.be.an('object')
      })

      it('should read a purchase order', async () => {
        mockApi().get('/purchaseOrders/purchaseOrderId')
          .reply(200, payload)

        const res = await scope.purchaseOrder('purchaseOrderId').read()

        expect(res).to.be.an('object')
        expect(res.id).to.equal(payload.id)
      })

      it('should update a purchase order', async () => {
        mockApi().put('/purchaseOrders/purchaseOrderId', payload)
          .reply(200, payload)

        const res = await scope.purchaseOrder('purchaseOrderId').update(payload)

        expect(res).to.be.an('object')
        expect(res.tags).to.deep.equal(payload.tags)
      })

      it('should delete a purchaseOrder', async () => {
        mockApi().delete('/purchaseOrders/purchaseOrderId')
          .reply(204)

        await scope.purchaseOrder('purchaseOrderId').delete()
      })
    }
  })
}
{'fraction_non_alphanumeric': 0.17537313432835822, 'fraction_numerical': 0.0445273631840796, 'mean_word_length': 2.6521344232515895, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '5885779', 'n_tokens_mistral': 1443, 'n_tokens_neox': 1313, 'n_words': 246}