This file contains 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
// Location: controller/campaign.js | |
const { | |
models: { | |
mongo: { campaign: Campaign } | |
} | |
} = require('@pomona/pomona2-dbmodels') | |
const Joi = require('@hapi/joi') | |
Joi.objectId = require('joi-objectid')(Joi) |
This file contains 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
// Location: controller/__tests__/campaign.mocha.js | |
// LINE CODE 1 - 11 -> https://gist.github.com/edharmowongso/2a052f5b352bbe0dbfeb5a9dce1bdda8 | |
const { | |
CampaignMockedModules: { | |
'@pomona/pomona2-dbmodels': { | |
models: { | |
mongo: { campaign: Campaign } | |
} |
This file contains 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
// Location: controller/__tests__/mocks/campaign.mockedModules.js | |
const proxyquire = require('proxyquire') | |
const sinon = require('sinon') | |
const { | |
mongoose: { | |
Types: { ObjectId } | |
} | |
} = require('mongodb-dbmodels') |
This file contains 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
// Location: controller/campaign.js | |
const Joi = require('@hapi/joi') | |
Joi.objectId = require('joi-objectid')(Joi) | |
exports.GetCampaignsByBrandId = async (req, res, next) => { | |
try { | |
const validatedQuery = await Joi.validate( | |
req.query, | |
Joi.object().keys({ |
This file contains 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
// Location: controller/campaign.js | |
exports.GetCampaignsByBrandId = async (req, res, next) => { | |
return true | |
} |
This file contains 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
// 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 |
This file contains 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
// Location: controller/__tests__/campaign.mocha.js | |
// LINE CODE 1 - 11 -> https://gist.github.com/edharmowongso/2a052f5b352bbe0dbfeb5a9dce1bdda8 | |
describe.only('Campaign Controller test', function() { | |
describe('GetCampaignsByBrandId test', function() { | |
let res, | |
next, | |
wrongId = '5d0e0ef4ea9baa7fb13ddsadfa', | |
fakeId = '5d9afccd7758c65dba4a531c' |
This file contains 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
// Located at app/lib/logger.js | |
const { log, error, warn } = console | |
class Log { | |
constructor(message) { | |
this.message = message | |
} | |
Write() { |
This file contains 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
// Located inside __tests__ folder | |
require('dotenv').config() | |
// Call the mocked modules | |
const { | |
loggerModule: logger | |
} = require('./mocks/logger.mockedModules') | |
// Act as the assertion library |
This file contains 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
// Located at __tests__/mocks/logger.mockedModules.js | |
// Stubbing required depedencies | |
const proxyquire = require('proxyquire') | |
const loggerMockedModules = {} | |
// Force the "real controller" to use this mocked module | |
// controller: reporting_log.js | |
const loggerModule = proxyquire( | |
'../../reporting_log', |
NewerOlder