Created
March 2, 2019 04:31
-
-
Save grantcarthew/9efa81406cb1d58e4dde5ec2ecc0bd61 to your computer and use it in GitHub Desktop.
product.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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