-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
129 additions
and
26 deletions.
There are no files selected for viewing
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/// <reference path="../_references.d.ts" /> | ||
|
||
export interface Stage { | ||
|
||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/// <reference path="../_references.d.ts" /> | ||
import * as Iridium from '../index'; | ||
import MongoDB = require('mongodb'); | ||
import Cursor from '../lib/Cursor'; | ||
import Promise = require('bluebird'); | ||
import _ = require('lodash'); | ||
|
||
interface TestDocument { | ||
_id?: string; | ||
group: string; | ||
score: number; | ||
} | ||
|
||
class Test extends Iridium.Instance<TestDocument, Test> implements TestDocument { | ||
static collection = 'test'; | ||
static schema: Iridium.Schema = { | ||
_id: MongoDB.ObjectID, | ||
group: String, | ||
score: Number | ||
}; | ||
|
||
_id: string; | ||
group: string; | ||
score: number; | ||
} | ||
|
||
describe("Model", () => { | ||
let core = new Iridium.Core({ database: 'test' }); | ||
|
||
before(() => core.connect()); | ||
|
||
|
||
describe("aggregate()", () => { | ||
let model = new Iridium.Model<TestDocument, Test>(core, Test); | ||
|
||
beforeEach(() => { | ||
return core.connect().then(() => model.remove()).then(() => model.insert([ | ||
{ group: 'A', score: 10 }, | ||
{ group: 'B', score: 11 }, | ||
{ group: 'C', score: 12 }, | ||
{ group: 'A', score: 13 }, | ||
{ group: 'B', score: 14 } | ||
])); | ||
}); | ||
|
||
it("should correctly pass through the aggregation pipeline", () => { | ||
return chai.expect(model.aggregate([ | ||
{ $group: { _id: '$group', score: { $sum: "$score" } } } | ||
])).to.eventually.exist.and.have.length(3); | ||
}); | ||
|
||
it("should allow you to specify the type of the resulting documents", () => { | ||
return model.aggregate<{ _id: string; score: number; }>([ | ||
{ $match: { group: 'A' } }, | ||
{ $group: { _id: '$group', score: { $sum: "$score" } } } | ||
]).then(results => { | ||
chai.expect(results).to.exist.and.have.length(1); | ||
chai.expect(results[0]._id).to.eql('A'); | ||
chai.expect(results[0].score).to.eql(23); | ||
}); | ||
}); | ||
}); | ||
}); |