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
const mongoose = require('mongoose'); | |
const Schema = mongoose.Schema; | |
const itemSchema = new Schema({ | |
name: { | |
type: String, | |
required: true | |
}, | |
rating: { | |
type: String, |
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
describe('Testing /item endpoint', () => { | |
let sampleItemVal; | |
let findOneStub; | |
const sampleUniqueHash = '1234567891'; | |
beforeEach(() => { | |
sampleItemVal = { | |
name: 'sample item', | |
price: 10, | |
rating: '5', |
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
function getUniqueHash(item) { | |
if (!item) return null; | |
const currentHash = item.hash; | |
let newHash = nanoid(10); | |
while (newHash === currentHash) { | |
newHash = nanoid(10); | |
} | |
return newHash; | |
} |
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
exports.updateItemHash = async function (hash) { | |
try { | |
if (!hash) { | |
throw new Error('Incomplete arguments'); | |
} | |
let item = await Item.findOne({ | |
hash | |
}); | |
item.hash = getUniqueHash(item); |
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
describe('Testing /item endpoint', () => { | |
let sampleItemVal; | |
let findOneStub; | |
beforeEach(() => { | |
sampleItemVal = { | |
name: 'sample item', | |
price: 10, | |
rating: '5', | |
hash: '123456891' |
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
describe('Test /health', () => { | |
before('before', () => { | |
console.log('Ran before all the test suites'); | |
}); | |
after('after', () => { | |
console.log('Ran after all the test suites'); | |
}); | |
beforeEach('beforeEach', () => { |
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
describe('Test /health', () => { | |
describe('Health check on /sync', () => { | |
it('health should be okay', () => { | |
const actualResult = healthCheckSync(); | |
expect(actualResult).to.equal('OK'); | |
}); | |
}); | |
describe('Health check on /async', () => { | |
it('health should be okay', async () => { |
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
"test:watch": "mocha --watch ./src/tests/*.spec.js" |
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
"test": "mocha ./src/tests/*.spec.js" |
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
- describe('Test /health') | |
-- describe('Test /health/sync') | |
-- describe('Test /health/async') |