Skip to content

Commit

Permalink
fix: failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Akalanka47000 authored Jul 23, 2024
1 parent eb09c22 commit 6faedec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
23 changes: 11 additions & 12 deletions lib/mongoose-aggregate-paginate.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,19 @@ function aggregatePaginate(query, options, callback) {
} else {
const [pipeline, countPipeline] = constructPipelines();

const countQuery = options.countQuery
let countQuery = options.countQuery
? options.countQuery
: this.aggregate(countPipeline);

if (options.countQuery) {
countQuery = countQuery.group({
_id: null,
count: {
$sum: 1,
},
});
}

if (allowDiskUse) {
countQuery.allowDiskUse(true);
}
Expand All @@ -157,17 +166,7 @@ function aggregatePaginate(query, options, callback) {

if (query.options) q.options = query.options;

promise = Promise.all([
q.exec(),
countQuery
.group({
_id: null,
count: {
$sum: 1,
},
})
.exec(),
]);
promise = Promise.all([q.exec(), countQuery.exec()]);
}

return promise
Expand Down
4 changes: 2 additions & 2 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,11 @@ describe("mongoose-paginate", function () {
};
return Book.aggregatePaginate(aggregate, options).then((result) => {
expect(result.docs).to.have.length(10);
expect(result.docs[0].title).to.equal("Book #41");
expect(result.docs[0].title).to.equal("Book #11");
expect(result.totalDocs).to.equal(100);
expect(result.limit).to.equal(10);
expect(result.page).to.equal(2);
expect(result.pagingCounter).to.equal(41);
expect(result.pagingCounter).to.equal(11);
expect(result.hasPrevPage).to.equal(true);
expect(result.hasNextPage).to.equal(true);
expect(result.prevPage).to.equal(1);
Expand Down

0 comments on commit 6faedec

Please sign in to comment.