How to use anAction method in root

Best JavaScript code snippet using root

middleware.js

Source:middleware.js Github

copy

Full Screen

1import firMiddleware from '../src/middleware';2import CALL_FIR_API from '../src/CALL_FIR_API';3import firConfig from './config';4import firebase from 'firebase';5jest.setTimeout(10000);6firebase.initializeApp(firConfig)7describe('firMiddleware must be a Redux middleware', () => {8 const doGetState = () => {};9 const nextHandler = firMiddleware(firebase)({ getState: doGetState });10 const doNext = () => {};11 const actionHandler = nextHandler(doNext);12 test('must take one argument', () => {13 expect(firMiddleware.length).toBe(1)14 })15 16 describe('next handler', () => {17 test('must return a function to handle next', () => {18 expect(typeof nextHandler).toBe('function')19 })20 test('must take one argument', () => {21 expect(nextHandler.length).toBe(1);22 })23 })24 describe('action handler', () => {25 test('must return a function to handle action', () => {26 expect(typeof actionHandler).toBe('function');27 })28 test('must take one argument', () => {29 expect(actionHandler.length).toBe(1);30 })31 })32})33describe('firMiddleware must pass actions without an [CALL_API] symbol to the next handler', () => {34 const doGetState = () => {};35 const anAction = {};36 const nextHandler = firMiddleware(firebase)({ getState: doGetState });37 test('should pass action to next handler', done => {38 const doNext = action => {39 expect(anAction).toBe(action)40 done();41 };42 const actionHandler = nextHandler(doNext);43 44 actionHandler(anAction);45 })46 test("mustn't return a promise on actions", () => {47 const doNext = action => action;48 const actionHandler = nextHandler(doNext);49 50 const noProm = actionHandler(anAction);51 expect(typeof noProm.then).toBe("undefined");52 });53})54describe('firMiddleware must pass valid request `types`', () => {55 const doGetState = () => {};56 const nextHandler = firMiddleware(firebase)({ getState: doGetState });57 58 test('must return a promise on actions with a [CALL_FIR] property', () => {59 const doNext = action => action;60 const actionHandler = nextHandler(doNext);61 62 const yesProm = actionHandler({[CALL_FIR_API]: {}});63 expect(typeof yesProm.then).toBe('function');64 });65 test('Must dispatch an error request for an invalid FirAction with a string request type', done => {66 const anAction = {67 [CALL_FIR_API]: {68 types: ['REQUEST']69 }70 };71 const doGetState = () => {};72 const nextHandler = firMiddleware(firebase)({ getState: doGetState });73 const doNext = action => {74 expect(action.type).toBe('REQUEST');75 expect(action.payload.name).toBe('InvalidFirAction');76 expect(action.error).toBe(true);77 done();78 };79 const actionHandler = nextHandler(doNext);80 81 actionHandler(anAction);82 });83 84 test('Must dispatch an error request for an invalid FirAction with a descriptor request type', done => {85 const anAction = {86 [CALL_FIR_API]: {87 types: [88 {89 type: 'REQUEST'90 }91 ]92 }93 };94 const doGetState = () => {};95 const nextHandler = firMiddleware(firebase)({ getState: doGetState });96 const doNext = action => {97 expect(action.type).toBe('REQUEST');98 expect(action.payload.name).toBe('InvalidFirAction');99 expect(action.error).toBe(true);100 done();101 };102 const actionHandler = nextHandler(doNext);103 actionHandler(anAction);104 });105 test('Must do nothing for an invalid request without a request type', done => {106 const anAction = {107 [CALL_FIR_API]: {}108 };109 const doGetState = () => {};110 const nextHandler = firMiddleware(firebase)({ getState: doGetState });111 const doNext = () => {112 throw Error('next handler called');113 };114 const actionHandler = nextHandler(doNext);115 116 actionHandler(anAction);117 setTimeout(() => {118 done();119 }, 200);120 });121 test('method must defined', done => {122 const anAction = {123 [CALL_FIR_API]: {124 ref: (db) => db.ref()125 }126 };127 const doGetState = () => {};128 const nextHandler = firMiddleware(firebase)({ getState: doGetState });129 const doNext = () => {130 throw Error('next handler called');131 };132 const actionHandler = nextHandler(doNext);133 134 actionHandler(anAction);135 setTimeout(() => {136 done();137 }, 200);138 });139})140describe('firMiddleware must dispatch an error request when FirAction have wrong ref type', () => {141 test('ref must defined', done => {142 const anAction = {143 [CALL_FIR_API]: {144 types: ['REQUEST', 'SUCCESS', 'FAILURE'],145 method: "once_value"146 }147 };148 const doGetState = () => {};149 const nextHandler = firMiddleware(firebase)({ getState: doGetState });150 const doNext = (action) => {151 expect(action.type).toBe('REQUEST');152 expect(action.payload.name).toBe('InvalidFirAction');153 expect(action.payload.validationErrors[0]).toBe('[CALL_API].ref property must have an ref property');154 expect(action.error).toBe(true);155 done();156 };157 const actionHandler = nextHandler(doNext);158 159 actionHandler(anAction);160 });161 test('ref type is a string which is invalid', done => {162 const anAction = {163 [CALL_FIR_API]: {164 types: ['REQUEST', 'SUCCESS', 'FAILURE'],165 ref: "/test",166 method: "once_value"167 }168 };169 const doGetState = () => {};170 const nextHandler = firMiddleware(firebase)({ getState: doGetState });171 const doNext = (action) => {172 expect(action.type).toBe('REQUEST');173 expect(action.payload.name).toBe('InvalidFirAction');174 expect(action.payload.validationErrors[0]).toBe('[CALL_API].ref property must be a function');175 expect(action.error).toBe(true);176 done();177 };178 const actionHandler = nextHandler(doNext);179 180 actionHandler(anAction);181 });182 test('ref type return type is not firebase.database.Reference', done => {183 // https://firebase.google.com/docs/reference/js/firebase.database.Reference184 const anAction = {185 [CALL_FIR_API]: {186 types: ['REQUEST', 'SUCCESS', 'FAILURE'],187 ref: () => 'test',188 method: "once_value"189 }190 };191 const doGetState = () => {};192 const nextHandler = firMiddleware(firebase)({ getState: doGetState });193 const doNext = (action) => {194 expect(action.type).toBe('REQUEST');195 expect(action.payload.name).toBe('InvalidFirAction');196 expect(action.payload.validationErrors[0]).toBe('[CALL_API].ref property must be an instance of firebase.database.Reference or firebase.database.Query');197 expect(action.error).toBe(true);198 done();199 };200 const actionHandler = nextHandler(doNext);201 202 actionHandler(anAction);203 });204})205describe('firMiddleware must dispatch an error request when FirAction have wrong `method` type', () => {206 test('method must defined', done => {207 const anAction = {208 [CALL_FIR_API]: {209 types: ['REQUEST', 'SUCCESS', 'FAILURE'],210 ref: (db) => db.ref()211 }212 };213 const doGetState = () => {};214 const nextHandler = firMiddleware(firebase)({ getState: doGetState });215 const doNext = (action) => {216 expect(action.type).toBe('REQUEST');217 expect(action.payload.name).toBe('InvalidFirAction');218 expect(action.payload.validationErrors[0]).toBe('[CALL_API].method must have a method property');219 expect(action.error).toBe(true);220 done();221 };222 const actionHandler = nextHandler(doNext);223 224 actionHandler(anAction);225 });226 test('method type must be one of the method types', done => {227 const anAction = {228 [CALL_FIR_API]: {229 types: ['REQUEST', 'SUCCESS', 'FAILURE'],230 ref: (db) => db.ref(),231 method: "test"232 }233 };234 const doGetState = () => {};235 const nextHandler = firMiddleware(firebase)({ getState: doGetState });236 const doNext = (action) => {237 expect(action.type).toBe('REQUEST');238 expect(action.payload.name).toBe('InvalidFirAction');239 expect(action.payload.validationErrors[0]).toMatch('Invalid [CALL_API].method: test, must be one of');240 expect(action.error).toBe(true);241 done();242 };243 const actionHandler = nextHandler(doNext);244 245 actionHandler(anAction);246 });247 test('method must be a string', done => {248 const anAction = {249 [CALL_FIR_API]: {250 types: ['REQUEST', 'SUCCESS', 'FAILURE'],251 ref: (db) => db.ref(),252 method: false253 }254 };255 const doGetState = () => {};256 const nextHandler = firMiddleware(firebase)({ getState: doGetState });257 const doNext = (action) => {258 expect(action.type).toBe('REQUEST');259 expect(action.payload.name).toBe('InvalidFirAction');260 expect(action.payload.validationErrors[0]).toBe('[CALL_API].method property must be a string');261 expect(action.error).toBe(true);262 done();263 };264 const actionHandler = nextHandler(doNext);265 266 actionHandler(anAction);267 });268})269describe('firMiddleware get value from firebase reference once', () => {270 test('get the `/test` value once', done => {271 firebase.database().ref('test').set({hello: 'world'})272 const anAction = {273 [CALL_FIR_API]: {274 types: ['REQUEST', 'SUCCESS', 'FAILURE'],275 ref: (db) => db.ref('/test'),276 method: 'once_value'277 }278 };279 const doGetState = () => {};280 const nextHandler = firMiddleware(firebase)({ getState: doGetState });281 const doNext = (action) => {282 if (action.type === 'SUCCESS') {283 expect(action.payload.val()).toEqual({hello: 'world'});284 done();285 }286 };287 const actionHandler = nextHandler(doNext);288 289 actionHandler(anAction);290 });291})292describe('firMiddleware `set` value', () => {293 test('set the `/test` value with {foo: "bar"}', done => {294 firebase.database().ref('test').set({hello: 'world'})295 const anAction = {296 [CALL_FIR_API]: {297 types: ['REQUEST', 'SUCCESS', 'FAILURE'],298 ref: (db) => db.ref('/test'),299 method: 'set',300 content: {foo: "bar"}301 }302 };303 const doGetState = () => {};304 const nextHandler = firMiddleware(firebase)({ getState: doGetState });305 const doNext = (action) => {306 if (action.type === 'SUCCESS') {307 firebase.database().ref('test').once('value')308 .then(dataSnapshot => {309 expect(dataSnapshot.val()).toEqual({foo: 'bar'});310 done();311 })312 }313 };314 const actionHandler = nextHandler(doNext);315 316 actionHandler(anAction);317 });318})319describe('firMiddleware `update` value', () => {320 test('update the `/test` value with {foo: "bar"}', done => {321 firebase.database().ref('test').set({hello: 'world'})322 const anAction = {323 [CALL_FIR_API]: {324 types: ['REQUEST', 'SUCCESS', 'FAILURE'],325 ref: (db) => db.ref('/test'),326 method: 'update',327 content: {foo: "bar"}328 }329 };330 const doGetState = () => {};331 const nextHandler = firMiddleware(firebase)({ getState: doGetState });332 const doNext = (action) => {333 if (action.type === 'SUCCESS') {334 firebase.database().ref('test').once('value')335 .then(dataSnapshot => {336 expect(dataSnapshot.val()).toEqual({337 foo: 'bar',338 hello: 'world'339 });340 done();341 })342 }343 };344 const actionHandler = nextHandler(doNext);345 346 actionHandler(anAction);347 });348})349describe('firMiddleware `remove` value', () => {350 test('remove the `/test` value with {foo: "bar"}', done => {351 firebase.database().ref('test').set({hello: 'world'})352 const anAction = {353 [CALL_FIR_API]: {354 types: ['REQUEST', 'SUCCESS', 'FAILURE'],355 ref: (db) => db.ref('/test'),356 method: 'remove'357 }358 };359 const doGetState = () => {};360 const nextHandler = firMiddleware(firebase)({ getState: doGetState });361 const doNext = (action) => {362 if (action.type === 'SUCCESS') {363 firebase.database().ref('test').once('value')364 .then(dataSnapshot => {365 expect(dataSnapshot.val()).toEqual(null);366 done();367 })368 }369 };370 const actionHandler = nextHandler(doNext);371 372 actionHandler(anAction);373 });374})375describe('firMiddleware `on_value` listen new values', () => {376 test('listen ref `/test` for update value with {foo: "bar"}', done => {377 firebase.database().ref('test').set({hello: 'world'})378 let updateValueTest = false379 const anAction = {380 [CALL_FIR_API]: {381 types: ['REQUEST', 'SUCCESS', 'FAILURE'],382 ref: (db) => db.ref('/test'),383 method: 'on_value'384 }385 };386 const doGetState = () => {};387 const nextHandler = firMiddleware(firebase)({ getState: doGetState });388 const doNext = (action) => {389 if (action.type === 'SUCCESS' && !updateValueTest) {390 updateValueTest = true391 firebase.database().ref('test').update({foo: 'bar'})392 } else if (action.type === 'SUCCESS' && updateValueTest) {393 expect(action.payload.val()).toEqual({ foo: 'bar', hello: 'world' });394 action.off();395 done();396 }397 };398 const actionHandler = nextHandler(doNext);399 400 actionHandler(anAction);401 });402 test('`/test` listen value and unsubscribe', done => {403 firebase.database().ref('test').set({hello: 'world'})404 const anAction = {405 [CALL_FIR_API]: {406 types: ['REQUEST', 'SUCCESS', 'FAILURE'],407 ref: (db) => db.ref('/test'),408 method: 'on_value'409 }410 };411 const doGetState = () => {};412 const testCall = jest.fn();413 const nextHandler = firMiddleware(firebase)({ getState: doGetState });414 const doNext = (action) => {415 if (action.type === 'SUCCESS') {416 testCall();417 action.off();418 firebase.database().ref('test').update({foo: 'bar'})419 .then(() => {420 expect(testCall).toHaveBeenCalledTimes(1);421 done();422 })423 }424 };425 const actionHandler = nextHandler(doNext);426 427 actionHandler(anAction);428 });429 test('`/test` listen value with query ', done => {430 firebase.database().ref('test').set({431 howard: {score: 140},432 bob: {score: 99},433 william: {score: 120}434 })435 const anAction = {436 [CALL_FIR_API]: {437 types: ['REQUEST', 'SUCCESS', 'FAILURE'],438 ref: (db) => db.ref('/test').orderByChild("score").equalTo(120),439 method: 'on_value'440 }441 };442 const doGetState = () => {};443 const nextHandler = firMiddleware(firebase)({ getState: doGetState });444 const doNext = (action) => {445 if (action.type === 'SUCCESS') {446 expect(action.payload.val()).toEqual({"william": {"score": 120}});447 action.off();448 done();449 }450 };451 const actionHandler = nextHandler(doNext);452 453 actionHandler(anAction);454 });455})456describe('firMiddleware `on_child_added` listen new values', () => {457 test('listen ref `/test` for update value with {foo: "bar"}', done => {458 firebase.database().ref('test').set({hello: 'world'})459 let updateValueTest = false460 const anAction = {461 [CALL_FIR_API]: {462 types: ['REQUEST', 'SUCCESS', 'FAILURE'],463 ref: (db) => db.ref('/test'),464 method: 'on_child_added'465 }466 };467 const doGetState = () => {};468 const nextHandler = firMiddleware(firebase)({ getState: doGetState });469 const doNext = (action) => {470 if (action.type === 'SUCCESS' && !updateValueTest) {471 updateValueTest = true472 firebase.database().ref('test').update({hello2: 'bar'})473 } else if (action.type === 'SUCCESS' && updateValueTest) {474 expect(action.payload.childSnapshot.val()).toEqual("bar");475 expect(action.payload.prevChildKey).toEqual("hello");476 action.off();477 done();478 }479 };480 const actionHandler = nextHandler(doNext);481 482 actionHandler(anAction);483 });484 test('`/test` listen value and unsubscribe', done => {485 firebase.database().ref('test').set({hello: 'world'})486 const anAction = {487 [CALL_FIR_API]: {488 types: ['REQUEST', 'SUCCESS', 'FAILURE'],489 ref: (db) => db.ref('/test'),490 method: 'on_child_added'491 }492 };493 const doGetState = () => {};494 const testCall = jest.fn();495 const nextHandler = firMiddleware(firebase)({ getState: doGetState });496 const doNext = (action) => {497 if (action.type === 'SUCCESS') {498 testCall();499 action.off();500 firebase.database().ref('test').update({foo: 'bar'})501 .then(() => firebase.database().ref('test').once('value'))502 .then((snapShot) => {503 expect(snapShot.val()).toEqual({foo: 'bar', hello: 'world'})504 expect(testCall).toHaveBeenCalledTimes(1);505 done();506 })507 }508 };509 const actionHandler = nextHandler(doNext);510 511 actionHandler(anAction);512 });513})514describe('firMiddleware `on_child_added` listen new values', () => {515 test('listen ref `/test` for update value with {foo: "bar"}', done => {516 firebase.database().ref('test').set({hello: 'world'})517 let updateValueTest = false518 const anAction = {519 [CALL_FIR_API]: {520 types: ['REQUEST', 'SUCCESS', 'FAILURE'],521 ref: (db) => db.ref('/test'),522 method: 'on_child_added'523 }524 };525 const doGetState = () => {};526 const nextHandler = firMiddleware(firebase)({ getState: doGetState });527 const doNext = (action) => {528 if (action.type === 'SUCCESS' && !updateValueTest) {529 updateValueTest = true530 firebase.database().ref('test').update({hello2: 'bar'})531 } else if (action.type === 'SUCCESS' && updateValueTest) {532 expect(action.payload.childSnapshot.val()).toEqual("bar");533 expect(action.payload.prevChildKey).toEqual("hello");534 action.off();535 done();536 }537 };538 const actionHandler = nextHandler(doNext);539 540 actionHandler(anAction);541 });542 test('`/test` listen value and unsubscribe', done => {543 firebase.database().ref('test').set({hello: 'world'})544 const anAction = {545 [CALL_FIR_API]: {546 types: ['REQUEST', 'SUCCESS', 'FAILURE'],547 ref: (db) => db.ref('/test'),548 method: 'on_child_added'549 }550 };551 const doGetState = () => {};552 const testCall = jest.fn();553 const nextHandler = firMiddleware(firebase)({ getState: doGetState });554 const doNext = (action) => {555 if (action.type === 'SUCCESS') {556 testCall();557 action.off();558 firebase.database().ref('test').update({foo: 'bar'})559 .then(() => firebase.database().ref('test').once('value'))560 .then((snapShot) => {561 expect(snapShot.val()).toEqual({foo: 'bar', hello: 'world'})562 expect(testCall).toHaveBeenCalledTimes(1);563 done();564 })565 }566 };567 const actionHandler = nextHandler(doNext);568 569 actionHandler(anAction);570 });571})572describe('firMiddleware `on_child_changed` listen new values', () => {573 test('listen ref `/test` for update value with {foo: "bar"}', done => {574 firebase.database().ref('test').set({hello: 'world'})575 const anAction = {576 [CALL_FIR_API]: {577 types: ['REQUEST', 'SUCCESS', 'FAILURE'],578 ref: (db) => db.ref('/test'),579 method: 'on_child_changed'580 }581 };582 const doGetState = () => {};583 const nextHandler = firMiddleware(firebase)({ getState: doGetState });584 const doNext = (action) => {585 if (action.type === 'SUCCESS') {586 expect(action.payload.childSnapshot.val()).toEqual({foo: "bar"});587 expect(action.payload.prevChildKey).toEqual(null);588 action.off();589 done();590 }591 };592 const actionHandler = nextHandler(doNext);593 actionHandler(anAction)594 .then(() => {595 firebase.database().ref('test/hello').update({foo: 'bar'})596 });597 });598 test('`/test` listen value and unsubscribe', done => {599 firebase.database().ref('test').set({hello: 'world'})600 const anAction = {601 [CALL_FIR_API]: {602 types: ['REQUEST', 'SUCCESS', 'FAILURE'],603 ref: (db) => db.ref('/test'),604 method: 'on_child_changed'605 }606 };607 const doGetState = () => {};608 const testCall = jest.fn();609 const nextHandler = firMiddleware(firebase)({ getState: doGetState });610 const doNext = (action) => {611 if (action.type === 'SUCCESS') {612 testCall();613 action.off();614 firebase.database().ref('test/hello').update({foo: 'bar2'})615 .then(() => {616 expect(testCall).toHaveBeenCalledTimes(1);617 done();618 })619 }620 };621 const actionHandler = nextHandler(doNext);622 623 actionHandler(anAction)624 .then(() => {625 firebase.database().ref('test/hello').update({foo: 'bar'})626 });627 });628})629describe('firMiddleware `on_child_removed` listen new values', () => {630 test('listen ref `/test` for removed value with {foo: "bar"}', done => {631 firebase.database().ref('test').set({632 hello: 'world',633 foo: 'bar'634 })635 const anAction = {636 [CALL_FIR_API]: {637 types: ['REQUEST', 'SUCCESS', 'FAILURE'],638 ref: (db) => db.ref('/test'),639 method: 'on_child_removed'640 }641 };642 const doGetState = () => {};643 const nextHandler = firMiddleware(firebase)({ getState: doGetState });644 const doNext = (action) => {645 if (action.type === 'SUCCESS') {646 expect(action.payload.val()).toEqual("bar");647 action.off();648 done();649 }650 };651 const actionHandler = nextHandler(doNext);652 actionHandler(anAction)653 .then(() => {654 firebase.database().ref('test/foo').remove()655 });656 });657 test('`/test` listen child_removed and unsubscribe', done => {658 firebase.database().ref('test').set({659 hello: 'world',660 foo: "bar"661 })662 const anAction = {663 [CALL_FIR_API]: {664 types: ['REQUEST', 'SUCCESS', 'FAILURE'],665 ref: (db) => db.ref('/test'),666 method: 'on_child_removed'667 }668 };669 const doGetState = () => {};670 const testCall = jest.fn();671 const nextHandler = firMiddleware(firebase)({ getState: doGetState });672 const doNext = (action) => {673 if (action.type === 'SUCCESS') {674 testCall();675 action.off();676 firebase.database().ref('test/foo').remove()677 .then(() => {678 expect(testCall).toHaveBeenCalledTimes(1);679 done();680 })681 }682 };683 const actionHandler = nextHandler(doNext);684 685 actionHandler(anAction)686 .then(() => {687 firebase.database().ref('test/hello').remove()688 });689 });690})691describe('firMiddleware `on_child_moved` listen new values', () => {692 test('listen ref `/test` for moved child sort by height', done => {693 firebase.database().ref('test').set({694 howard: {height: 100},695 bob: {height: 200}696 })697 const anAction = {698 [CALL_FIR_API]: {699 types: ['REQUEST', 'SUCCESS', 'FAILURE'],700 ref: (db) => db.ref('/test').orderByChild("height"),701 method: 'on_child_moved'702 }703 };704 const doGetState = () => {};705 const nextHandler = firMiddleware(firebase)({ getState: doGetState });706 const doNext = (action) => {707 if (action.type === 'SUCCESS') {708 expect(action.payload.childSnapshot.val()).toEqual({height: 50});709 action.off();710 done();711 }712 };713 const actionHandler = nextHandler(doNext);714 actionHandler(anAction)715 .then(() => {716 firebase.database().ref('/test/bob/height').set(50)717 });718 });719 test('`/test` listen child_moved and unsubscribe', done => {720 firebase.database().ref('test').set({721 howard: {height: 100},722 bob: {height: 200}723 })724 const anAction = {725 [CALL_FIR_API]: {726 types: ['REQUEST', 'SUCCESS', 'FAILURE'],727 ref: (db) => db.ref('/test').orderByChild("height"),728 method: 'on_child_moved'729 }730 };731 const doGetState = () => {};732 const testCall = jest.fn();733 const nextHandler = firMiddleware(firebase)({ getState: doGetState });734 const doNext = (action) => {735 if (action.type === 'SUCCESS') {736 testCall();737 action.off();738 firebase.database().ref('/test/bob/height').set(200)739 .then(() => {740 expect(testCall).toHaveBeenCalledTimes(1);741 done();742 })743 }744 };745 const actionHandler = nextHandler(doNext);746 747 actionHandler(anAction)748 .then(() => {749 firebase.database().ref('/test/bob/height').set(50)750 });751 });...

Full Screen

Full Screen

backEndTasks.js

Source:backEndTasks.js Github

copy

Full Screen

1var CronJob = require('cron').CronJob;2var Actionitem = require('../actionItem/actionItem.model');3var Contact = require('../contact/contact.model');4var _ = require('lodash');5var nodemailer = require('nodemailer');6var User = require('../user/user.model');7var Project = require('../project/project.model');8var job = new CronJob({9 cronTime: '* * 5 * * *',10 onTick: function() {11 console.log('Job: You will see this message once a Day');12 Actionitem.find(function (err, actionItems) {13 if(err) { return handleError(res, err); }14 // return res.json(200, actionItems);15 var currentTime = new Date();16 actionItems.forEach(function(obj) {17 var actionItemTitle = obj.title;18 var actionItemDescription = obj.description;19 if (!obj.completed && (((obj.dueDate - currentTime)/(1000 * 3600 *24)) < 1)) {20 console.log( (obj.dueDate - currentTime)/(1000 * 3600 *24) );21 if (((obj.dueDate - currentTime)/(1000 * 3600 *24)) < 0) {22 txtSubject = '★URGENT★: Task IS Past Due';23 } else {24 txtSubject = '★REMINDER★: Task Due Tomorrow';25 }26 Contact.findById(obj.owner, function (err, contact) {27 if(err) { return handleError(res, err); }28 // if(!contact) { return res.send(404); }29 // return res.json(contact);30 var ownerName = contact.name;31 var ownerEmail = contact.email;32 Project.findById(obj.project, function (err, project) {33 if(err) {return handleError(res, err); }34 var userEmail = project.userEmail;35 var projectName = project.name;36 var transporter = nodemailer.createTransport({37 service: 'Gmail',38 auth: {39 user: 'suiteproductivity@gmail.com',40 pass: 'simple!123'41 }42 });43 // setup e-mail data with unicode symbols44 var mailOptions = {45 from: userEmail, // 'Fred Foo ✔ <foo@blurdybloop.com>', // sender address46 replyTo: userEmail, // 'martinebutler@gmail.com',47 to: ownerEmail, // list of receivers48 subject: txtSubject, 49 // subject: '★REMINDER★: Task Due Tomorrow', 50 text: 'Hello ' + ownerName +',' + '\n\nProject: ' + projectName51 + '\nTitle: ' + actionItemTitle 52 + '\nDescription: ' + actionItemDescription 53 + '\n\nUpdate @: http://localhost:9000/updateTask/' + obj._id54 };55 // send mail with defined transport object56 transporter.sendMail(mailOptions, function(error, info){57 // if(error){58 // console.log(error);59 // }else{60 // console.log('Message sent: ' + info.response);61 // return res.json(info.response);62 // }63 });64 });65 });66 }67 });68 });69 },70 start: false,71 timeZone: "America/New_York"72});73job.start();74var job2 = new CronJob({75 cronTime: '* * 5 * * *',76 onTick: function() {77 console.log('Job2: You will see this message once a day');78 Project.find(function (err, project) {79 if(err) { return handleError(res, err); }80 // return res.json(200, actionItems);81 // var currentTime = new Date();82 // console.log(actionItems);83 project.forEach(function(obj) {84 // console.log(obj);85 var projectName = obj.name;86 // var emailTxt = '\n\nProject: ' + projectName + '\n\nOpen Action Items:\n';87 Project.findById(obj._id)88 .populate('actionItems')89 .exec(function (err, aItem) {90 if(!aItem) return res.send(401);91 // console.log('aItem:', aItem.actionItems);92 var allActionItemsForAProject = aItem.actionItems;93 var emailTxt = '\n\nProject: ' + projectName + '\n\nOpen Action Items:\n';94 var numOfActions = allActionItemsForAProject.length;95 var indexOfActions = 1;96 var count = 1;97 allActionItemsForAProject.forEach(function(obj) {98 // emailTxt += indexOfActions + ') Title: ' + obj.title + '\nDescription: ' + obj.description + '\ndueDate: ' + obj.dueDate;99 var anAction = obj;100 Actionitem.findById(obj._id)101 .populate('owner')102 .exec(function (err, owner) {103 if(!owner) return res.send(401);104// *************105 // console.log('anAction.complete', anAction.completed);106 if (!anAction.completed) {107 emailTxt += count + ') Title: ' + anAction.title + '\nDescription: ' 108 + anAction.description + '\n\ndueDate: ' + anAction.dueDate;109 emailTxt += '\nOwner: ' + owner.owner.name + '\nOwner Email: ' + owner.owner.email 110 + '\nupdate @: http://localhost:9000/updateTask/' + obj._id + '\n\n';111 // if (anAction.updates.length > 0) {112 // emailTxt += '\n\nLast Update: ' + anAction.updates[anAction.updates.length-1];113 // }114 count++;115 } 116 117// *************118 // emailTxt += indexOfActions + ') Title: ' + anAction.title + '\nSTATUS: ' + actionStatus + '\nDescription: ' 119 // + anAction.description + '\ndueDate: ' + anAction.dueDate;120 // emailTxt += '\nOwner: ' + owner.owner.name + '\nOwner Email: ' + owner.owner.email 121 // + '\nupdate @: http://localhost:9000/updateTask/' + obj._id + '\n\n';122 // console.log(emailTxt);123 // console.log(emailTxt) // + emailTxt2);124 indexOfActions++;125 // console.log('all', numOfActions);126 // console.log('index', indexOfActions);127 if (numOfActions == indexOfActions) {128 var transporter = nodemailer.createTransport({129 service: 'Gmail',130 auth: {131 user: 'suiteproductivity@gmail.com',132 pass: 'simple!123'133 }134 });135 // setup e-mail data with unicode symbols136 var mailOptions = {137 from: 'martinebutler@gmail.com', 138 replyTo: 'martinebutler@gmail.com',139 to: 'martinebutler@gmail.com', 140 subject: '★Daily Status★ Project: ' + projectName, 141 text: emailTxt142 };143 // send mail with defined transport object144 transporter.sendMail(mailOptions, function(error, info){145 // if(error){146 // console.log(error);147 // }else{148 // console.log('Message sent: ' + info.response);149 // return res.json(info.response);150 // }151 });152 }153 });154 })155 });156 });157 });158 },159 start: false,160 timeZone: "America/New_York"161});...

Full Screen

Full Screen

WebAPI.ts

Source:WebAPI.ts Github

copy

Full Screen

1/*2 * Tencent is pleased to support the open source community by making TKEStack3 * available.4 *5 * Copyright (C) 2012-2021 Tencent. All Rights Reserved.6 *7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use8 * this file except in compliance with the License. You may obtain a copy of the9 * License at10 *11 * https://opensource.org/licenses/Apache-2.012 *13 * Unless required by applicable law or agreed to in writing, software14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT15 * WARRANTIES OF ANY KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations under the License.17 */18import { OperationResult, QueryState, RecordSet, uuid } from '@tencent/ff-redux';19import { Base64 } from 'js-base64';20import { resourceConfig } from '../../../config/resourceConfig';21import {22 reduceK8sQueryString,23 reduceK8sRestfulPath,24 reduceNetworkRequest,25 reduceNetworkWorkflow26} from '../../../helpers';27import { Method } from '../../../helpers/reduceNetwork';28import { RequestParams, Resource, ResourceFilter, ResourceInfo } from '../common/models';29import { Audit, AuditFilter, AuditFilterConditionValues } from './models';30const tips = seajs.require('tips');31const enum Action {32 ListFieldValues = 'listFieldValues/',33 ListBlockClusters = 'listBlockClusters',34 GetStoreConfig = 'getStoreConfig',35 ConfigTest = 'configTest',36 UpdateStoreConfig = 'updateStoreConfig',37}38// 返回标准操作结果39function operationResult<T>(target: T[] | T, error?: any): OperationResult<T>[] {40 if (target instanceof Array) {41 return target.map(x => ({ success: !error, target: x, error }));42 }43 return [{ success: !error, target: target as T, error }];44}45/** 访问凭证相关 */46export async function fetchAuditList(query: QueryState<AuditFilter>) {47 const { search, paging, filter } = query;48 const { pageIndex, pageSize } = paging;49 const queryObj = {50 pageIndex,51 pageSize,52 ...filter53 };54 const queryString = reduceK8sQueryString({ k8sQueryObj: queryObj });55 const apiKeyResourceInfo: ResourceInfo = resourceConfig()['audit'];56 const url = reduceK8sRestfulPath({57 resourceInfo: apiKeyResourceInfo,58 specificName: 'list/'59 });60 // const url = '/apis/audit.tkestack.io/v1/events/list/';61 const params: RequestParams = {62 method: Method.get,63 url: url + queryString64 };65 const response = await reduceNetworkRequest(params);66 let auditList: any[] = [];67 let totalCount: number = 0;68 try {69 console.log('fetchAuditList response is: ', response);70 if (response.code === 0) {71 auditList = response.data.items;72 totalCount = response.data.total;73 }74 } catch (error) {75 if (+error.response.status !== 404) {76 throw error;77 }78 }79 const result: RecordSet<Audit> = {80 recordCount: totalCount,81 records: auditList82 };83 return result;84}85/**86 * 获取查询条件数据87 */88export async function fetchAuditFilterCondition() {89 return fetchAuditEvents(Action.ListFieldValues);90}91/**92 * 获取audit相关信息93 * anAction可以是:listFieldValues(), listBlockClusters(列出被屏蔽集群列表)94 * @param anAction95 */96export async function fetchAuditEvents(anAction: Action) {97 try {98 const resourceInfo: ResourceInfo = resourceConfig()['audit'];99 const url = reduceK8sRestfulPath({ resourceInfo, specificName: anAction });100 const response = await reduceNetworkRequest({101 method: 'GET',102 url103 });104 if (response.code === 0) {105 return operationResult(response.data);106 } else {107 return operationResult('', response);108 }109 } catch (error) {110 tips.error(error.response.data.message, 2000);111 return operationResult('', error.response);112 }113}114/**115 * 获取审计配置等。Action可以是:getStoreConfig(获取当前es配置)116 * @param anAction117 */118export async function fetchAuditRecord(anAction: Action) {119 try {120 const resourceInfo: ResourceInfo = resourceConfig()['audit'];121 const url = reduceK8sRestfulPath({ resourceInfo, specificName: anAction });122 const response = await reduceNetworkRequest({123 method: 'GET',124 url125 });126 if (response.code === 0) {127 return response.data;128 } else {129 return operationResult('', response);130 }131 } catch (error) {132 tips.error(error.response.data.message, 2000);133 return operationResult('', error.response);134 }135}136/**137 * 获取审计ES配置138 */139export async function getStoreConfig() {140 return fetchAuditRecord(Action.GetStoreConfig);141}142/**143 * 连接检测144 */145export async function configTest(payload) {146 return postAuditEvents(Action.ConfigTest, { elasticSearch: payload })147}148export async function updateStoreConfig(payload) {149 return postAuditEvents(Action.UpdateStoreConfig, { elasticSearch: payload })150}151export async function postAuditEvents(anAction: Action, payload) {152 try {153 const resourceInfo: ResourceInfo = resourceConfig()['audit'];154 const url = reduceK8sRestfulPath({ resourceInfo, specificName: anAction });155 const response = await reduceNetworkRequest({156 method: 'POST',157 url,158 data: payload159 });160 if (response.code === 0) {161 return response.data;162 } else {163 return operationResult('', response);164 }165 } catch (error) {166 tips.error(error.response.data.message, 2000);167 return operationResult('', error.response);168 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = require('./root.js');2root.anAction();3module.exports = {4 anAction: function() {5 console.log('anAction was called');6 }7};8require.paths.unshift('./lib');9var root = require('root');

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = require('root');2root.anAction();3var child = require('child');4child.anAction();5var child = require('child');6child.anAction();7var root = function () {8 var anAction = function () {9 console.log("I am an action of root class");10 }11 return {12 }13}14module.exports = root();15var root = require('root');16var child = function () {17 var anAction = function () {18 console.log("I am an action of child class");19 }20 return {21 }22}23module.exports = child();24var root = require('root');25root.anAction();26var child = require('child');27child.anAction();28var root = function () {29 var anAction = function () {30 console.log("I am an action of root class");31 }32 return {

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = this;2root.anAction();3var child = this.createChild("child");4child.anAction();5var grandchild = child.createChild("grandchild");6grandchild.anAction();7var greatgrandchild = grandchild.createChild("greatgrandchild");8greatgrandchild.anAction();9var greatgreatgrandchild = greatgrandchild.createChild("greatgreatgrandchild");10greatgreatgrandchild.anAction();11var greatgreatgreatgrandchild = greatgreatgrandchild.createChild("greatgreatgreatgrandchild");12greatgreatgreatgrandchild.anAction();13var greatgreatgreatgreatgrandchild = greatgreatgreatgrandchild.createChild("greatgreatgreatgreatgrandchild");14greatgreatgreatgreatgrandchild.anAction();15var greatgreatgreatgreatgreatgrandchild = greatgreatgreatgreatgrandchild.createChild("greatgreatgreatgreatgreatgrandchild");16greatgreatgreatgreatgreatgrandchild.anAction();17var greatgreatgreatgreatgreatgreatgrandchild = greatgreatgreatgreatgreatgrandchild.createChild("greatgreatgreatgreatgreatgreatgrandchild");18greatgreatgreatgreatgreatgreatgrandchild.anAction();19var greatgreatgreatgreatgreatgreatgreatgrandchild = greatgreatgreatgreatgreatgreatgrandchild.createChild("greatgreatgreatgreatgreatgreatgreatgrandchild");20greatgreatgreatgreatgreatgreatgreatgrandchild.anAction();21var greatgreatgreatgreatgreatgreatgreatgreatgrandchild = greatgreatgreatgreatgreatgreatgreatgreatgrandchild.createChild("greatgreatgreatgreatgreatgreatgreatgreatgrandchild");22greatgreatgreatgreatgreatgreatgreatgreatgrandchild.anAction();23var greatgreatgreatgreatgreatgreatgreatgreatgreatgrandchild = greatgreatgreatgreatgreatgreatgreatgreatgreatgrandchild.createChild("

Full Screen

Using AI Code Generation

copy

Full Screen

1rootObject.anAction();2exports.anAction = function() {3 console.log("anAction method of rootObject called");4}5exports.anAction = function() {6 console.log("anAction method of subObject called");7}8subObject.anAction();9exports.anAction = function() {10 console.log("anAction method of subObject called");11}12subObject.anAction();13exports.anAction = function() {14 console.log("anAction method of rootObject called");15}16rootObject.anAction();17exports.anAction = function() {18 console.log("anAction method of rootObject called");19}20exports.anAction = function() {21 console.log("anAction method of subObject called");22}23subObject.anAction();24exports.anAction = function() {25 console.log("anAction method of subObject called");26}27subObject.anAction();28exports.anAction = function() {29 console.log("anAction method of rootObject called");30}31rootObject.anAction();32exports.anAction = function() {33 console.log("anAction method of rootObject called");34}35exports.anAction = function() {36 console.log("anAction method of subObject called");37}

Full Screen

Using AI Code Generation

copy

Full Screen

1var obj = require('root');2obj.anAction();3var obj = require('root');4console.log(obj.aProperty);5var root = {};6root.aProperty = "some value";7root.anAction = function() {8 console.log("some action");9};10module.exports = root;11var obj = require('root');12obj.anAction();13var obj = require('root');14console.log(obj.aProperty);15var root = {};16root.aProperty = "some value";17root.anAction = function() {18 console.log("some action");19};20module.exports = root;

Full Screen

Using AI Code Generation

copy

Full Screen

1root.anAction();2test.anAction();3test.anAction();4root.anAction();5test.anAction();6test.anAction();7root.anAction();8test.anAction();9test.anAction();10root.anAction();11test.anAction();12test.anAction();13root.anAction();14test.anAction();15test.anAction();16root.anAction();17test.anAction();18test.anAction();19root.anAction();20test.anAction();21test.anAction();22root.anAction();23test.anAction();24test.anAction();25root.anAction();26test.anAction();27test.anAction();28root.anAction();29test.anAction();30test.anAction();31root.anAction();32test.anAction();

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = this;2root.anAction();3function anAction() {4}5var root = this;6root.anAction();7function anAction() {8}9var root = this;10root.anAction();11function anAction() {12}13var root = this;14root.anAction();15function anAction() {16}17var root = this;18root.anAction();19function anAction() {20}21var root = this;22root.anAction();23function anAction() {24}25var root = this;26root.anAction();27function anAction() {28}29var root = this;30root.anAction();31function anAction() {32}33var root = this;34root.anAction();35function anAction() {

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 root 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