How to use getCollector method in istanbul

Best JavaScript code snippet using istanbul

MemoryQueryExecutor.test.js

Source:MemoryQueryExecutor.test.js Github

copy

Full Screen

...119 it('gets all data of collection and return an instance of Collection<Eloquent<T>>', async function () {120 const handler = makeQueryBuilderHandler('User');121 const result = await handler.getQueryExecutor().get();122 expect_query_log({123 raw: 'MemoryDataSourceProvider.create("User").getCollector().exec()',124 action: 'get'125 }, result);126 expect(result.length).toEqual(7);127 for (let i = 0; i < 7; i++) {128 expect_match_user(result[i], dataset[i]);129 }130 });131 it('returns an empty collection if no result', async function () {132 const handler = makeQueryBuilderHandler('User');133 makeQueryBuilder(handler).where('first_name', 'no-one');134 const result = await handler.getQueryExecutor().get();135 expect_query_log({136 raw: `MemoryDataSourceProvider.create("User").getCollector().filterBy(${JSON.stringify({137 $and: [{ field: 'first_name', operator: '=', value: 'no-one' }]138 })}).exec()`139 }, result);140 expect(result.length === 0).toBe(true);141 });142 it('can get data by query builder, case 1', async function () {143 const handler = makeQueryBuilderHandler('User');144 makeQueryBuilder(handler).where('age', 1000);145 const result = await handler.getQueryExecutor().get();146 expect_query_log({147 raw: `MemoryDataSourceProvider.create("User").getCollector().filterBy(${JSON.stringify({148 $and: [{ field: 'age', operator: '=', value: 1000 }]149 })}).exec()`,150 action: 'get'151 }, result);152 expect(result.length).toEqual(1);153 expect_match_user(result[0], dataset[3]);154 });155 it('can get data by query builder, case 2', async function () {156 const handler = makeQueryBuilderHandler('User');157 makeQueryBuilder(handler).where('age', 40);158 const result = await handler.getQueryExecutor().get();159 expect_query_log({160 raw: `MemoryDataSourceProvider.create("User").getCollector().filterBy(${JSON.stringify({161 $and: [{ field: 'age', operator: '=', value: 40 }]162 })}).exec()`,163 dataSource: 'NajsEloquent.Driver.Memory.MemoryDataSource',164 action: 'get'165 }, result);166 expect(result.length).toEqual(2);167 expect_match_user(result[0], dataset[2]);168 expect_match_user(result[1], dataset[5]);169 });170 it('can get data by query builder, case 3', async function () {171 const handler = makeQueryBuilderHandler('User');172 makeQueryBuilder(handler)173 .where('age', 40)174 .where('last_name', 'stark');175 const result = await handler.getQueryExecutor().get();176 expect_query_log({177 raw: `MemoryDataSourceProvider.create("User").getCollector().filterBy(${JSON.stringify({178 $and: [{ field: 'age', operator: '=', value: 40 }, { field: 'last_name', operator: '=', value: 'stark' }]179 })}).exec()`,180 dataSource: 'NajsEloquent.Driver.Memory.MemoryDataSource',181 action: 'get'182 }, result);183 expect(result.length).toEqual(1);184 expect_match_user(result[0], dataset[2]);185 });186 it('can get data by query builder, case 4', async function () {187 const handler = makeQueryBuilderHandler('User');188 makeQueryBuilder(handler)189 .where('age', 40)190 .orWhere('first_name', 'peter');191 const result = await handler.getQueryExecutor().get();192 expect_query_log({193 raw: `MemoryDataSourceProvider.create("User").getCollector().filterBy(${JSON.stringify({194 $or: [{ field: 'age', operator: '=', value: 40 }, { field: 'first_name', operator: '=', value: 'peter' }]195 })}).exec()`,196 dataSource: 'NajsEloquent.Driver.Memory.MemoryDataSource',197 action: 'get'198 }, result);199 expect(result.length).toEqual(3);200 expect_match_user(result[0], dataset[2]);201 expect_match_user(result[1], dataset[5]);202 expect_match_user(result[2], dataset[6]);203 });204 it('can get data by query builder, case 5', async function () {205 const handler = makeQueryBuilderHandler('User');206 makeQueryBuilder(handler)207 .where('age', 40)208 .orWhere('first_name', 'peter')209 .orderBy('id', 'desc');210 const result = await handler.getQueryExecutor().get();211 expect_query_log({212 raw: `MemoryDataSourceProvider.create("User").getCollector().orderBy(${JSON.stringify([213 ['id', 'desc']214 ])}).filterBy(${JSON.stringify({215 $or: [{ field: 'age', operator: '=', value: 40 }, { field: 'first_name', operator: '=', value: 'peter' }]216 })}).exec()`,217 dataSource: 'NajsEloquent.Driver.Memory.MemoryDataSource',218 action: 'get'219 }, result);220 expect(result.length).toEqual(3);221 expect_match_user(result[0], dataset[6]);222 expect_match_user(result[1], dataset[5]);223 expect_match_user(result[2], dataset[2]);224 });225 it('returns an empty array if executeMode is disabled', async function () {226 const handler = makeQueryBuilderHandler('User');227 makeQueryBuilder(handler)228 .where('age', 40)229 .orWhere('first_name', 'peter')230 .orderBy('id', 'desc');231 const result = await handler232 .getQueryExecutor()233 .setExecuteMode('disabled')234 .get();235 expect_query_log({236 raw: `MemoryDataSourceProvider.create("User").getCollector().orderBy(${JSON.stringify([237 ['id', 'desc']238 ])}).filterBy(${JSON.stringify({239 $or: [{ field: 'age', operator: '=', value: 40 }, { field: 'first_name', operator: '=', value: 'peter' }]240 })}).exec()`,241 dataSource: 'NajsEloquent.Driver.Memory.MemoryDataSource',242 action: 'get'243 }, result);244 expect(result).toEqual([]);245 });246 });247 describe('.first()', function () {248 it('finds first document of collection and return an instance of Eloquent<T>', async function () {249 const handler = makeQueryBuilderHandler('User');250 const result = await handler.getQueryExecutor().first();251 expect_query_log({252 raw: `MemoryDataSourceProvider.create("User").getCollector().limit(1).exec()`,253 dataSource: 'NajsEloquent.Driver.Memory.MemoryDataSource',254 action: 'first'255 }, result);256 expect_match_user(result, dataset[0]);257 });258 it('finds first document of collection and return an instance of Eloquent<T>', async function () {259 const handler = makeQueryBuilderHandler('User');260 makeQueryBuilder(handler).orderBy('id', 'desc');261 const result = await handler.getQueryExecutor().first();262 expect_query_log({263 raw: `MemoryDataSourceProvider.create("User").getCollector().orderBy(${JSON.stringify([264 ['id', 'desc']265 ])}).limit(1).exec()`,266 dataSource: 'NajsEloquent.Driver.Memory.MemoryDataSource',267 action: 'first'268 }, result);269 expect_match_user(result, dataset[6]);270 });271 it('returns undefined if no result', async function () {272 const handler = makeQueryBuilderHandler('User');273 makeQueryBuilder(handler).where('first_name', 'no-one');274 const result = await handler.getQueryExecutor().first();275 expect_query_log({276 raw: `MemoryDataSourceProvider.create("User").getCollector().filterBy(${JSON.stringify({277 $and: [{ field: 'first_name', operator: '=', value: 'no-one' }]278 })}).limit(1).exec()`,279 dataSource: 'NajsEloquent.Driver.Memory.MemoryDataSource',280 action: 'first'281 }, result);282 expect(result).toBeUndefined();283 });284 it('can find data by query builder, case 1', async function () {285 const handler = makeQueryBuilderHandler('User');286 makeQueryBuilder(handler).where('age', 1000);287 const result = await handler.getQueryExecutor().first();288 expect_query_log({289 raw: `MemoryDataSourceProvider.create("User").getCollector().filterBy(${JSON.stringify({290 $and: [{ field: 'age', operator: '=', value: 1000 }]291 })}).limit(1).exec()`,292 dataSource: 'NajsEloquent.Driver.Memory.MemoryDataSource',293 action: 'first'294 }, result);295 expect_match_user(result, dataset[3]);296 });297 it('can find data by query builder, case 2', async function () {298 const handler = makeQueryBuilderHandler('User');299 makeQueryBuilder(handler)300 .where('age', 40)301 .orWhere('first_name', 'jane');302 const result = await handler.getQueryExecutor().first();303 expect_query_log({304 raw: `MemoryDataSourceProvider.create("User").getCollector().filterBy(${JSON.stringify({305 $or: [{ field: 'age', operator: '=', value: 40 }, { field: 'first_name', operator: '=', value: 'jane' }]306 })}).limit(1).exec()`,307 dataSource: 'NajsEloquent.Driver.Memory.MemoryDataSource',308 action: 'first'309 }, result);310 expect_match_user(result, dataset[1]);311 });312 it('can find data by query builder, case 3', async function () {313 const handler = makeQueryBuilderHandler('User');314 makeQueryBuilder(handler)315 .where('first_name', 'tony')316 .where('last_name', 'stewart');317 const result = await handler.getQueryExecutor().first();318 expect_query_log({319 raw: `MemoryDataSourceProvider.create("User").getCollector().filterBy(${JSON.stringify({320 $and: [321 { field: 'first_name', operator: '=', value: 'tony' },322 { field: 'last_name', operator: '=', value: 'stewart' }323 ]324 })}).limit(1).exec()`,325 dataSource: 'NajsEloquent.Driver.Memory.MemoryDataSource',326 action: 'first'327 }, result);328 expect_match_user(result, dataset[5]);329 });330 // it('can find data by .native() before using query functions of query builder', async function() {331 // const handler = makeQueryBuilderHandler('users')332 // const result = await makeQueryBuilder(handler)333 // .native(function(collection) {334 // return collection.findOne({335 // first_name: 'tony'336 // })337 // })338 // .execute()339 // expect_match_user(result, dataset[2])340 // })341 // it('can find data by native() after using query functions of query builder', async function() {342 // const handler = makeQueryBuilderHandler('users')343 // const result = await makeQueryBuilder(handler)344 // .where('age', 40)345 // .orWhere('age', 1000)346 // .native(function(collection, conditions) {347 // return collection.findOne(conditions, { sort: [['last_name', -1]] })348 // })349 // .execute()350 // expect_match_user(result, dataset[5])351 // })352 // it('can find data by native() and modified after using query functions of query builder', async function() {353 // const handler = makeQueryBuilderHandler('users')354 // const result = await await makeQueryBuilder(handler)355 // .where('age', 40)356 // .orWhere('age', 1000)357 // .native(function(collection) {358 // return collection.findOne({359 // first_name: 'thor'360 // })361 // })362 // .execute()363 // expect_match_user(result, dataset[3])364 // })365 it('returns an undefined if executeMode is disabled', async function () {366 const handler = makeQueryBuilderHandler('User');367 makeQueryBuilder(handler)368 .where('age', 40)369 .orWhere('first_name', 'jane');370 const result = await handler371 .getQueryExecutor()372 .setExecuteMode('disabled')373 .first();374 expect_query_log({375 raw: `MemoryDataSourceProvider.create("User").getCollector().filterBy(${JSON.stringify({376 $or: [{ field: 'age', operator: '=', value: 40 }, { field: 'first_name', operator: '=', value: 'jane' }]377 })}).limit(1).exec()`,378 dataSource: 'NajsEloquent.Driver.Memory.MemoryDataSource',379 action: 'first'380 }, result);381 expect(result).toBeUndefined();382 });383 });384 describe('.count()', function () {385 it('counts all data of records and returns a number', async function () {386 const handler = makeQueryBuilderHandler('User');387 const result = await handler.getQueryExecutor().count();388 expect_query_log({389 raw: `MemoryDataSourceProvider.create("User").getCollector().exec()`,390 dataSource: 'NajsEloquent.Driver.Memory.MemoryDataSource',391 action: 'count'392 }, result);393 expect(result).toEqual(7);394 });395 it('returns 0 if no result', async function () {396 const handler = makeQueryBuilderHandler('User');397 makeQueryBuilder(handler).where('first_name', 'no-one');398 const result = await handler.getQueryExecutor().count();399 expect_query_log({400 raw: `MemoryDataSourceProvider.create("User").getCollector().filterBy(${JSON.stringify({401 $and: [{ field: 'first_name', operator: '=', value: 'no-one' }]402 })}).exec()`,403 dataSource: 'NajsEloquent.Driver.Memory.MemoryDataSource',404 action: 'count'405 }, result);406 expect(result).toEqual(0);407 });408 it('overrides select even .select was used', async function () {409 const handler = makeQueryBuilderHandler('User');410 makeQueryBuilder(handler).select('abc', 'def');411 const result = await handler.getQueryExecutor().count();412 expect_query_log({413 raw: `MemoryDataSourceProvider.create("User").getCollector().exec()`,414 dataSource: 'NajsEloquent.Driver.Memory.MemoryDataSource',415 action: 'count'416 }, result);417 expect(result).toEqual(7);418 });419 it('overrides ordering even .orderBy was used', async function () {420 const handler = makeQueryBuilderHandler('User');421 makeQueryBuilder(handler).orderBy('abc');422 const result = await handler.getQueryExecutor().count();423 expect_query_log({424 raw: `MemoryDataSourceProvider.create("User").getCollector().exec()`,425 dataSource: 'NajsEloquent.Driver.Memory.MemoryDataSource',426 action: 'count'427 }, result);428 expect(result).toEqual(7);429 });430 it('can count items by query builder, case 1', async function () {431 const handler = makeQueryBuilderHandler('User');432 makeQueryBuilder(handler)433 .where('age', 18)434 .orWhere('first_name', 'tony');435 const result = await handler.getQueryExecutor().count();436 expect_query_log({437 raw: `MemoryDataSourceProvider.create("User").getCollector().filterBy(${JSON.stringify({438 $or: [{ field: 'age', operator: '=', value: 18 }, { field: 'first_name', operator: '=', value: 'tony' }]439 })}).exec()`,440 dataSource: 'NajsEloquent.Driver.Memory.MemoryDataSource',441 action: 'count'442 }, result);443 expect(result).toEqual(2);444 });445 it('can count items by query builder, case 2', async function () {446 const handler = makeQueryBuilderHandler('User');447 makeQueryBuilder(handler)448 .where('age', 1000)449 .orWhere('first_name', 'captain')450 .orderBy('last_name')451 .limit(10);452 const result = await handler.getQueryExecutor().count();453 expect_query_log({454 raw: `MemoryDataSourceProvider.create("User").getCollector().limit(10).filterBy(${JSON.stringify({455 $or: [456 { field: 'age', operator: '=', value: 1000 },457 { field: 'first_name', operator: '=', value: 'captain' }458 ]459 })}).exec()`,460 dataSource: 'NajsEloquent.Driver.Memory.MemoryDataSource',461 action: 'count'462 }, result);463 expect(result).toEqual(2);464 });465 it('returns 0 if executeMode is disabled', async function () {466 const handler = makeQueryBuilderHandler('User');467 makeQueryBuilder(handler)468 .where('age', 1000)469 .orWhere('first_name', 'captain')470 .orderBy('last_name')471 .limit(10);472 const result = await handler473 .getQueryExecutor()474 .setExecuteMode('disabled')475 .count();476 expect_query_log({477 raw: `MemoryDataSourceProvider.create("User").getCollector().limit(10).filterBy(${JSON.stringify({478 $or: [479 { field: 'age', operator: '=', value: 1000 },480 { field: 'first_name', operator: '=', value: 'captain' }481 ]482 })}).exec()`,483 dataSource: 'NajsEloquent.Driver.Memory.MemoryDataSource',484 action: 'count'485 }, result);486 expect(result).toEqual(0);487 });488 });489 describe('.update()', function () {490 it('can update data of collection, returns result of dataSource.write()', async function () {491 let handler = makeQueryBuilderHandler('User');492 makeQueryBuilder(handler).where('first_name', 'peter');493 const result = await handler.getQueryExecutor().update({ age: 19 });494 expect_query_log({495 raw: `MemoryDataSourceProvider.create("User").getCollector().filterBy(${JSON.stringify({496 $and: [{ field: 'first_name', operator: '=', value: 'peter' }]497 })}).exec() >> update records >> dataSource.write()`,498 action: 'update',499 records: [500 {501 origin: Object.assign({}, dataset[6], { age: 15 }),502 modified: true,503 updated: Object.assign({}, dataset[6], { age: 19 })504 }505 ]506 }, result);507 expect(result).toEqual(true);508 handler = makeQueryBuilderHandler('User');509 makeQueryBuilder(handler).where('first_name', 'peter');510 const updatedResult = await handler.getQueryExecutor().first();511 expect_match_user(updatedResult, Object.assign({}, dataset[6], { age: 19 }));512 });513 it('does not call dataSource.push() if the record is not modified', async function () {514 let handler = makeQueryBuilderHandler('User');515 makeQueryBuilder(handler).where('first_name', 'peter');516 const result = await handler.getQueryExecutor().update({ age: 19 });517 expect_query_log({518 raw: `MemoryDataSourceProvider.create("User").getCollector().filterBy(${JSON.stringify({519 $and: [{ field: 'first_name', operator: '=', value: 'peter' }]520 })}).exec() >> update records >> dataSource.write()`,521 action: 'update',522 records: [523 {524 origin: Object.assign({}, dataset[6], { age: 19 }),525 modified: false,526 updated: Object.assign({}, dataset[6], { age: 19 })527 }528 ]529 }, result);530 expect(result).toEqual(true);531 handler = makeQueryBuilderHandler('User');532 makeQueryBuilder(handler).where('first_name', 'peter');533 const updatedResult = await handler.getQueryExecutor().first();534 expect_match_user(updatedResult, Object.assign({}, dataset[6], { age: 19 }));535 });536 it('returns empty update result if no row matched', async function () {537 const handler = makeQueryBuilderHandler('User');538 makeQueryBuilder(handler).where('first_name', 'no-one');539 const result = await handler.getQueryExecutor().update({ $set: { age: 19 } });540 expect_query_log({541 raw: `MemoryDataSourceProvider.create("User").getCollector().filterBy(${JSON.stringify({542 $and: [{ field: 'first_name', operator: '=', value: 'no-one' }]543 })}).exec() >> empty, do nothing`,544 action: 'update'545 }, result);546 expect(result).toEqual(true);547 });548 it('can update data by query builder, case 1', async function () {549 let handler = makeQueryBuilderHandler('User');550 makeQueryBuilder(handler).where('age', 1000);551 const result = await handler.getQueryExecutor().update({ age: 1001 });552 expect_query_log({553 raw: `MemoryDataSourceProvider.create("User").getCollector().filterBy(${JSON.stringify({554 $and: [{ field: 'age', operator: '=', value: 1000 }]555 })}).exec() >> update records >> dataSource.write()`,556 action: 'update'557 }, result);558 expect(result).toEqual(true);559 handler = makeQueryBuilderHandler('User');560 makeQueryBuilder(handler).where('first_name', 'thor');561 const updatedResult = await handler.getQueryExecutor().first();562 expect_match_user(updatedResult, Object.assign({}, dataset[3], { age: 1001 }));563 });564 it('can update data by query builder, case 2: multiple documents', async function () {565 let handler = makeQueryBuilderHandler('User');566 makeQueryBuilder(handler).where('age', 40);567 const result = await handler.getQueryExecutor().update({ age: 41 });568 expect_query_log({569 raw: `MemoryDataSourceProvider.create("User").getCollector().filterBy(${JSON.stringify({570 $and: [{ field: 'age', operator: '=', value: 40 }]571 })}).exec() >> update records >> dataSource.write()`,572 action: 'update'573 }, result);574 expect(result).toEqual(true);575 handler = makeQueryBuilderHandler('User');576 makeQueryBuilder(handler).where('age', 41);577 const updatedResults = await handler.getQueryExecutor().get();578 expect_match_user(updatedResults[0], Object.assign({}, dataset[2], { age: 41 }));579 expect_match_user(updatedResults[1], Object.assign({}, dataset[5], { age: 41 }));580 });581 it('auto add updatedAt field to $set if timestamps options is on', async function () {582 const now = new Date(1988, 4, 16);583 MomentProviderFacade_1.MomentProvider.setNow(() => now);584 function makeHandler() {585 return new MemoryQueryBuilderHandler_1.MemoryQueryBuilderHandler({586 getDriver() {587 return {588 getSoftDeletesFeature() {589 return {590 hasSoftDeletes() {591 return false;592 }593 };594 },595 getTimestampsFeature() {596 return {597 hasTimestamps() {598 return true;599 },600 getTimestampsSetting() {601 return { createdAt: 'created_at', updatedAt: 'updated_at' };602 }603 };604 }605 };606 },607 getModelName() {608 return 'User';609 },610 getPrimaryKey() {611 return 'id';612 }613 });614 }615 let handler = makeHandler();616 makeQueryBuilder(handler)617 .where('first_name', 'tony')618 .where('last_name', 'stewart');619 const result = await handler.getQueryExecutor().update({ age: 43 });620 expect(result).toEqual(true);621 handler = makeHandler();622 makeQueryBuilder(handler)623 .where('first_name', 'tony')624 .where('last_name', 'stewart');625 const updatedResult = await handler.getQueryExecutor().first();626 expect_match_user(updatedResult, Object.assign({}, dataset[5], { age: 43, updated_at: now }));627 handler = makeHandler();628 makeQueryBuilder(handler)629 .where('first_name', 'tony')630 .where('last_name', 'stewart');631 const result2 = await handler.getQueryExecutor().update({ age: 44 });632 expect(result2).toEqual(true);633 handler = makeHandler();634 makeQueryBuilder(handler)635 .where('first_name', 'tony')636 .where('last_name', 'stewart');637 const updatedResult2 = await handler.getQueryExecutor().first();638 expect_match_user(updatedResult2, Object.assign({}, dataset[5], { age: 44, updated_at: now }));639 });640 it('returns an true and do nothing if executeMode is disabled', async function () {641 let handler = makeQueryBuilderHandler('User');642 makeQueryBuilder(handler)643 .where('first_name', 'tony')644 .where('last_name', 'stewart');645 const result = await handler646 .getQueryExecutor()647 .setExecuteMode('disabled')648 .update({ $inc: { age: 1 } });649 expect_query_log({650 raw: `MemoryDataSourceProvider.create("User").getCollector().filterBy(${JSON.stringify({651 $and: [652 { field: 'first_name', operator: '=', value: 'tony' },653 { field: 'last_name', operator: '=', value: 'stewart' }654 ]655 })}).exec() >> empty, do nothing`,656 action: 'update'657 }, result);658 expect(result).toEqual(true);659 handler = makeQueryBuilderHandler('User');660 makeQueryBuilder(handler)661 .where('first_name', 'tony')662 .where('last_name', 'stewart');663 const updatedResult = await handler.getQueryExecutor().first();664 expect_match_user(updatedResult, Object.assign({}, dataset[5], { age: 44 }));665 });666 });667 describe('.delete()', function () {668 it('can delete data of collection, returns result of dataSource.write()', async function () {669 const handler = makeQueryBuilderHandler('User');670 makeQueryBuilder(handler).where('first_name', 'peter');671 const result = await handler.getQueryExecutor().delete();672 expect_query_log({673 raw: `MemoryDataSourceProvider.create("User").getCollector().filterBy(${JSON.stringify({674 $and: [{ field: 'first_name', operator: '=', value: 'peter' }]675 })}).exec() >> delete records >> dataSource.write()`,676 action: 'delete'677 }, result);678 expect(result).toEqual(true);679 const count = await makeQueryBuilderHandler('User')680 .getQueryExecutor()681 .count();682 expect(count).toEqual(6);683 });684 it('returns true and do nothing if executeMode is disabled', async function () {685 const handler = makeQueryBuilderHandler('User');686 makeQueryBuilder(handler)687 .where('first_name', 'john')688 .where('last_name', 'doe');689 const result = await handler690 .getQueryExecutor()691 .setExecuteMode('disabled')692 .delete();693 expect_query_log({694 raw: `MemoryDataSourceProvider.create("User").getCollector().filterBy(${JSON.stringify({695 $and: [696 { field: 'first_name', operator: '=', value: 'john' },697 { field: 'last_name', operator: '=', value: 'doe' }698 ]699 })}).exec() >> empty, do nothing`,700 action: 'delete'701 }, result);702 expect(result).toEqual(true);703 const count = await makeQueryBuilderHandler('User')704 .getQueryExecutor()705 .count();706 expect(count).toEqual(6);707 });708 it('can delete data by query builder, case 1', async function () {709 const handler = makeQueryBuilderHandler('User');710 makeQueryBuilder(handler).where('age', 1001);711 const result = await handler.getQueryExecutor().delete();712 expect_query_log({713 raw: `MemoryDataSourceProvider.create("User").getCollector().filterBy(${JSON.stringify({714 $and: [{ field: 'age', operator: '=', value: 1001 }]715 })}).exec() >> delete records >> dataSource.write()`,716 action: 'delete'717 }, result);718 expect(result).toEqual(true);719 const count = await makeQueryBuilderHandler('User')720 .getQueryExecutor()721 .count();722 expect(count).toEqual(5);723 });724 it('can delete data by query builder, case 2: multiple documents', async function () {725 const handler = makeQueryBuilderHandler('User');726 makeQueryBuilder(handler)727 .where('first_name', 'tony')728 .orWhere('first_name', 'jane');729 const result = await handler.getQueryExecutor().delete();730 expect_query_log({731 raw: `MemoryDataSourceProvider.create("User").getCollector().filterBy(${JSON.stringify({732 $or: [733 { field: 'first_name', operator: '=', value: 'tony' },734 { field: 'first_name', operator: '=', value: 'jane' }735 ]736 })}).exec() >> delete records >> dataSource.write()`,737 action: 'delete'738 }, result);739 expect(result).toEqual(true);740 const count = await makeQueryBuilderHandler('User')741 .getQueryExecutor()742 .count();743 expect(count).toEqual(2);744 });745 it('can delete data by query builder, case 3', async function () {746 const handler = makeQueryBuilderHandler('User');747 makeQueryBuilder(handler)748 .where('first_name', 'john')749 .where('last_name', 'doe');750 const result = await handler.getQueryExecutor().delete();751 expect_query_log({752 raw: `MemoryDataSourceProvider.create("User").getCollector().filterBy(${JSON.stringify({753 $and: [754 { field: 'first_name', operator: '=', value: 'john' },755 { field: 'last_name', operator: '=', value: 'doe' }756 ]757 })}).exec() >> delete records >> dataSource.write()`,758 action: 'delete'759 }, result);760 expect(result).toEqual(true);761 const count = await makeQueryBuilderHandler('User')762 .getQueryExecutor()763 .count();764 expect(count).toEqual(1);765 });766 it('can not call delete without using any .where() statement', async function () {767 const handler = makeQueryBuilderHandler('User');768 const result = await handler.getQueryExecutor().delete();769 expect(result).toEqual(false);770 });771 it('can not call delete if query is empty', async function () {772 const handler = makeQueryBuilderHandler('User');773 makeQueryBuilder(handler).select('any');774 const result = await handler.getQueryExecutor().delete();775 expect(result).toEqual(false);776 });777 // it('can delete by native() function', async function() {778 // const handler = makeQueryBuilderHandler('users')779 // const result = await makeQueryBuilder(handler)780 // .native(function(collection) {781 // return collection.remove({})782 // })783 // .execute()784 // expect(result).toEqual({ n: 1, ok: 1 })785 // const count = await makeQueryBuilderHandler('users')786 // .getQueryExecutor()787 // .count()788 // expect(count).toEqual(0)789 // })790 });791 describe('.restore()', function () {792 it('does nothing if Model do not support SoftDeletes', async function () {793 const handler = makeQueryBuilderHandler('User');794 makeQueryBuilder(handler).where('first_name', 'peter');795 const result = await handler.getQueryExecutor().restore();796 expect(QueryLogFacade_1.QueryLog.pull()).toHaveLength(0);797 expect(result).toEqual(false);798 });799 function makeHandler() {800 return new MemoryQueryBuilderHandler_1.MemoryQueryBuilderHandler({801 getDriver() {802 return {803 getSoftDeletesFeature() {804 return {805 hasSoftDeletes() {806 return true;807 },808 getSoftDeletesSetting() {809 return { deletedAt: 'deleted_at' };810 }811 };812 },813 getTimestampsFeature() {814 return {815 hasTimestamps() {816 return false;817 }818 };819 }820 };821 },822 getModelName() {823 return 'Role';824 },825 getPrimaryKeyName() {826 return 'id';827 }828 });829 }830 it('can not call restore if query is empty', async function () {831 const handler = makeHandler();832 makeQueryBuilder(handler).withTrashed();833 const result = await handler.getQueryExecutor().restore();834 expect(QueryLogFacade_1.QueryLog.pull()).toHaveLength(0);835 expect(result).toEqual(false);836 });837 it('can restore data by query builder, case 1', async function () {838 let handler = makeHandler();839 makeQueryBuilder(handler)840 .onlyTrashed()841 .where('name', 'role-0');842 const result = await handler.getQueryExecutor().restore();843 expect_query_log({844 raw: `MemoryDataSourceProvider.create("Role").getCollector().filterBy(${JSON.stringify({845 $and: [846 // tslint:disable-next-line847 { field: 'deleted_at', operator: '<>', value: null },848 { field: 'name', operator: '=', value: 'role-0' }849 ]850 })}).exec() >> update records >> dataSource.write()`,851 action: 'restore'852 }, result);853 expect(result).toEqual(true);854 handler = makeHandler();855 const count = await handler.getQueryExecutor().count();856 expect(count).toEqual(1);857 });858 it('returns true and do nothing if executeMode is disabled', async function () {859 let handler = makeHandler();860 makeQueryBuilder(handler)861 .withTrashed()862 .where('name', 'role-1')863 .orWhere('name', 'role-2')864 .orWhere('name', 'role-3');865 const result = await handler866 .getQueryExecutor()867 .setExecuteMode('disabled')868 .restore();869 expect_query_log({870 raw: `MemoryDataSourceProvider.create("Role").getCollector().filterBy(${JSON.stringify({871 $or: [872 { field: 'name', operator: '=', value: 'role-1' },873 { field: 'name', operator: '=', value: 'role-2' },874 { field: 'name', operator: '=', value: 'role-3' }875 ]876 })}).exec() >> empty, do nothing`,877 action: 'restore'878 }, result);879 expect(result).toEqual(true);880 handler = makeHandler();881 const count = await handler.getQueryExecutor().count();882 expect(count).toEqual(1);883 });884 it('can restore data by query builder, case 2: multiple documents', async function () {885 let handler = makeHandler();886 makeQueryBuilder(handler)887 .withTrashed()888 .where('name', 'role-1')889 .orWhere('name', 'role-2')890 .orWhere('name', 'role-3');891 const result = await handler.getQueryExecutor().restore();892 expect_query_log({893 raw: `MemoryDataSourceProvider.create("Role").getCollector().filterBy(${JSON.stringify({894 $or: [895 { field: 'name', operator: '=', value: 'role-1' },896 { field: 'name', operator: '=', value: 'role-2' },897 { field: 'name', operator: '=', value: 'role-3' }898 ]899 })}).exec() >> update records >> dataSource.write()`,900 action: 'restore'901 }, result);902 expect(result).toEqual(true);903 handler = makeHandler();904 const count = await handler.getQueryExecutor().count();905 expect(count).toEqual(4);906 });907 });...

Full Screen

Full Screen

sp.js

Source:sp.js Github

copy

Full Screen

...4const spData = require('../common/sp-data.js');5const spCm = require('./sp-cm.js');6const spRta = require('./sp-rta.js');7const collectorCache = {};8async function getCollector(domain, entityId, scope = 'general') {9 const cacheTag = `${entityId}:${scope}`;10 if (collectorCache[cacheTag]) {11 return collectorCache[cacheTag];12 }13 let collector = null;14 const errors = [];15 for (const c of [spCm(domain, entityId), spRta(domain, entityId)]) {16 try {17 await c.probe();18 collector = c;19 break;20 }21 catch (ex) {22 const handled = bg.handleServerErrors(ex, 'sp.getCollector:' + c.name);23 if (handled == 'amazonNotLoggedIn') {24 // treat this as if it were success, then let the error25 // propagate when we try to get the real page.26 collector = c;27 break;28 }29 errors.push(`${c.name}: ${ga.errorToString(ex)}`);30 console.log('Probe failed for', domain, entityId, c.name, ga.errorToString(ex));31 }32 }33 if (!collector) {34 console.log(`No valid collectors for ${domain} ${cacheTag}: ${errors}`);35 ga.mga('event', 'no-valid-collector', cacheTag, errors.join(', '));36 throw new Error(`No valid collectors for ${domain}`);37 }38 collectorCache[cacheTag] = collector;39 console.log('Using collector', domain, cacheTag, collector.name);40 ga.mga('event', 'collector-domain', domain, collector.name);41 return collector;42}43async function requestLifetimeCampaignData({ entity }) {44 const collector = await getCollector(entity.domain, entity.entityId);45 return collector.getLifetimeCampaignData();46}47async function requestDailyCampaignData({ entity, date }) {48 const collector = await getCollector(entity.domain, entity.entityId);49 return collector.getDailyCampaignData(date);50}51async function requestAdGroupId({ entity, campaignId }) {52 const collector = await getCollector(entity.domain, entity.entityId);53 return collector.getAdGroupId(campaignId);54}55async function requestCampaignAsin({ entity, campaignId, adGroupId }) {56 const collector = await getCollector(entity.domain, entity.entityId);57 return collector.getCampaignAsin(campaignId, adGroupId);58}59async function requestKeywordData({ entity, campaignId, adGroupId }) {60 const collector = await getCollector(entity.domain, entity.entityId);61 return collector.getKeywordData(campaignId, adGroupId);62}63async function requestDailyKeywordData({ entity, campaignId, adGroupId, date }) {64 const collector = await getCollector(entity.domain, entity.entityId);65 return collector.getDailyKeywordData(campaignId, adGroupId, date);66}67function requestAdEntities({ domain }) {68 const collector = spCm(domain);69 return collector.getAdEntities();70}71async function updateKeyword({ entity, keywords, operation, dataValues }) {72 if (!keywords || !keywords.length) {73 return { ok: [], fail: [] };74 }75 if (typeof keywords == 'string') {76 keywords = [keywords];77 }78 const collector = await getCollector(entity.domain, entity.entityId);79 return collector.updateKeywords({ keywords, operation, dataValues });80}81async function addKeywords({ entity, adGroupId, keywords }) {82 const collector = await getCollector(entity.domain, entity.entityId);83 adGroupId = spData.stripPrefix(adGroupId);84 keywords = _.uniqBy(keywords, kw => kw.keyword);85 const result = await collector.addKeywords({ keywords, adGroupId });86 return result;87}88async function updateCampaigns({ entity, campaigns, operation, dataValues }) {89 if (!campaigns || !campaigns.length) {90 return { ok: [], fail: [] };91 }92 const collector = await getCollector(entity.domain, entity.entityId);93 const result = await collector.updateCampaigns({ campaigns, operation, dataValues });94 return result;95}96async function requestPortfolios({ entity }) {97 const { domain, entityId } = entity;98 const collector = await getCollector(domain, entityId);99 return collector.getPortfolios();100}101module.exports = {102 name: 'sp',103 addKeywords,104 requestAdEntities,105 requestAdGroupId,106 requestCampaignAsin,107 requestDailyCampaignData,108 requestKeywordData,109 requestDailyKeywordData,110 requestLifetimeCampaignData,111 requestPortfolios,112 updateCampaigns,...

Full Screen

Full Screen

lib-spec.js

Source:lib-spec.js Github

copy

Full Screen

...3const getCollector = function (keys) {4 return new Collector(keys).initialization();5}6test('basic log func', t => {7 let c = getCollector();8 c.log('test', -999);9 t.is(c.$logs.length, 1);10 c.markLog('test', 'test');11 t.is(c.$marks.length, 1);12 c.clear();13 t.falsy(c.$logs.length || c.$marks.length);14});15test('key value log', t => {16 let c = getCollector(['test1', 'test2']);17 18 c.data('test1', 'bullshit')19 .data('test2', 'nice')20 .data('test2', 'bueatiful');21 22 t.deepEqual(c.$datas, {23 test1: ['bullshit'],24 test2: ['nice', 'bueatiful']25 });26});27test('log exports', t => {28 let c = getCollector(['data1']);29 30 c.log('me', 1).markLog('me', 1).data('data1', 1);31 32 t.regex(c.export2text(), /data1/);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var istanbul = require('istanbul');2var collector = istanbul.utils.getCollector('coverage/coverage.json');3var reporter = new istanbul.Reporter();4reporter.addAll(['lcov', 'text-summary']);5reporter.write(collector, true, function () {6 console.log('All reports generated');7});8"scripts": {9 },10var app = require('../app');11var request = require('supertest');12var assert = require('assert');13describe('GET /', function() {14 it('respond with hello world', function(done) {15 request(app)16 .get('/')17 .expect('Hello World', done);18 });19});

Full Screen

Using AI Code Generation

copy

Full Screen

1var istanbul = require("istanbul");2var collector = istanbul.utils.getCollector("coverage.json");3var reporter = new istanbul.Reporter();4reporter.addAll(["lcov", "json", "text", "html"]);5reporter.write(collector, true, function() {6 console.log("done");7});

Full Screen

Using AI Code Generation

copy

Full Screen

1var istanbul = require('istanbul');2var collector = istanbul.utils.createCollector();3var reporter = new istanbul.Reporter();4var report = istanbul.Report.create('html');5reporter.add(report);6collector.add(JSON.parse(fs.readFileSync('coverage/coverage.json', 'utf8')));7reporter.write(collector, true, function () {8 console.log('All reports generated');9});10var istanbul = require('istanbul');11var collector = istanbul.utils.createCollector();12var reporter = new istanbul.Reporter();13var report = istanbul.Report.create('html');14reporter.add(report);15collector.add(JSON.parse(fs.readFileSync('coverage/coverage.json', 'utf8')));16reporter.write(collector, true, function () {17 console.log('All reports generated');18});19var istanbul = require('istanbul');20var collector = istanbul.utils.createCollector();21var reporter = new istanbul.Reporter();22var report = istanbul.Report.create('html');23reporter.add(report);24collector.add(JSON.parse(fs.readFileSync('coverage/coverage.json', 'utf8')));25reporter.write(collector, true, function () {26 console.log('All reports generated');27});28var istanbul = require('istanbul');29var collector = istanbul.utils.createCollector();30var reporter = new istanbul.Reporter();31var report = istanbul.Report.create('html');32reporter.add(report);33collector.add(JSON.parse(fs.readFileSync('coverage/coverage.json', 'utf8')));34reporter.write(collector, true, function () {35 console.log('All reports generated');36});37var istanbul = require('istanbul');38var collector = istanbul.utils.createCollector();39var reporter = new istanbul.Reporter();40var report = istanbul.Report.create('html');41reporter.add(report);42collector.add(JSON.parse(fs.readFileSync('coverage/coverage.json', 'utf8')));43reporter.write(collector, true, function () {44 console.log('All reports generated');45});

Full Screen

Using AI Code Generation

copy

Full Screen

1var istanbul = require('istanbul');2var collector = istanbul.libReport.create('json');3collector.add(__dirname + '/coverage/coverage.json');4var finalCoverage = collector.getFinalCoverage();5var summary = istanbul.libReport.summarizers.pkg(finalCoverage);6var reporter = istanbul.libReport.create('lcov');7reporter.writeReport(collector, true);8{9 "scripts": {10 },11 "devDependencies": {12 }13}

Full Screen

Using AI Code Generation

copy

Full Screen

1const istanbul = require('istanbul');2const collector = istanbul.Collector();3collector.add(__coverage__);4const reporter = istanbul.Report.create('lcov', {});5reporter.writeReport(collector, true);6const fs = require('fs');7const istanbul = require('istanbul');8const collector = istanbul.Collector();9collector.add(__coverage__);10const reporter = istanbul.Report.create('lcov', {});11reporter.writeReport(collector, true, () => {12 fs.readFile('lcov.info', 'utf8', (err, data) => {13 if (err) throw err;14 console.log(data);15 });16});

Full Screen

Using AI Code Generation

copy

Full Screen

1var middleware = require('istanbul-middleware');2var collector = middleware.getCollector();3collector.add(coverageData);4res.send('done');5});6app.listen(3000, function () {7console.log('Example app listening on port 3000!');8});9The collector has a method called report() which generates the reports. The report() method accepts two arguments:10Error object (if any)11collector.report(true, function (err, coverage) {12if (err) {13console.log(err);14} else {15middleware.generateReport(coverage, function (err, report) {16if (err) {17console.log(err);18} else {19console.log(report);20}21});22}23});24The collector has a method called report() which generates the reports. The report() method accepts two arguments:25Error object (if any)26collector.report(true, function (err, coverage) {27if (err) {28console.log(err);29} else {30middleware.generateReport(coverage, function (err, report) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var collector = istanbul.getCollector();2collector.add(coverage);3collector.write();4Thanks for the reply. I have added the path option in instrumenter.instrumentSync() as suggested. But I am getting the following error:5 at Collector.add (/home/srikanth/istanbul/node_modules/istanbul/lib/collector.js:47:27)6 at Object.<anonymous> (/home/srikanth/istanbul/test.js:8:9)7 at Module._compile (module.js:456:26)8 at Object..js (module.js:474:10)9 at Module.load (module.js:356:32)10 at Function.Module._load (module.js:312:12)11 at Function.Module.runMain (module.js:497:10)12 at startup (node.js:119:16)

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run istanbul automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful