beforeEach(function() {
		return Promise.all([
			systemjs.import('./src/stores/route-store'),
			systemjs.import('./src/dispatcher')
		]).then(function(modules) {
			routeStore = new modules[0].routeStore.constructor();
			dispatcher = modules[1].dispatcher;
		});
	});
 db.collection("coll_group_1").then(coll => {
     Promise.all([
         coll.insert({
             _id: 1111,
             name: 'eeee',
             age: 22
         }, {chain: true}),
         coll.insert({
             _id: 1112,
             name: 'dddd',
             age: 23
         }, {chain: true}),
         coll.insert({
             _id: 1113,
             name: 'cccc',
             age: 22
         }, {chain: true}),
         coll.insert({
             _id: 1114,
             name: 'bbbb',
             age: 25
         }, {chain: true}),
         coll.insert({
             _id: 1115,
             name: 'aaaa',
             age: 23
         })
     ]).then(() => {
         var docs = coll.aggregate([{
             $group: {
                 _id: "$age",
                 count: {
                     $sum: 1
                 },
                 total_id: {
                     $sum: "$_id"
                 },
                 total_age: {
                     $sum: '$age'
                 }
             }
         }]);
         
         expect(docs).to.exist;
         expect(docs).to.be.instanceof(Array);
         expect(docs).to.have.length(3);
         
         done();
     });
 });
 getResult(): Promise.IThenable<User> {
     if (_.isUndefined(this.passwordPromise)) {
         throw new Error("You need to set password first");
     }
    
     return Promise.all([
         this.passwordPromise,
     ]).then(([password]) => {
         return {
             id: this.email,
             email: this.email,
             password: password,
             salt: this.salt
         }
     });
 }
 db.collection("coll_group_2").then(coll => {
     Promise.all([
         coll.insert({
             _id: 1111,
             name: 'eeee',
             age: 22
         }, {chain: true}),
         coll.insert({
             _id: 1112,
             name: 'dddd',
             age: 23
         }, {chain: true}),
         coll.insert({
             _id: 1113,
             name: 'cccc',
             age: 22
         }, {chain: true}),
         coll.insert({
             _id: 1114,
             name: 'bbbb',
             age: 25
         }, {chain: true}),
         coll.insert({
             _id: 1115,
             name: 'aaaa',
             age: 23
         })
     ]).then(() => {
         var docs = coll.aggregate([{
             $group: {
                 _id: null,
                 aver_age: {
                     $avg: '$age'
                 }
             }
         }]);
         
         expect(docs).to.exist;
         expect(docs).to.be.instanceof(Array);
         expect(docs).to.have.length(1);
         expect(docs[0].aver_age).to.be.equal(23);
         
         done();
     });
 });
 db.collection("coll_match_1").then(coll => {
     Promise.all([
         coll.insert({
             _id: 1111,
             name: 'eeee',
             age: 22
         }, {chain: true}),
         coll.insert({
             _id: 1112,
             name: 'dddd',
             age: 23
         }, {chain: true}),
         coll.insert({
             _id: 1113,
             name: 'cccc',
             age: 22
         }, {chain: true}),
         coll.insert({
             _id: 1114,
             name: 'bbbb',
             age: 25
         }, {chain: true}),
         coll.insert({
             _id: 1115,
             name: 'aaaa',
             age: 23
         })
     ]);
     
     var docs = coll.aggregate([{
         $match: {
             age: {
                 $gte: 23
             }
         }
     }]);
     
     expect(docs).to.exist;
     expect(docs).to.be.instanceof(Array);
     expect(docs).to.have.length(3);
     
     done();
 });
Example #6
0
                .then((token) => {

                    const promises: Array<Promise.IThenable<ISeverityCountResult>> = [];

                    [SeverityType.Low, SeverityType.Medium, SeverityType.High, SeverityType.Critical].forEach((severity) => {
                        const q = qs.stringify({
                            fields: 'severityString',
                            limit: 1,
                            filters: `severity:${severity}+isSuppressed:false`,
                            excludeFilters: true
                        });

                        promises.push(
                            new Promise<ISeverityCountResult>((resolve, reject) => {
                                msg.http(FoDApiHelper.getApiUri(`/api/v3/releases/${releaseId}/vulnerabilities?${q}`))
                                    .headers({
                                        'authorization': `Bearer ${token}`,
                                        'content-type': 'application/octet-stream'
                                    })
                                    .get()((err: any, res: any, body: any) => {
                                        if (err)
                                            return reject(err);

                                        const result = JSON.parse(body);

                                        if (result && result.totalCount && result.items) {
                                            return resolve({ severityId: severity, severityType: result.items[0].severityString, count: result.totalCount });
                                        }

                                        return resolve(null);
                                    });
                            }));
                    });

                    return Promise.all(promises);
                })
 db.collection("coll_mixed_1").then(coll => {
     Promise.all([
         coll.insert({
             _id: 1111,
             name: 'eeee',
             age: 22
         }, {chain: true}),
         coll.insert({
             _id: 1112,
             name: 'dddd',
             age: 23
         }, {chain: true}),
         coll.insert({
             _id: 1113,
             name: 'cccc',
             age: 22
         }, {chain: true}),
         coll.insert({
             _id: 1114,
             name: 'bbbb',
             age: 25
         }, {chain: true}),
         coll.insert({
             _id: 1115,
             name: 'aaaa',
             age: 23
         }, {chain: true}),
         coll.insert({
             _id: 1115,
             name: 'abab',
             age: 22
         })
     ]);
     
     
     var docs = coll.aggregate([{
         $match: {
             age: {
                 $lt: 25
             }
         }
     }, {
         $group: {
             _id: "$age",
             total: {
                 $sum: 1
             }
         }
     }, {
         $sort: {
             total: -1
         }
     }, {
         $project: {
             suma_total: '$total',
             total: -1
         }
     }]);
     
     expect(docs).to.exist;
     expect(docs).to.be.instanceof(Array);
     expect(docs).to.have.length(2);
     
     expect(docs[0]).to.be.eql({ _id: 22, suma_total: 3 });
     expect(docs[1]).to.be.eql({ _id: 23, suma_total: 2 });
     
     done();
 });