How to use requiredKeys method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

rabbitmq.js

Source:rabbitmq.js Github

copy

Full Screen

1/**2 * @module unit/models/rabbitmq3 */4'use strict'5var clone = require('101/clone')6var Code = require('code')7var createCount = require('callback-count')8var Lab = require('lab')9var path = require('path')10var Promise = require('bluebird')11var sinon = require('sinon')12var rabbitMQ = require('models/rabbitmq')13var Publisher = require('ponos/lib/rabbitmq')14var lab = exports.lab = Lab.script()15var afterEach = lab.afterEach16var beforeEach = lab.beforeEach17var describe = lab.describe18var expect = Code.expect19var it = lab.it20var moduleName = path.relative(process.cwd(), __filename)21describe('RabbitMQ Model: ' + moduleName, function () {22 beforeEach(function (done) {23 rabbitMQ._publisher = {24 connect: sinon.stub(),25 disconnect: sinon.stub(),26 publishEvent: sinon.stub(),27 publishTask: sinon.stub()28 }29 sinon.stub(Publisher.prototype, 'connect')30 done()31 })32 afterEach(function (done) {33 Publisher.prototype.connect.restore()34 done()35 })36 describe('connect', function () {37 it('should call connect', function (done) {38 Publisher.prototype.connect.returns(Promise.resolve())39 var out = rabbitMQ.connect().asCallback(function (err) {40 if (err) { return done(err) }41 expect(out).to.be.an.instanceof(Promise)42 sinon.assert.calledOnce(rabbitMQ._publisher.connect)43 done()44 })45 })46 })47 describe('disconnect', function () {48 it('should call disconnect', function (done) {49 rabbitMQ._publisher.disconnect.returns('foo')50 var out = rabbitMQ.disconnect()51 expect(out).to.equal('foo')52 sinon.assert.calledOnce(rabbitMQ._publisher.disconnect)53 done()54 })55 })56 describe('CreateImageBuilderContainer', function () {57 var validJobData58 beforeEach(function (done) {59 validJobData = {60 manualBuild: {61 user: 'asdaSDFASDF'62 },63 sessionUserGithubId: 'asdaSDFASDF',64 contextId: '4G23G243G4545',65 contextVersionId: 'G45GH4GERGDSG',66 contextVersionBuildId: 'G45GH4GERGFSG',67 dockerHost: '0.0.0.0',68 noCache: false,69 ownerUsername: 'tjmehta'70 }71 done()72 })73 describe('success', function () {74 it('should publish a job with required data', function (done) {75 rabbitMQ.createImageBuilderContainer(validJobData)76 sinon.assert.calledOnce(rabbitMQ._publisher.publishTask)77 sinon.assert.calledWith(rabbitMQ._publisher.publishTask,78 'build.container.create',79 validJobData)80 done()81 })82 })83 describe('validation errors', function () {84 it('should throw the validation error', function (done) {85 var requiredKeys = Object.keys(validJobData)86 var count = createCount(requiredKeys.length, done)87 requiredKeys.forEach(function (key) {88 var options = clone(validJobData)89 delete options[key]90 try {91 rabbitMQ.createImageBuilderContainer(options)92 } catch (e) {93 expect(e).to.exist()94 expect(e.message).match(new RegExp(key))95 }96 count.next()97 })98 })99 })100 })101 describe('startInstanceContainer', function () {102 var validJobData103 beforeEach(function (done) {104 validJobData = {105 containerId: '123',106 instanceId: '55555',107 sessionUserGithubId: '9494949'108 }109 done()110 })111 describe('success', function () {112 it('should publish a job with required data', function (done) {113 rabbitMQ.startInstanceContainer(validJobData)114 sinon.assert.calledOnce(rabbitMQ._publisher.publishTask)115 sinon.assert.calledWith(rabbitMQ._publisher.publishTask,116 'instance.start',117 validJobData)118 done()119 })120 })121 describe('validation errors', function () {122 it('should throw the validation error', function (done) {123 var requiredKeys = Object.keys(validJobData)124 var count = createCount(requiredKeys.length, done)125 requiredKeys.forEach(function (key) {126 var options = clone(validJobData)127 delete options[key]128 try {129 rabbitMQ.startInstanceContainer(options)130 } catch (e) {131 expect(e).to.exist()132 expect(e.message).match(new RegExp(key))133 }134 count.next()135 })136 })137 })138 })139 describe('createInstanceContainer', function () {140 var opts141 beforeEach(function (done) {142 opts = {143 contextVersionId: '123456789012345678901234',144 instanceId: '123456789012345678901234',145 ownerUsername: 'runnable',146 sessionUserGithubId: '10'147 }148 done()149 })150 describe('success', function () {151 it('should create a job', function (done) {152 rabbitMQ.createInstanceContainer(opts)153 sinon.assert.calledOnce(rabbitMQ._publisher.publishTask)154 sinon.assert.calledWith(rabbitMQ._publisher.publishTask,155 'application.container.create',156 opts)157 done()158 })159 })160 describe('validation errors', function () {161 it('should throw the validation error', function (done) {162 var requiredKeys = Object.keys(opts)163 var count = createCount(requiredKeys.length, done)164 requiredKeys.forEach(function (key) {165 var options = clone(opts)166 delete options[key]167 try {168 rabbitMQ.createInstanceContainer(options)169 } catch (e) {170 expect(e).to.exist()171 expect(e.message).match(new RegExp(key))172 }173 count.next()174 })175 })176 })177 })178 describe('redeployInstanceContainer', function () {179 var validJobData180 beforeEach(function (done) {181 validJobData = {182 instanceId: '507f191e810c19729de860ea',183 sessionUserGithubId: 429706184 }185 done()186 })187 describe('success', function () {188 it('should create a job', function (done) {189 rabbitMQ.redeployInstanceContainer(validJobData)190 sinon.assert.calledOnce(rabbitMQ._publisher.publishTask)191 sinon.assert.calledWith(rabbitMQ._publisher.publishTask,192 'application.container.redeploy',193 validJobData)194 done()195 })196 })197 describe('validation errors', function () {198 it('should throw the validation error', function (done) {199 var requiredKeys = Object.keys(validJobData)200 var count = createCount(requiredKeys.length, done)201 requiredKeys.forEach(function (key) {202 var options = clone(validJobData)203 delete options[key]204 try {205 rabbitMQ.redeployInstanceContainer(options)206 } catch (e) {207 expect(e).to.exist()208 expect(e.message).match(new RegExp(key))209 }210 count.next()211 })212 })213 })214 })215 describe('deleteInstance', function () {216 var validJobData217 beforeEach(function (done) {218 validJobData = {219 instanceId: '507f191e810c19729de860ea'220 }221 done()222 })223 describe('success', function () {224 it('should create a job', function (done) {225 rabbitMQ.deleteInstance(validJobData)226 sinon.assert.calledOnce(rabbitMQ._publisher.publishTask)227 sinon.assert.calledWith(rabbitMQ._publisher.publishTask,228 'instance.delete',229 validJobData)230 done()231 })232 })233 describe('validation errors', function () {234 it('should throw the validation error', function (done) {235 var requiredKeys = Object.keys(validJobData)236 var count = createCount(requiredKeys.length, done)237 requiredKeys.forEach(function (key) {238 var options = clone(validJobData)239 delete options[key]240 try {241 rabbitMQ.deleteInstance(options)242 } catch (e) {243 expect(e).to.exist()244 expect(e.message).match(new RegExp(key))245 }246 count.next()247 })248 })249 })250 })251 describe('deleteContainer', function () {252 var validJobData253 beforeEach(function (done) {254 validJobData = {255 containerId: '6249c3a24d48fbeee444de321ee005a02c388cbaec6b900ac6693bbc7753ccd8'256 }257 done()258 })259 describe('success', function () {260 it('should create a job', function (done) {261 rabbitMQ.deleteContainer(validJobData)262 sinon.assert.calledOnce(rabbitMQ._publisher.publishTask)263 sinon.assert.calledWith(rabbitMQ._publisher.publishTask,264 'container.delete',265 validJobData)266 done()267 })268 })269 })270 describe('publishInstanceRebuild', function () {271 var validJobData272 beforeEach(function (done) {273 validJobData = {274 instanceId: '507f1f77bcf86cd799439011'275 }276 done()277 })278 describe('success', function () {279 it('should create a job', function (done) {280 rabbitMQ.publishInstanceRebuild(validJobData)281 sinon.assert.calledOnce(rabbitMQ._publisher.publishTask)282 sinon.assert.calledWith(rabbitMQ._publisher.publishTask,283 'instance.rebuild',284 validJobData)285 done()286 })287 })288 describe('validation errors', function () {289 it('should throw the validation error', function (done) {290 var requiredKeys = Object.keys(validJobData)291 var count = createCount(requiredKeys.length, done)292 requiredKeys.forEach(function (key) {293 var options = clone(validJobData)294 delete options[key]295 try {296 rabbitMQ.publishInstanceRebuild(options)297 } catch (e) {298 expect(e).to.exist()299 expect(e.message).match(new RegExp(key))300 }301 count.next()302 })303 })304 })305 })306 describe('instanceUpdated', function () {307 var validJobData308 beforeEach(function (done) {309 validJobData = {310 instance: '507f1f77bcf86cd799439011'311 }312 done()313 })314 describe('success', function () {315 it('should create a job', function (done) {316 rabbitMQ.instanceUpdated(validJobData)317 sinon.assert.calledOnce(rabbitMQ._publisher.publishEvent)318 sinon.assert.calledWith(rabbitMQ._publisher.publishEvent,319 'instance.updated',320 validJobData)321 done()322 })323 })324 describe('validation errors', function () {325 it('should throw the validation error', function (done) {326 var requiredKeys = Object.keys(validJobData)327 var count = createCount(requiredKeys.length, done)328 requiredKeys.forEach(function (key) {329 var options = clone(validJobData)330 delete options[key]331 try {332 rabbitMQ.instanceUpdated(options)333 } catch (e) {334 expect(e).to.exist()335 expect(e.message).match(new RegExp(key))336 }337 count.next()338 })339 })340 })341 })342 describe('instanceCreated', function () {343 var validJobData344 beforeEach(function (done) {345 validJobData = {346 instance: {id: 1234}347 }348 done()349 })350 describe('success', function () {351 it('should create a job', function (done) {352 rabbitMQ.instanceCreated(validJobData)353 sinon.assert.calledOnce(rabbitMQ._publisher.publishEvent)354 sinon.assert.calledWith(rabbitMQ._publisher.publishEvent,355 'instance.created',356 validJobData)357 done()358 })359 })360 describe('validation errors', function () {361 it('should throw the validation error', function (done) {362 var requiredKeys = Object.keys(validJobData)363 var count = createCount(requiredKeys.length, done)364 requiredKeys.forEach(function (key) {365 var options = clone(validJobData)366 delete options[key]367 try {368 rabbitMQ.instanceCreated(options)369 } catch (e) {370 expect(e).to.exist()371 expect(e.message).match(new RegExp(key))372 }373 count.next()374 })375 })376 })377 })378 describe('instanceDeleted', function () {379 var validJobData380 beforeEach(function (done) {381 validJobData = {382 instance: {id: 1234}383 }384 done()385 })386 describe('success', function () {387 it('should create a job', function (done) {388 rabbitMQ.instanceDeleted(validJobData)389 sinon.assert.calledOnce(rabbitMQ._publisher.publishEvent)390 sinon.assert.calledWith(rabbitMQ._publisher.publishEvent,391 'instance.deleted',392 validJobData)393 done()394 })395 })396 describe('validation errors', function () {397 it('should throw the validation error', function (done) {398 var requiredKeys = Object.keys(validJobData)399 var count = createCount(requiredKeys.length, done)400 requiredKeys.forEach(function (key) {401 var options = clone(validJobData)402 delete options[key]403 try {404 rabbitMQ.instanceDeleted(options)405 } catch (e) {406 expect(e).to.exist()407 expect(e.message).match(new RegExp(key))408 }409 count.next()410 })411 })412 })413 })414 describe('instanceDeployed', function () {415 var validJobData416 beforeEach(function (done) {417 validJobData = {418 instanceId: 1234,419 cvId: 56789420 }421 done()422 })423 describe('success', function () {424 it('should create a job', function (done) {425 rabbitMQ.instanceDeployed(validJobData)426 sinon.assert.calledOnce(rabbitMQ._publisher.publishEvent)427 sinon.assert.calledWith(rabbitMQ._publisher.publishEvent,428 'instance.deployed',429 validJobData)430 done()431 })432 })433 describe('validation errors', function () {434 it('should throw the validation error', function (done) {435 var requiredKeys = Object.keys(validJobData)436 var count = createCount(requiredKeys.length, done)437 requiredKeys.forEach(function (key) {438 var options = clone(validJobData)439 delete options[key]440 try {441 rabbitMQ.instanceDeployed(options)442 } catch (e) {443 expect(e).to.exist()444 expect(e.message).match(new RegExp(key))445 }446 count.next()447 })448 })449 })450 })451 describe('firstDockCreated', function () {452 var validJobData453 beforeEach(function (done) {454 validJobData = {455 githubId: 123456 }457 done()458 })459 describe('success', function () {460 it('should create a job', function (done) {461 rabbitMQ.firstDockCreated(validJobData)462 sinon.assert.calledOnce(rabbitMQ._publisher.publishEvent)463 sinon.assert.calledWith(rabbitMQ._publisher.publishEvent,464 'first.dock.created',465 validJobData)466 done()467 })468 })469 describe('validation errors', function () {470 it('should throw the validation error', function (done) {471 var requiredKeys = Object.keys(validJobData)472 var count = createCount(requiredKeys.length, done)473 requiredKeys.forEach(function (key) {474 var options = clone(validJobData)475 delete options[key]476 try {477 rabbitMQ.firstDockCreated(options)478 } catch (e) {479 expect(e).to.exist()480 expect(e.message).match(new RegExp(key))481 }482 count.next()483 })484 })485 })486 })487 describe('deleteContextVersion', function () {488 var validJobData489 beforeEach(function (done) {490 validJobData = {491 contextVersionId: 1234492 }493 done()494 })495 describe('success', function () {496 it('should create a job', function (done) {497 rabbitMQ.deleteContextVersion(validJobData)498 sinon.assert.calledOnce(rabbitMQ._publisher.publishTask)499 sinon.assert.calledWith(rabbitMQ._publisher.publishTask,500 'context-version.delete',501 validJobData)502 done()503 })504 })505 describe('validation errors', function () {506 it('should throw the validation error', function (done) {507 var requiredKeys = Object.keys(validJobData)508 var count = createCount(requiredKeys.length, done)509 requiredKeys.forEach(function (key) {510 var options = clone(validJobData)511 delete options[key]512 try {513 rabbitMQ.deleteContextVersion(options)514 } catch (e) {515 expect(e).to.exist()516 expect(e.message).match(new RegExp(key))517 }518 count.next()519 })520 })521 })522 })523 describe('contextVersionDeleted', function () {524 var validJobData525 beforeEach(function (done) {526 validJobData = {527 contextVersion: { _id: 1 }528 }529 done()530 })531 describe('success', function () {532 it('should create a job', function (done) {533 rabbitMQ.contextVersionDeleted(validJobData)534 sinon.assert.calledOnce(rabbitMQ._publisher.publishEvent)535 sinon.assert.calledWith(rabbitMQ._publisher.publishEvent,536 'context-version.deleted',537 validJobData)538 done()539 })540 })541 describe('validation errors', function () {542 it('should throw the validation error', function (done) {543 var requiredKeys = Object.keys(validJobData)544 var count = createCount(requiredKeys.length, done)545 requiredKeys.forEach(function (key) {546 var options = clone(validJobData)547 delete options[key]548 try {549 rabbitMQ.contextVersionDeleted(options)550 } catch (e) {551 expect(e).to.exist()552 expect(e.message).match(new RegExp(key))553 }554 count.next()555 })556 })557 })558 })559 describe('publishContainerImageBuilderStarted', function () {560 var validJobData561 beforeEach(function (done) {562 validJobData = {563 inspectData: { id: 1234 }564 }565 done()566 })567 describe('success', function () {568 it('should create a job', function (done) {569 rabbitMQ.publishContainerImageBuilderStarted(validJobData)570 sinon.assert.calledOnce(rabbitMQ._publisher.publishEvent)571 sinon.assert.calledWith(rabbitMQ._publisher.publishEvent,572 'build.container.started',573 validJobData)574 done()575 })576 })577 describe('validation errors', function () {578 it('should throw the validation error', function (done) {579 var requiredKeys = Object.keys(validJobData)580 var count = createCount(requiredKeys.length, done)581 requiredKeys.forEach(function (key) {582 var options = clone(validJobData)583 delete options[key]584 try {585 rabbitMQ.publishContainerImageBuilderStarted(options)586 } catch (e) {587 expect(e).to.exist()588 expect(e.message).match(new RegExp(key))589 }590 count.next()591 })592 })593 })594 }) // end publishContainerImageBuilderStarted595 describe('publishDockRemoved', function () {596 var validJobData597 beforeEach(function (done) {598 validJobData = {599 githubId: 1234,600 host: 'http://10.0.0.1:4242'601 }602 done()603 })604 describe('success', function () {605 it('should create a job', function (done) {606 rabbitMQ.publishDockRemoved(validJobData)607 sinon.assert.calledOnce(rabbitMQ._publisher.publishEvent)608 sinon.assert.calledWith(rabbitMQ._publisher.publishEvent,609 'dock.removed',610 validJobData)611 done()612 })613 })614 describe('validation errors', function () {615 it('should throw the validation error', function (done) {616 var requiredKeys = Object.keys(validJobData)617 var count = createCount(requiredKeys.length, done)618 requiredKeys.forEach(function (key) {619 var options = clone(validJobData)620 delete options[key]621 try {622 rabbitMQ.publishDockRemoved(options)623 } catch (e) {624 expect(e).to.exist()625 expect(e.message).match(new RegExp(key))626 }627 count.next()628 })629 })630 })631 }) // end publishDockRemoved632 describe('clearContainerMemory', function () {633 var validJobData634 beforeEach(function (done) {635 validJobData = {636 containerId: 'abcd'637 }638 done()639 })640 describe('success', function () {641 it('should create a job', function (done) {642 rabbitMQ.clearContainerMemory(validJobData)643 sinon.assert.calledOnce(rabbitMQ._publisher.publishTask)644 sinon.assert.calledWith(rabbitMQ._publisher.publishTask,645 'container.resource.clear',646 validJobData)647 done()648 })649 })650 describe('validation errors', function () {651 it('should throw the validation error', function (done) {652 var requiredKeys = Object.keys(validJobData)653 var count = createCount(requiredKeys.length, done)654 requiredKeys.forEach(function (key) {655 var options = clone(validJobData)656 delete options[key]657 try {658 rabbitMQ.clearContainerMemory(options)659 } catch (e) {660 expect(e).to.exist()661 expect(e.message).match(new RegExp(key))662 }663 count.next()664 })665 })666 })667 }) // end clearContainerMemory668 describe('killInstanceContainer', function () {669 var validJobData670 beforeEach(function (done) {671 validJobData = {672 containerId: 'abcd',673 instanceId: 'efgh'674 }675 done()676 })677 describe('success', function () {678 it('should create a job', function (done) {679 rabbitMQ.killInstanceContainer(validJobData)680 sinon.assert.calledOnce(rabbitMQ._publisher.publishTask)681 sinon.assert.calledWith(rabbitMQ._publisher.publishTask,682 'instance.kill',683 validJobData)684 done()685 })686 })687 describe('validation errors', function () {688 it('should throw the validation error', function (done) {689 var requiredKeys = Object.keys(validJobData)690 var count = createCount(requiredKeys.length, done)691 requiredKeys.forEach(function (key) {692 var options = clone(validJobData)693 delete options[key]694 try {695 rabbitMQ.killInstanceContainer(options)696 } catch (e) {697 expect(e).to.exist()698 expect(e.message).match(new RegExp(key))699 }700 count.next()701 })702 })703 })704 }) // end killInstanceContainer705 describe('killIsolation', function () {706 var validJobData707 beforeEach(function (done) {708 validJobData = {709 isolationId: 'efgh',710 triggerRedeploy: true711 }712 done()713 })714 describe('success', function () {715 it('should create a job', function (done) {716 rabbitMQ.killIsolation(validJobData)717 sinon.assert.calledOnce(rabbitMQ._publisher.publishTask)718 sinon.assert.calledWith(rabbitMQ._publisher.publishTask,719 'isolation.kill',720 validJobData)721 done()722 })723 })724 describe('validation errors', function () {725 it('should throw the validation error', function (done) {726 var requiredKeys = Object.keys(validJobData)727 var count = createCount(requiredKeys.length, done)728 requiredKeys.forEach(function (key) {729 var options = clone(validJobData)730 delete options[key]731 try {732 rabbitMQ.killIsolation(options)733 } catch (e) {734 expect(e).to.exist()735 expect(e.message).match(new RegExp(key))736 }737 count.next()738 })739 })740 })741 }) // end killIsolation742 describe('redeployIsolation', function () {743 var validJobData744 beforeEach(function (done) {745 validJobData = {746 isolationId: 'efgh'747 }748 done()749 })750 describe('success', function () {751 it('should create a job', function (done) {752 rabbitMQ.redeployIsolation(validJobData)753 sinon.assert.calledOnce(rabbitMQ._publisher.publishTask)754 sinon.assert.calledWith(rabbitMQ._publisher.publishTask,755 'isolation.redeploy',756 validJobData)757 done()758 })759 })760 describe('validation errors', function () {761 it('should throw the validation error', function (done) {762 var requiredKeys = Object.keys(validJobData)763 var count = createCount(requiredKeys.length, done)764 requiredKeys.forEach(function (key) {765 var options = clone(validJobData)766 delete options[key]767 try {768 rabbitMQ.redeployIsolation(options)769 } catch (e) {770 expect(e).to.exist()771 expect(e.message).match(new RegExp(key))772 }773 count.next()774 })775 })776 })777 }) // end redeployIsolation778 describe('instanceContainerErrored', function () {779 var validJobData780 beforeEach(function (done) {781 validJobData = {782 containerId: 'efgh',783 instanceId: '12341234',784 error: new Error('black')785 }786 done()787 })788 describe('success', function () {789 it('should create a job', function (done) {790 rabbitMQ.instanceContainerErrored(validJobData)791 sinon.assert.calledOnce(rabbitMQ._publisher.publishEvent)792 sinon.assert.calledWith(rabbitMQ._publisher.publishEvent,793 'application.container.errored',794 validJobData)795 done()796 })797 })798 describe('validation errors', function () {799 it('should throw the validation error', function (done) {800 var requiredKeys = Object.keys(validJobData)801 var count = createCount(requiredKeys.length, done)802 requiredKeys.forEach(function (key) {803 var options = clone(validJobData)804 delete options[key]805 try {806 rabbitMQ.instanceContainerErrored(options)807 } catch (e) {808 expect(e).to.exist()809 expect(e.message).match(new RegExp(key))810 }811 count.next()812 })813 })814 })815 }) // end instanceContainerErrored...

Full Screen

Full Screen

helper.js

Source:helper.js Github

copy

Full Screen

1var validator = require("validator");2var in_array = require("in_array");3var nodeMailer = require("nodemailer");4const accountSid = "ACfb02facb814d07ce93bb9cc6a3cf646b";5const authToken = "591847b1a33727ad8df642b0c85ed690";6const client = require("twilio")(accountSid, authToken);7var os = require("os");8var path = require("path");9require("dotenv").config();10var uniqid = require("uniqid");11var self = (module.exports = {12 getFileName: function (fileObject) {13 $extension = path.extname(fileObject.name);14 $fileName = uniqid() + "" + $extension;15 return $fileName;16 },17 getUrl: function () {18 return process.env.NODE_URL;19 },20 getUploadsUrl: function () {21 return process.env.NODE_UPLOADS_URL;22 },23 getFrontEndUrl: function () {24 return process.env.REACT_URL;25 },26 getAppPath: function () {27 return path.dirname(require.main.filename);28 },29 registerValidator: function (data) {30 let $errors = {};31 let keys = Object.keys(data);32 let requiredKeys = ["password", "username", "email", "mobile_number"];33 for ($j = 0; $j < requiredKeys.length; $j++) {34 $requiredKey = requiredKeys[$j];35 if (!in_array($requiredKey, keys)) {36 $errors[$requiredKey] = $requiredKey + " is required";37 }38 }39 if (keys.length > 0) {40 for ($i = 0; $i < keys.length; $i++) {41 $key = keys[$i];42 $value = data[$key];43 if ($key == "password" || $key == "username") {44 if (validator.isEmpty($value)) {45 $errors[$key] = $key + " is required";46 }47 }48 }49 return Object.keys($errors).length > 0 ? $errors : false;50 }51 },52 loginValidator: function (data) {53 let $errors = {};54 let keys = Object.keys(data);55 let requiredKeys = ["mobile_number", "email", "password"];56 for ($j = 0; $j < requiredKeys.length; $j++) {57 $requiredKey = requiredKeys[$j];58 if (!in_array($requiredKey, keys)) {59 $errors[$requiredKey] = $requiredKey + " is required";60 }61 }62 if (keys.length > 0) {63 for ($i = 0; $i < keys.length; $i++) {64 $key = keys[$i];65 $value = data[$key];66 switch ($key) {67 case "password":68 if (validator.isEmpty($value)) {69 $errors[$key] = $key + " is required";70 }71 break;72 default:73 break;74 }75 }76 return Object.keys($errors).length > 0 ? $errors : false;77 }78 },79 forgotValidator(data) {80 let $errors = {};81 let keys = Object.keys(data);82 let requiredKeys = ["email", "mobile_number"];83 for ($j = 0; $j < requiredKeys.length; $j++) {84 $requiredKey = requiredKeys[$j];85 if (!in_array($requiredKey, keys)) {86 $errors[$requiredKey] = $requiredKey + " is required";87 }88 }89 return Object.keys($errors).length > 0 ? $errors : false;90 },91 resetValidator(data) {92 let $errors = {};93 let keys = Object.keys(data);94 let requiredKeys = ["user_id", "password", "password_confirmation", "otp"];95 for ($j = 0; $j < requiredKeys.length; $j++) {96 $requiredKey = requiredKeys[$j];97 if (!in_array($requiredKey, keys)) {98 $errors[$requiredKey] = $requiredKey + " is required";99 }100 }101 if (keys.length > 0) {102 for ($i = 0; $i < keys.length; $i++) {103 $key = keys[$i];104 $value = data[$key];105 if (validator.isEmpty($value)) {106 $errors[$key] = $key + " is required";107 }108 }109 return Object.keys($errors).length > 0 ? $errors : false;110 }111 },112 generateOTP() {113 var digits = "0123456789";114 let OTP = "";115 for (let i = 0; i < 4; i++) {116 OTP += digits[Math.floor(Math.random() * 10)];117 }118 return OTP;119 },120 otpValidator(data) {121 let $errors = {};122 let keys = Object.keys(data);123 let requiredKeys = ["mobile_number"];124 for ($j = 0; $j < requiredKeys.length; $j++) {125 $requiredKey = requiredKeys[$j];126 if (!in_array($requiredKey, keys)) {127 $errors[$requiredKey] = $requiredKey + " is required";128 }129 }130 if (keys.length > 0) {131 for ($i = 0; $i < keys.length; $i++) {132 $key = keys[$i];133 $value = data[$key];134 if ($key == "mobile_number") {135 if (!validator.isMobilePhone($value, "en-US")) {136 $errors[$key] = $key + " is not valid";137 }138 }139 }140 return Object.keys($errors).length > 0 ? $errors : false;141 }142 },143 otpV2Validator(data) {144 let $errors = {};145 let keys = Object.keys(data);146 let requiredKeys = ["user_id", "otp"];147 for ($j = 0; $j < requiredKeys.length; $j++) {148 $requiredKey = requiredKeys[$j];149 if (!in_array($requiredKey, keys)) {150 $errors[$requiredKey] = $requiredKey + " is required";151 }152 }153 if (keys.length > 0) {154 for ($i = 0; $i < keys.length; $i++) {155 $key = keys[$i];156 $value = data[$key];157 if ($key == "user_id") {158 if (validator.isEmpty($value)) {159 $errors[$key] = $key + " is not valid";160 }161 }162 if ($key == "otp") {163 if (validator.isEmpty($value)) {164 $errors[$key] = $key + " is required";165 }166 }167 }168 return Object.keys($errors).length > 0 ? $errors : false;169 }170 },171 isValid(obj) {172 if (obj === null) return false;173 if (obj === undefined) return false;174 for (var key in obj) {175 if (hasOwnProperty.call(obj, key)) return true;176 }177 return false;178 },179 sendEmail(mailOptions) {180 let transporter = nodeMailer.createTransport({181 host: "smtp.gmail.com",182 port: 587,183 secure: false,184 requireTLS: true,185 auth: {186 user: "raghveer07@gmail.com",187 pass: "reavy@143",188 },189 });190 transporter.sendMail(mailOptions, (error, info) => {191 if (error) {192 console.log(error);193 return false;194 }195 return true;196 });197 },198 sendVerificationEmail($user, $otp = 0) {199 $verficationUrl =200 self.getFrontEndUrl() + "/verify/" + $user.verification_code + "/email";201 $html =202 '<table style="width:620px;margin:0 auto;background: #f5f5f5;padding: 20px;font-family: Lato,sans-serif;"><tbody>';203 $html +=204 '<tr><td><h1 style="color: #1f272a !important;margin-bottom: 0px;letter-spacing: 1px;font-family: Google Sans,Roboto,RobotoDraft,Helvetica,Arial,sans-serif;">Hello !</h1></td>';205 $html += "</tr>";206 $html += '<tr style="margin: 5px 0;display: inline-block;">';207 $html +=208 '<td style="font-size:17px;color: #1f272a !important;margin-bottom: 0px;letter-spacing: 1px;font-family: Google Sans,Roboto,RobotoDraft,Helvetica,Arial,sans-serif;"><h1 style = "text-align:center">' +209 $otp +210 "</h1> is your verification code.Do not share with anyone</td>";211 $html += "</tr>";212 $html += '<tr style="margin: 5px 0;display: inline-block;">';213 $html +=214 '<td style="font-family: Google Sans,Roboto,RobotoDraft,Helvetica,Arial,sans-serif;color: #1f272a !important;text-align:right;font-size: 17px;color:#999;font-weight:400;">If you already verified your email, no further action is required.</td>';215 $html += "</tr>";216 $html += "<tr>";217 $html +=218 '<td style="font-family: Google Sans,Roboto,RobotoDraft,Helvetica,Arial,sans-serif;color: #1f272a !important;text-align:right;font-size: 17px;color:#999;font-weight:400;">Regards,<br>TvLakey</td>';219 $html += "</tr></tbody></table>";220 //$user.email = 'rahul1.eminence@gmail.com';221 $mailOptions = {222 from: '"TvLakay" <info@TvLakay.com>',223 to: $user.email,224 subject: "Verify Email",225 html: $html,226 };227 self.sendEmail($mailOptions);228 },229 sendForgotEmail($token, $email) {230 $html =231 '<table style="width:620px;margin:0 auto;background: #f5f5f5;padding: 20px;font-family: Lato,sans-serif;"><tbody>';232 $html +=233 '<tr><td><h1 style="color: #1f272a !important;margin-bottom: 0px;letter-spacing: 1px;font-family: Google Sans,Roboto,RobotoDraft,Helvetica,Arial,sans-serif;">Hello !</h1></td>';234 $html += "</tr>";235 $html += '<tr style="margin: 5px 0;display: inline-block;">';236 $html +=237 '<td style="font-size:17px;color: #1f272a !important;margin-bottom: 0px;letter-spacing: 1px;font-family: Google Sans,Roboto,RobotoDraft,Helvetica,Arial,sans-serif;"><h1 style = "text-align:center">' +238 $token +239 "</h1> is your verification code.Do not share with anyone</td>";240 $html += "</tr>";241 $html += '<tr style="margin: 5px 0;display: inline-block;">';242 $html +=243 '<td style="font-family: Google Sans,Roboto,RobotoDraft,Helvetica,Arial,sans-serif;color: #1f272a !important;text-align:right;font-size: 17px;color:#999;font-weight:400;">If you did not request a password reset, no further action is required.</td>';244 $html += "</tr>";245 $html += "<tr>";246 $html +=247 '<td style="font-family: Google Sans,Roboto,RobotoDraft,Helvetica,Arial,sans-serif;color: #1f272a !important;text-align:right;font-size: 17px;color:#999;font-weight:400;">Regards,<br>TvLakey</td>';248 $html += "</tr></tbody></table>";249 //$email = 'rahul1.eminence@gmail.com';250 $mailOptions = {251 from: '"TvLakay" <info@TvLakay.com>',252 to: $email,253 subject: "Reset Password",254 html: $html,255 };256 self.sendEmail($mailOptions);257 },258 sendMessage($mobileNumber, $otp) {259 client.messages.create(260 {261 body:262 "Your TvLakay one time password is " +263 $otp +264 " .Please do not share with anyone",265 from: "+12054319828",266 // to: '+16802109685'267 to: `+16${$mobileNumber}`,268 },269 function (err, message) {270 if (err) {271 return err.message;272 } else {273 return message.sid;274 }275 }276 );277 },278 isDefined($string) {279 if ($string !== "undefined" || $string !== "null") {280 return true;281 }282 return false;283 },284 profileValidator(data, $type = 1) {285 switch ($type) {286 case 1:287 var requiredKeys = ["username"];288 break;289 case 2:290 var requiredKeys = ["email"];291 break;292 case 3:293 var requiredKeys = ["email", "otp"];294 break;295 case 4:296 var requiredKeys = ["mobile_number"];297 break;298 case 5:299 var requiredKeys = ["mobile_number", "otp"];300 break;301 case 6:302 var requiredKeys = [303 "old_password",304 "password",305 "password_confirmation",306 ];307 break;308 default:309 break;310 }311 let $errors = {};312 let keys = Object.keys(data);313 for ($j = 0; $j < requiredKeys.length; $j++) {314 $requiredKey = requiredKeys[$j];315 if (!in_array($requiredKey, keys)) {316 $errors[$requiredKey] = $requiredKey + " is required";317 }318 }319 if (keys.length > 0) {320 for ($i = 0; $i < keys.length; $i++) {321 $key = keys[$i];322 $value = data[$key];323 if (validator.isEmpty($value)) {324 $errors[$key] = $key + " is required";325 }326 if ($key == "email") {327 if (!validator.isEmail($value)) {328 $errors[$key] = "Not a valid email address";329 }330 }331 if ($key == "mobile_number") {332 if (!validator.isMobilePhone($value)) {333 $errors[$key] = "Not a valid mobile number";334 }335 }336 }337 return Object.keys($errors).length > 0 ? $errors : false;338 }339 },340 trendingValidator: function (data) {341 let $errors = {};342 let keys = Object.keys(data);343 let requiredKeys = ["channel_id"];344 for ($j = 0; $j < requiredKeys.length; $j++) {345 $requiredKey = requiredKeys[$j];346 if (!in_array($requiredKey, keys)) {347 $errors[$requiredKey] = $requiredKey + " is required";348 }349 }350 if (keys.length > 0) {351 for ($i = 0; $i < keys.length; $i++) {352 $key = keys[$i];353 $value = data[$key];354 if (validator.isEmpty(data[$key])) {355 $errors[$key] = $key + " is required";356 }357 }358 return Object.keys($errors).length > 0 ? $errors : false;359 }360 },361 statValidator: function (data) {362 let $errors = {};363 let keys = Object.keys(data);364 let requiredKeys = ["channel_id", "user_id", "ad_id"];365 for ($j = 0; $j < requiredKeys.length; $j++) {366 $requiredKey = requiredKeys[$j];367 if (!in_array($requiredKey, keys)) {368 $errors[$requiredKey] = $requiredKey + " is required";369 }370 }371 if (keys.length > 0) {372 for ($i = 0; $i < keys.length; $i++) {373 $key = keys[$i];374 $value = data[$key];375 if (validator.isEmpty(data[$key])) {376 $errors[$key] = $key + " is required";377 }378 }379 return Object.keys($errors).length > 0 ? $errors : false;380 }381 },...

Full Screen

Full Screen

3.RequiredKeys.ts

Source:3.RequiredKeys.ts Github

copy

Full Screen

1// 获取对象类型中的必须属性的联合类型2type a1 = RequiredKeys<{ foo: number | undefined, bar?: string, flag: boolean }> // foo|flag3type a2 = RequiredKeys<{ foo: number, bar?: string }> // foo4type a3 = RequiredKeys<{ foo: number, flag: boolean }> // foo|flag5type a4 = RequiredKeys<{ foo?: number, flag?: boolean }> // never6type a5 = RequiredKeys<{}> // never...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { requiredKeys } = require('fast-check-monorepo');3fc.assert(4 fc.property(fc.integer(), fc.integer(), (a, b) => {5 return requiredKeys({ a, b }, ['a', 'b']);6 })7);8const fc = require('fast-check');9const { requiredKeys } = require('fast-check-monorepo');10fc.assert(11 fc.property(fc.integer(), fc.integer(), (a, b) => {12 return requiredKeys({ a, b }, ['a', 'b']);13 })14);15const fc = require('fast-check');16const { requiredKeys } = require('fast-check-monorepo');17fc.assert(18 fc.property(fc.integer(), fc.integer(), (a, b) => {19 return requiredKeys({ a, b }, ['a', 'b']);20 })21);22const fc = require('fast-check');23const { requiredKeys } = require('fast-check-monorepo');24fc.assert(25 fc.property(fc.integer(), fc.integer(), (a, b) => {26 return requiredKeys({ a, b }, ['a', 'b']);27 })28);29const fc = require('fast-check');30const { requiredKeys } = require('fast-check-monorepo');31fc.assert(32 fc.property(fc.integer(), fc.integer(), (a, b) => {33 return requiredKeys({ a, b }, ['a', 'b']);34 })35);36const fc = require('fast-check');37const { requiredKeys } = require('fast-check-monorepo');38fc.assert(39 fc.property(fc.integer(), fc.integer(), (a, b) => {40 return requiredKeys({ a, b }, ['a', 'b']);41 })42);43const fc = require('fast-check');44const { requiredKeys } = require('fast-check

Full Screen

Using AI Code Generation

copy

Full Screen

1const { requiredKeys } = require('fast-check-monorepo');2const fc = require('fast-check');3const a = fc.record({4 a: fc.integer(),5 b: fc.integer(),6 c: fc.integer(),7 d: fc.integer(),8 e: fc.integer(),9 f: fc.integer(),10 g: fc.integer(),11 h: fc.integer(),12 i: fc.integer(),13 j: fc.integer(),14 k: fc.integer(),15 l: fc.integer(),16 m: fc.integer(),17 n: fc.integer(),18 o: fc.integer(),19 p: fc.integer(),20 q: fc.integer(),21 r: fc.integer(),22 s: fc.integer(),23 t: fc.integer(),24 u: fc.integer(),25 v: fc.integer(),26 w: fc.integer(),27 x: fc.integer(),28 y: fc.integer(),29 z: fc.integer(),30 aa: fc.integer(),31 ab: fc.integer(),32 ac: fc.integer(),33 ad: fc.integer(),34 ae: fc.integer(),35 af: fc.integer(),36 ag: fc.integer(),37 ah: fc.integer(),38 ai: fc.integer(),39 aj: fc.integer(),40 ak: fc.integer(),41 al: fc.integer(),42 am: fc.integer(),43 an: fc.integer(),44 ao: fc.integer(),45 ap: fc.integer(),46 aq: fc.integer(),47 ar: fc.integer(),48 as: fc.integer(),49 at: fc.integer(),50 au: fc.integer(),51 av: fc.integer(),52 aw: fc.integer(),53 ax: fc.integer(),54 ay: fc.integer(),55 az: fc.integer(),56 ba: fc.integer(),57 bb: fc.integer(),58 bc: fc.integer(),59 bd: fc.integer(),60 be: fc.integer(),61 bf: fc.integer(),62 bg: fc.integer(),63 bh: fc.integer(),64 bi: fc.integer(),65 bj: fc.integer(),66 bk: fc.integer(),67 bl: fc.integer(),68 bm: fc.integer(),69 bn: fc.integer(),70 bo: fc.integer(),71 bp: fc.integer(),72 bq: fc.integer(),73 br: fc.integer(),74 bs: fc.integer(),75 bt: fc.integer(),76 bu: fc.integer(),77 bv: fc.integer(),78 bw: fc.integer(),79 bx: fc.integer(),80 by: fc.integer(),81 bz: fc.integer(),

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { requiredKeys } = fc;3describe('requiredKeys', () => {4 it('should fail when a key is missing', () => {5 fc.assert(6 fc.property(fc.object(), obj => {7 requiredKeys(obj, 'foo');8 })9 );10 });11});12const fc = require('fast-check');13const { requiredKeys } = fc;14describe('requiredKeys', () => {15 it('should fail when a key is missing', () => {16 fc.assert(17 fc.property(fc.object(), obj => {18 requiredKeys(obj, 'foo');19 })20 );21 });22});23const fc = require('fast-check');24const { requiredKeys } = fc;25describe('requiredKeys', () => {26 it('should fail when a key is missing', () => {27 fc.assert(28 fc.property(fc.object(), obj => {29 requiredKeys(obj, 'foo');30 })31 );32 });33});34const fc = require('fast-check');35const { requiredKeys } = fc;36describe('requiredKeys', () => {37 it('should fail when a key is missing', () => {38 fc.assert(39 fc.property(fc.object(), obj => {40 requiredKeys(obj, 'foo');41 })42 );43 });44});45const fc = require('fast-check');46const { requiredKeys } = fc;47describe('requiredKeys', () => {48 it('should fail when a key is missing', () => {49 fc.assert(50 fc.property(fc.object(), obj => {51 requiredKeys(obj, 'foo');52 })53 );54 });55});56const fc = require('fast-check');57const { requiredKeys } = fc;58describe('requiredKeys', () => {59 it('should fail when a key is missing', () => {60 fc.assert(61 fc.property(fc.object(), obj => {62 requiredKeys(obj, 'foo');63 })64 );

Full Screen

Using AI Code Generation

copy

Full Screen

1const { requiredKeys } = require('fast-check');2const { keys } = require('lodash');3const obj = requiredKeys({4});5const { requiredKeys } = require('fast-check');6const { keys } = require('lodash');7const obj = requiredKeys({8});9const { requiredKeys } = require('fast-check-monorepo');10- [requiredKeys](#requiredkeys)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { requiredKeys } = require('fast-check');2const { isPlainObject } = require('lodash');3const isObject = (obj) => {4 if (!isPlainObject(obj)) {5 return false;6 }7 return true;8};9const isArrayOfObjects = (arr) => {10 if (!Array.isArray(arr)) {11 return false;12 }13 for (let i = 0; i < arr.length; i++) {14 if (!isObject(arr[i])) {15 return false;16 }17 }18 return true;19};20const isArrayOfStrings = (arr) => {21 if (!Array.isArray(arr)) {22 return false;23 }24 for (let i = 0; i < arr.length; i++) {25 if (typeof arr[i] !== 'string') {26 return false;27 }28 }29 return true;30};31const isArrayOfNumbers = (arr) => {32 if (!Array.isArray(arr)) {33 return false;34 }35 for (let i = 0; i < arr.length; i++) {36 if (typeof arr[i] !== 'number') {37 return false;38 }39 }40 return true;41};42const isArrayOfBooleans = (arr) => {43 if (!Array.isArray(arr)) {44 return false;45 }46 for (let i = 0; i < arr.length; i++) {47 if (typeof arr[i] !== 'boolean') {48 return false;49 }50 }51 return true;52};53const isArrayOfArrays = (arr) => {54 if (!Array.isArray(arr)) {55 return false;56 }57 for (let i = 0; i < arr.length; i++) {58 if (!Array.isArray(arr[i])) {59 return false;60 }61 }62 return true;63};64const isArrayOfArrayOfObjects = (arr) => {65 if (!Array.isArray(arr)) {66 return false;67 }68 for (let i = 0; i < arr.length; i++) {69 if (!Array.isArray(arr[i])) {70 return false;71 }72 for (let j = 0; j < arr[i].length; j++) {73 if (!isObject(arr[i][j])) {74 return false;75 }76 }77 }78 return true;79};80const isArrayOfArrayOfStrings = (arr) => {81 if (!Array.isArray(arr)) {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { requiredKeys } = require('fast-check');2const { anything } = require('fast-check/lib/arbitrary/anything');3const arb = anything();4const keys = requiredKeys(arb);5console.log(keys);6const { anything } = require('fast-check/lib/arbitrary/anything');7const { requiredKeys } = require('fast-check/lib/check/arbitrary/definition/RequiredKeys');8const arb = anything();9const keys = requiredKeys(arb);10console.log(keys);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { requiredKeys } = require('fast-check-monorepo');2const myObject = {3};4const myObject2 = {5};6const { requiredKeys } = require('fast-check-monorepo');7const myObject = {8};9const myObject2 = {10};11const { requiredKeys } = require('fast-check-monorepo');12const myObject = {13};14const myObject2 = {15};16const { requiredKeys } = require('fast-check-monorepo');17const myObject = {18};19const myObject2 = {

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { requiredKeys } = require('fast-check-monorepo');3const testFunction = ({a, b, c}) => {4 return a + b + c;5}6const property = (a, b, c) => testFunction({a, b, c}) === 6;7const requiredKeys = ['a'];8fc.assert(fc.property(fc.integer(), fc.integer(), fc.integer(), property), {requiredKeys});

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { requiredKeys } = require('fast-check/lib/check/arbitrary/RecordArbitrary');3const requiredKeysType = { a: fc.string(), b: fc.string() };4const requiredKeysKeys = requiredKeys(requiredKeysType);5const requiredKeysValidator = fc.record(requiredKeysKeys, fc.string());6 .filter(requiredKeys => requiredKeys.a === 'a' && requiredKeys.b === 'b')7 .checkForall()8 .then(o

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 fast-check-monorepo 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