Skip to content

Instantly share code, notes, and snippets.

@edharmowongso
Last active September 12, 2020 09:30
Show Gist options
  • Save edharmowongso/2a052f5b352bbe0dbfeb5a9dce1bdda8 to your computer and use it in GitHub Desktop.
Save edharmowongso/2a052f5b352bbe0dbfeb5a9dce1bdda8 to your computer and use it in GitHub Desktop.
First Part (TDD)
// Location: controller/__tests__/campaign.mocha.js
require('dotenv').config()
const chai = require('chai')
const sinon = require('sinon')
const sinonChai = require('sinon-chai')
const deepEqualInAnyOrder = require('deep-equal-in-any-order')
const { mockReq, mockRes } = require('sinon-express-mock')
const { expect } = chai
chai.use(sinonChai)
chai.use(deepEqualInAnyOrder)
const campaignController = require('../campaign')
describe.only('Campaign Controller test', function() {
describe('GetCampaignsByBrandId test', function() {
describe('Joi validation failed', function() {
it('throws error if not sending brand_id attr in request params', async function() {
expect(await campaignController.GetCampaignsByBrandId()).eq(true)
})
it('throws error if sending invalid brand_id attr in request params', async function() {
expect(await campaignController.GetCampaignsByBrandId()).eq(true)
})
})
describe('Joi validation passed', function() {
it('returns expected results', async function() {
expect(await campaignController.GetCampaignsByBrandId()).eq(true)
})
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment