Skip to content

Instantly share code, notes, and snippets.

View Rishabh570's full-sized avatar
👋

Rishabh Rawat Rishabh570

👋
View GitHub Profile
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const itemSchema = new Schema({
name: {
type: String,
required: true
},
rating: {
type: String,
describe('Testing /item endpoint', () => {
let sampleItemVal;
let findOneStub;
const sampleUniqueHash = '1234567891';
beforeEach(() => {
sampleItemVal = {
name: 'sample item',
price: 10,
rating: '5',
function getUniqueHash(item) {
if (!item) return null;
const currentHash = item.hash;
let newHash = nanoid(10);
while (newHash === currentHash) {
newHash = nanoid(10);
}
return newHash;
}
exports.updateItemHash = async function (hash) {
try {
if (!hash) {
throw new Error('Incomplete arguments');
}
let item = await Item.findOne({
hash
});
item.hash = getUniqueHash(item);
describe('Testing /item endpoint', () => {
let sampleItemVal;
let findOneStub;
beforeEach(() => {
sampleItemVal = {
name: 'sample item',
price: 10,
rating: '5',
hash: '123456891'
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', () => {
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 () => {
"test:watch": "mocha --watch ./src/tests/*.spec.js"
@Rishabh570
Rishabh570 / test-script-package.json
Created April 19, 2022 17:58
Add this test script to your package.json file.
"test": "mocha ./src/tests/*.spec.js"
- describe('Test /health')
-- describe('Test /health/sync')
-- describe('Test /health/async')