Skip to content

Instantly share code, notes, and snippets.

@grantcarthew
Created March 2, 2019 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grantcarthew/9efa81406cb1d58e4dde5ec2ecc0bd61 to your computer and use it in GitHub Desktop.
Save grantcarthew/9efa81406cb1d58e4dde5ec2ecc0bd61 to your computer and use it in GitHub Desktop.
product.test.js
// product.test.js
const axios = require('axios')
const driver = require('../src/store/driver')
const httpSetup = require('./setup/http-setup')
const log = require('../src/logger')
let listener
beforeAll(async function () {
await driver.connect(global.__MONGO_URI__)
listener = await httpSetup()
})
describe('PUT new product', () => {
test('It should PUT a new product in the database', async () => {
const product = {
_id: driver.objectId(),
name: 'test product',
rrp: '300aud',
viewedAt: new Date(),
createdAt: new Date(),
updatedAt: new Date()
}
const result = await axios.put('/products', product)
expect(result.status).toBe(200)
})
})
describe('GET product list', () => {
test('It should respond to the GET method', async () => {
const result = await axios.get('/products')
expect(result.status).toBe(200)
expect(result.data.payload.length).toBeGreaterThan(0)
})
})
afterAll(async function () {
listener.close()
await driver.disconnect()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment