Skip to content

Instantly share code, notes, and snippets.

@sminutoli
Last active September 28, 2016 14:34
Show Gist options
  • Save sminutoli/2de49febdf55260e508cd47f240c26ec to your computer and use it in GitHub Desktop.
Save sminutoli/2de49febdf55260e508cd47f240c26ec to your computer and use it in GitHub Desktop.
describe('##getItemsGroupedByCategory', ()=> {
it('should receive a callback', ()=> {
assertFnParams(itemModel.getItemsGroupedByCategory, 1);
});
it('should call the callback with the mongoose response', ()=> {
let callback = function () {};
mock.schema.aggregate.andReturn(mock.schema);
mock.schema.match.andReturn(mock.schema);
mock.schema.sort.andReturn(mock.schema);
mock.schema.group.andReturn(mock.schema);
itemModel.getItemsGroupedByCategory.call(mock, callback);
expect(mock.schema.aggregate).toHaveBeenCalled();
expect(mock.schema.match).toHaveBeenCalledWith(itemModel.getMongooseObjects.match.showable);
expect(mock.schema.sort).toHaveBeenCalledWith(itemModel.getMongooseObjects.sort.stateType.desc);
expect(mock.schema.group).toHaveBeenCalledWith(itemModel.getMongooseObjects.group.categoryId);
expect(mock.handleCallback).toHaveBeenCalledWith(callback, httpStatus.BAD_REQUEST);
});
});
describe('##getItemsGroupedByCategory', ()=> {
//setup
let callback = function () {};
mock.schema.aggregate.andReturn(mock.schema);
mock.schema.match.andReturn(mock.schema);
mock.schema.sort.andReturn(mock.schema);
mock.schema.group.andReturn(mock.schema);
//action
itemModel.getItemsGroupedByCategory.call(mock, callback);
it('should receive a callback', ()=> {
//assert
assertFnParams(itemModel.getItemsGroupedByCategory, 1);
});
it('should call the callback aggregate the mongoose response', () => {
expect(mock.schema.aggregate).toHaveBeenCalled();
});
it('should call the callback schema.match with match.showable', () => {
expect(mock.schema.match).toHaveBeenCalledWith(itemModel.getMongooseObjects.match.showable);
});
it('should call the callback schema.match with match.showable', () => {
expect(mock.schema.sort).toHaveBeenCalledWith(itemModel.getMongooseObjects.sort.stateType.desc);
});
it('should call the callback schema.group with match.showable', () => {
expect(mock.schema.group).toHaveBeenCalledWith(itemModel.getMongooseObjects.group.categoryId);
});
it('should call the callback handleCallback with match.showable', () => {
expect(mock.handleCallback).toHaveBeenCalledWith(callback, httpStatus.BAD_REQUEST);
});
});
describe('##getItemsGroupedByCategory', ()=> {
let callback;
before(() => {
callback = function () {};
mock.schema.aggregate.andReturn(mock.schema);
mock.schema.match.andReturn(mock.schema);
mock.schema.sort.andReturn(mock.schema);
mock.schema.group.andReturn(mock.schema);
});
it('should receive a callback', ()=> {
itemModel.getItemsGroupedByCategory.call(mock, callback);
assertFnParams(itemModel.getItemsGroupedByCategory, 1);
});
it('should call the callback aggregate the mongoose response', () => {
itemModel.getItemsGroupedByCategory.call(mock, callback);
expect(mock.schema.aggregate).toHaveBeenCalled();
});
it('should call the callback schema.match with match.showable', () => {
itemModel.getItemsGroupedByCategory.call(mock, callback);
expect(mock.schema.match).toHaveBeenCalledWith(itemModel.getMongooseObjects.match.showable);
});
it('should call the callback schema.match with match.showable', () => {
itemModel.getItemsGroupedByCategory.call(mock, callback);
expect(mock.schema.sort).toHaveBeenCalledWith(itemModel.getMongooseObjects.sort.stateType.desc);
});
it('should call the callback schema.group with match.showable', () => {
itemModel.getItemsGroupedByCategory.call(mock, callback);
expect(mock.schema.group).toHaveBeenCalledWith(itemModel.getMongooseObjects.group.categoryId);
});
it('should call the callback handleCallback with match.showable', () => {
itemModel.getItemsGroupedByCategory.call(mock, callback);
expect(mock.handleCallback).toHaveBeenCalledWith(callback, httpStatus.BAD_REQUEST);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment