Best JavaScript code snippet using wpt
emp3.api.MessageHandler.Spec.js
Source:emp3.api.MessageHandler.Spec.js
1describe('emp3.api.MessageHandler', function() {2 var sandbox,3 engine = {4 "mapEngineId": 'leafletMapEngine',5 "engineBasePath": "/emp3/leaflet/"6 },7 containerId = "containerId";8 beforeEach(function() {9 sandbox = sinon.sandbox.create();10 });11 afterEach(function() {12 emp3.api.MessageHandler.destroyInstance();13 sandbox.restore();14 });15 describe('getInstance', function() {16 it('returns the MessageHandler singleton', function() {17 var handler = emp3.api.MessageHandler.getInstance();18 handler.should.exist;19 handler.should.have.property('sendMessage');20 handler.should.have.property('spawnMap');21 handler.should.have.property('publish');22 });23 });24 describe('sendMessage', function() {25 it('will not publish a message if no map engine is running', function() {26 var cmd = {27 cmd: emp3.api.enums.channel.plotFeature,28 overlayId: '1234-5678-9ABC',29 features: [new emp3.api.Circle()],30 onSuccess: function() {31 },32 onError: function() {33 }34 };35 var message = {36 source: this,37 method: 'Overlay.addFeatures',38 args: {}39 };40 sandbox.stub(emp3.api.MessageHandler.getInstance(), 'isAMapReady').returns(false);41 var sendMessage = function() {42 emp3.api.MessageHandler.getInstance().sendMessage(cmd, message);43 };44 sendMessage.should.throw('There is no map engine available to publish messages to');45 });46 it('will publish a message if a map engine is running', function() {47 var cmd = {48 cmd: emp3.api.enums.channel.plotFeature,49 overlayId: '1234-5678-9ABC',50 features: [new emp3.api.Circle()],51 onSuccess: sandbox.spy(),52 onError: sandbox.spy()53 };54 var message = {55 source: this,56 method: 'Overlay.addFeatures',57 args: {}58 };59 // Stub the necessary pieces60 sandbox.stub(emp3.api.MessageHandler.getInstance(), 'isAMapReady').returns(true);61 var publishStub = sandbox.stub(emp3.api.MessageHandler.getInstance(), 'publish');62 expect(function() {63 emp3.api.MessageHandler.getInstance().sendMessage(cmd, message);64 })65 .to.not.throw();66 publishStub.should.have.been.calledWith(cmd, message);67 });68 });69 describe('publish', function() {70 it('uses the correct channel handler to send messages to the environment');71 });72 describe('addEventListener', function() {73 it('adds an event listener to the eventListeners hashMap', function() {74 var callback = sandbox.spy();75 var args = {76 id: '1234-5678-9ABC-DEF0',77 event: 'Map.centerOnLocation',78 callback: callback79 };80 emp3.api.MessageHandler.getInstance().addEventListener(args);81 emp3.api.MessageHandler.getInstance().getEventListeners()[args.id][args.event][0]();82 callback.should.have.been.calledOnce;83 });84 });85 describe('getEventListeners', function() {86 it('retrieves the list of callbacks for events', function() {87 var callback1 = sandbox.spy();88 var callback2 = sandbox.spy();89 var callback3 = sandbox.spy();90 var callback4 = sandbox.spy();91 var args1 = {92 id: '1234-5678-9ABC-DEF0',93 event: 'Map.centerOnLocation',94 callback: callback195 };96 var args2 = {97 id: '1234-5678-9ABC-DEF0',98 event: 'Map.zoomOut',99 callback: callback2100 };101 var args3 = {102 id: 'DEF0-1234-5678-9ABC',103 event: 'Map.centerOnLocation',104 callback: callback3105 };106 var args4 = {107 id: 'DEF0-1234-5678-9ABC',108 event: 'Map.centerOnLocation',109 callback: callback4110 };111 // Add the listeners112 emp3.api.MessageHandler.getInstance().addEventListener(args1);113 emp3.api.MessageHandler.getInstance().addEventListener(args2);114 emp3.api.MessageHandler.getInstance().addEventListener(args3);115 emp3.api.MessageHandler.getInstance().addEventListener(args4);116 // Retrieve and invoke the callbacks117 emp3.api.MessageHandler.getInstance().getEventListeners()[args1.id][args1.event][0]();118 emp3.api.MessageHandler.getInstance().getEventListeners()[args1.id][args2.event][0]();119 emp3.api.MessageHandler.getInstance().getEventListeners()[args3.id][args3.event][0]();120 emp3.api.MessageHandler.getInstance().getEventListeners()[args3.id][args3.event][0]();121 emp3.api.MessageHandler.getInstance().getEventListeners()[args3.id][args3.event][1]();122 // Check the spies for having been called123 callback1.should.have.been.calledOnce;124 callback2.should.have.been.calledOnce;125 callback3.should.have.been.calledTwice;126 callback4.should.have.been.calledOnce;127 });128 });129 describe('handleGetVisibilityTransactionComplete', function() {130 it('runs success callback for Map.getVisibility calls when no errors are present', function() {131 var onSuccess = sandbox.spy();132 var callbacks = {133 onSuccess: onSuccess,134 callInfo: "callInfo",135 source: "source",136 args: {137 parent: "parent",138 target: "target"139 },140 visible: 0141 };142 var details = {143 target: "targetObj",144 parent: "parentObj",145 visible: emp3.api.enums.VisibilityStateEnum.HIDDEN146 };147 var failures = {};148 emp3.api.MessageHandler.getInstance().handleGetVisibilityTransactionComplete(callbacks, details, failures);149 onSuccess.should.have.been.calledWithMatch({150 failures: failures,151 parent: callbacks.args.parent,152 target: callbacks.args.target,153 visible: callbacks.visible154 });155 });156 });157 describe('handleCenterOnLocationTransactionComplete', function() {158 it('calls onSuccess when Camera is set using Map.setCamera', function() {159 var successSpy = sandbox.spy();160 var errorSpy = sandbox.spy();161 var callbacks = {162 callInfo: {163 method: 'Map.setCamera',164 args: {165 camera: {166 geoId: "geoId",167 name: "name"168 }169 }170 },171 source: 'mocha',172 args: {},173 onSuccess: successSpy,174 onError: errorSpy175 };176 var details = {177 center: {178 lat: 40,179 lon: 40180 },181 range: 50000,182 tilt: 50,183 roll: 50,184 heading: 50185 };186 var failures = "boo";187 emp3.api.MessageHandler.getInstance().handleCenterOnLocationTransactionComplete(callbacks, details, failures);188 successSpy.should.have.been.calledWithMatch({189 camera: {190 geoId: callbacks.callInfo.args.camera.geoId,191 name: callbacks.callInfo.args.camera.name,192 latitude: details.center.lat,193 longitude: details.center.lon,194 altitude: details.range,195 tilt: details.tilt,196 roll: details.roll,197 heading: details.heading198 }199 });200 });201 });202 describe('handleFeatureAdd', function() {203 it('calls handleFeatureEvent', function() {204 sandbox.stub(emp3.api.MessageHandler.getInstance(), 'handleFeatureEvent');205 var sender = {};206 var message = {};207 var handleFeatureAdd = function() {208 emp3.api.MessageHandler.getInstance().handleFeatureAdd(sender, message);209 };210 handleFeatureAdd.should.not.throw(/any error/);211 });212 });213 describe('handleFeatureUpdate', function() {214 it('calls handleFeatureEvent', function() {215 sandbox.stub(emp3.api.MessageHandler.getInstance(), 'handleFeatureEvent');216 var sender = {};217 var message = {};218 var handleFeatureAdd = function() {219 emp3.api.MessageHandler.getInstance().handleFeatureUpdate(sender, message);220 };221 handleFeatureAdd.should.not.throw(/any error/);222 });223 });224 describe('handleFeatureRemove', function() {225 it('calls handleFeatureEvent', function() {226 sandbox.stub(emp3.api.MessageHandler.getInstance(), 'handleFeatureEvent');227 var sender = {};228 var message = {};229 var handleFeatureAdd = function() {230 emp3.api.MessageHandler.getInstance().handleFeatureRemove(sender, message);231 };232 handleFeatureAdd.should.not.throw(/any error/);233 });234 });235 describe('handleFeatureEvent', function() {236 var sender = {237 id: "map1"238 },239 message = {240 features: [{241 name: "point1",242 geoId: "point1",243 properties: {244 featureType: emp3.api.enums.FeatureTypeEnum.GEO_POINT245 },246 feature: {247 coordinates: [40, 40],248 type: "Point"249 }250 }]251 };252 it('can create feature add events', function() {253 var eventType = emp3.api.enums.EventType.MAP_FEATURE_ADDED,254 messageHandler = emp3.api.MessageHandler.getInstance(),255 callback = sandbox.spy(),256 addEventListenerArgs = {257 id: sender.id,258 event: emp3.api.enums.EventType.MAP_FEATURE_ADDED,259 callback: callback260 };261 // setup eventListener.262 emp3.api.MessageHandler.getInstance().addEventListener(addEventListenerArgs);263 messageHandler.handleFeatureEvent(eventType, sender, message);264 callback.should.have.been.calledWithMatch({265 type: emp3.api.enums.EventType.MAP_FEATURE_ADDED266 });267 });268 it('can create feature update events', function() {269 var eventType = emp3.api.enums.EventType.MAP_FEATURE_UPDATED,270 messageHandler = emp3.api.MessageHandler.getInstance(),271 callback = sandbox.spy(),272 addEventListenerArgs = {273 id: sender.id,274 event: emp3.api.enums.EventType.MAP_FEATURE_UPDATED,275 callback: callback276 };277 // setup eventListener.278 emp3.api.MessageHandler.getInstance().addEventListener(addEventListenerArgs);279 messageHandler.handleFeatureEvent(eventType, sender, message);280 callback.should.have.been.calledWithMatch({281 type: emp3.api.enums.EventType.MAP_FEATURE_UPDATED282 });283 });284 it('can create feature removed events', function() {285 var eventType = emp3.api.enums.EventType.MAP_FEATURE_REMOVED,286 messageHandler = emp3.api.MessageHandler.getInstance(),287 callback = sandbox.spy(),288 addEventListenerArgs = {289 id: sender.id,290 event: emp3.api.enums.EventType.MAP_FEATURE_REMOVED,291 callback: callback292 };293 // setup eventListener.294 emp3.api.MessageHandler.getInstance().addEventListener(addEventListenerArgs);295 messageHandler.handleFeatureEvent(eventType, sender, message);296 callback.should.have.been.calledWithMatch({297 type: emp3.api.enums.EventType.MAP_FEATURE_REMOVED298 });299 });300 });301 describe('get', function() {302 it('sends a payload to to the validator with a `get` command for overlays or features', function() {303 var args = {304 onSuccess: sandbox.spy(),305 onError: sandbox.spy()306 };307 var callInfo = {308 args: args,309 method: 'Map.getOverlays',310 source: {}311 };312 var message = {313 onSuccess: args.onSuccess,314 onError: args.onError,315 recursive: true,316 select: [],317 types: [],318 filter: {}319 };320 var transactionId = '1234-5678-9ABC-DEF0';321 var validateStub = sandbox.stub(emp3.api.MessageHandler.getInstance(), 'validate');322 emp3.api.MessageHandler.getInstance().get(callInfo, message, transactionId);323 validateStub.should.have.been.calledWithMatch('map.get', {324 types: sinon.match.array,325 recursive: message.recursive,326 select: message.select,327 filter: message.filter,328 messageId: transactionId329 },330 callInfo);331 });332 });333 describe('validate', function() {334 it('sends validated messages to the environment pubSub `publish` method', function() {335 var channel = 'map.get';336 var args = {337 onSuccess: sandbox.spy(),338 onError: sandbox.spy()339 };340 var message = {341 onSuccess: args.onSuccess,342 onError: args.onError,343 recursive: true,344 select: [],345 types: [],346 filter: {}347 };348 var callInfo = {349 args: {350 onSuccess: sandbox.spy(),351 onError: sandbox.spy()352 },353 method: 'Map.getOverlays',354 source: {}355 };356 var environmentPublisherStub = sandbox.stub(emp3.api.environment.browser.pubSub, 'publish');357 emp3.api.MessageHandler.getInstance().validate(channel, message, callInfo);358 environmentPublisherStub.should.have.been.calledWith({359 channel: channel,360 message: message361 });362 });363 it('should split the message into chunks of 500 if the message channel is plotFeatureBatch, unplotFeatureBatch, featureSelectedBatch, or featureDeselectedBatch', function() {364 var args = {365 onSuccess: sandbox.spy(),366 onError: sandbox.spy()367 };368 var message = {369 onSuccess: args.onSuccess,370 onError: args.onError,371 features: []372 };373 for (var i = 0; i < 1001; i++) {374 message.features.push('i\'m a feature');375 }376 var callInfo = {377 args: {378 onSuccess: sandbox.spy(),379 onError: sandbox.spy()380 },381 method: 'Map.getOverlays',382 source: {}383 };384 var channels = [385 emp3.api.enums.channel.plotFeatureBatch,386 emp3.api.enums.channel.unplotFeatureBatch,387 emp3.api.enums.channel.featureSelectedBatch,388 emp3.api.enums.channel.featureDeselectedBatch389 ];390 var environmentPublisherStub = sandbox.stub(emp3.api.environment.browser.pubSub, 'publish');391 for (var chanIdx in channels) {392 var channel = channels[chanIdx];393 emp3.api.MessageHandler.getInstance().validate(channel, message, callInfo);394 environmentPublisherStub.should.have.been.calledWith({395 channel: channel,396 message: sinon.match.object397 });398 var publishedFeatures = environmentPublisherStub.firstCall.args[0].message.features;399 publishedFeatures.should.have.length(500);400 }401 });402 });403 describe('clearFeatures', function() {404 it('passes a clearFeatures payload to the validate function', function() {405 var messageHandler = emp3.api.MessageHandler.getInstance();406 var validateStub = sandbox.stub(messageHandler, 'validate');407 var callInfo = {408 method: 'Test.clearContainer',409 source: this,410 args: {411 onSuccess: sandbox.spy(),412 onError: sandbox.spy()413 }414 };415 var message = {416 overlay: new emp3.api.Overlay()417 };418 var transactionId = '1234-5678-9ABC-DEF0';419 messageHandler.clearFeatures(callInfo, message, transactionId);420 validateStub.should.have.been.calledWith(emp3.api.enums.channel.clearFeatures, {421 overlayId: message.overlay.geoId,422 messageId: transactionId423 }, callInfo);424 });425 });426 describe('manageSelection', function() {427 it('adds features into the selectionHash', function() {428 var sender = {429 id: 'map1'430 };431 var msg = {432 details: {433 features: {434 featureId: 'feature1',435 name: 'feature1',436 feature: {437 coordinates: [40, 40],438 type: 'Point'439 },440 properties: {441 featureType: 'point'442 }443 }444 }445 };446 var messageHandler = emp3.api.MessageHandler.getInstance();447 expect(function() {448 messageHandler.manageSelection(sender, msg);449 }).to.not.throw();450 });451 });452 describe('manageDeselection', function() {453 it('calls removeSelection to remove items out of selectionHash', function() {454 var sender = {455 id: 'map1'456 };457 var msg = {458 details: {459 features: [{460 featureId: 'feature1',461 name: 'feature1',462 feature: {463 coordinates: [40, 40],464 type: 'Point'465 },466 properties: {467 featureType: 'point'468 }469 }]470 }471 };472 var messageHandler = emp3.api.MessageHandler.getInstance();473 var removeSelectionStub = sandbox.stub(messageHandler, 'removeSelection');474 // unfortunately cannot test the validate function is called. the selectionHash475 // must be populated, but it is a private variable.476 messageHandler.manageSelection(sender, msg);477 messageHandler.isSelected('map1', 'feature1').should.equal(true);478 messageHandler.manageDeselection(sender, msg);479 removeSelectionStub.should.have.been.calledWithMatch('map1', ['feature1']);480 });481 });482 describe('removeSelection', function() {483 it('removes items out of the selectionHash', function() {484 var sender = {485 id: 'map1'486 };487 var msg = {488 details: {489 features: [{490 featureId: 'feature1',491 name: 'feature1',492 feature: {493 coordinates: [40, 40],494 type: 'Point'495 },496 properties: {497 featureType: 'point'498 }499 }]500 }501 };502 var messageHandler = emp3.api.MessageHandler.getInstance();503 messageHandler.manageSelection(sender, msg);504 messageHandler.isSelected('map1', 'feature1').should.equal(true);505 messageHandler.removeSelection('map1', ['feature1']);506 messageHandler.isSelected('map1', 'feature1').should.equal(false);507 });508 });509 describe('isSelected', function() {510 it('finds a feature selected', function() {511 var sender = {512 id: 'map1'513 };514 var msg = {515 details: {516 features: [{517 featureId: 'feature1',518 name: 'feature1',519 feature: {520 coordinates: [40, 40],521 type: 'Point'522 },523 properties: {524 featureType: 'point'525 }526 }]527 }528 };529 var messageHandler = emp3.api.MessageHandler.getInstance();530 messageHandler.manageSelection(sender, msg);531 messageHandler.isSelected('map1', 'feature1').should.equal(true);532 messageHandler.manageDeselection(sender, msg);533 messageHandler.isSelected('map1', 'feature1').should.equal(false);534 });535 it('finds a feature unselected', function() {536 var messageHandler = emp3.api.MessageHandler.getInstance();537 messageHandler.isSelected('map1', 'feature1').should.equal(false);538 });539 });...
adminController.js
Source:adminController.js
1"use strict";2var languages = require("../languages.json");3var admin = require("../models/admin");4var messageHandler = require("../utilities/messageHandler");5var adminController = {6 retreiveCategories(req, res) { 7 if (req.session.userRole === 1) { 8 admin.retreiveCategories(categories => {9 res.render("addCategoryPage.ejs", {10 language: languages[req.session.language],11 lastVisitedUrl: req.originalUrl,12 isLoggedIn: req.session.isLoggedIn,13 userRole: req.session.userRole,14 categories: categories,15 errorMessage: messageHandler.retrieveErrorMessage(req),16 noticeMessage: messageHandler.retrieveNoticeMessage(req)17 });18 }); 19 }20 else{21 messageHandler.setErrorMessage(req, "adminRoleRequired");22 res.redirect("/");23 } 24 25 26 },27 retreiveSubforums(req, res) { 28 if (req.session.userRole === 1) { 29 admin.retreiveSubforums(subforums => {30 res.render("removeSubforumPage.ejs", {31 language: languages[req.session.language],32 lastVisitedUrl: req.originalUrl,33 isLoggedIn: req.session.isLoggedIn,34 userRole: req.session.userRole,35 subforums: subforums,36 errorMessage: messageHandler.retrieveErrorMessage(req),37 noticeMessage: messageHandler.retrieveNoticeMessage(req)38 });39 }); 40 }41 else{42 messageHandler.setErrorMessage(req, "adminRoleRequired");43 res.redirect("/");44 } 45 46 47 },48 retreiveCategories2(req, res) { 49 if (req.session.userRole === 1) { 50 admin.retreiveCategories(categories => {51 res.render("removeCategoryPage.ejs", {52 language: languages[req.session.language],53 lastVisitedUrl: req.originalUrl,54 isLoggedIn: req.session.isLoggedIn,55 userRole: req.session.userRole,56 categories: categories,57 errorMessage: messageHandler.retrieveErrorMessage(req),58 noticeMessage: messageHandler.retrieveNoticeMessage(req)59 });60 }); 61 }62 else{63 messageHandler.setErrorMessage(req, "adminRoleRequired");64 res.redirect("/");65 } 66 67 68 },69 retreiveSubforum(req, res) { 70 if (req.session.userRole === 1) { 71 admin.retreiveCategories(categories => {72 res.render("addSubforumPage.ejs", {73 language: languages[req.session.language],74 lastVisitedUrl: req.originalUrl,75 isLoggedIn: req.session.isLoggedIn,76 userRole: req.session.userRole,77 categories: categories,78 errorMessage: messageHandler.retrieveErrorMessage(req),79 noticeMessage: messageHandler.retrieveNoticeMessage(req)80 });81 }); 82 }83 else{84 messageHandler.setErrorMessage(req, "adminRoleRequired");85 res.redirect("/");86 } 87 88 89 },90 retreiveUsers(req, res) { 91 if (req.session.userRole === 1) { 92 admin.retreiveUsers(users => { 93 res.render("changeUserRolePage.ejs", {94 language: languages[req.session.language],95 lastVisitedUrl: req.originalUrl,96 isLoggedIn: req.session.isLoggedIn,97 userRole: req.session.userRole,98 users: users,99 errorMessage: messageHandler.retrieveErrorMessage(req),100 noticeMessage: messageHandler.retrieveNoticeMessage(req)101 }); 102 }); 103 }104 else{105 messageHandler.setErrorMessage(req, "adminRoleRequired");106 res.redirect("/");107 } 108 109 },110 addCategory(req, res) { 111 if (req.session.userRole === 1) { 112 admin.createNewCategory(req.body.categoryName, req.body.language, req.body.parentCategory, error => {113 if (!error) {114 messageHandler.setErrorMessage(req, "justError");115 }116 else {117 messageHandler.setNoticeMessage(req, "addedCategory");118 }119 res.redirect("/admin/");120 });121 }122 else{123 messageHandler.setErrorMessage(req, "adminRoleRequired");124 res.redirect("/");125 } 126 127 },128 addSubforum(req, res) { 129 if (req.session.userRole === 1) { 130 admin.createNewSubforum(req.body.subforumName, req.body.parentCategory, error => {131 if (!error) {132 messageHandler.setErrorMessage(req, "justError");133 }134 else {135 messageHandler.setNoticeMessage(req, "addedSubforum");136 }137 res.redirect("/admin/");138 });139 }140 else{141 messageHandler.setErrorMessage(req, "adminRoleRequired");142 res.redirect("/");143 } 144 145 },146 changeUserRole(req, res) { 147 if (req.session.userRole === 1) { 148 admin.changeUserRole(req.body.username, req.body.userRole, error => {149 if (!error) {150 messageHandler.setErrorMessage(req, "justError");151 }152 else {153 messageHandler.setNoticeMessage(req, "changedUserRole");154 }155 res.redirect("/admin/");156 }); 157 }158 else{159 messageHandler.setErrorMessage(req, "adminRoleRequired");160 res.redirect("/");161 }162 163 },164 retreivePanel(req, res) { 165 if (req.session.userRole === 1) { 166 res.render("adminPage.ejs", {167 language: languages[req.session.language],168 lastVisitedUrl: req.originalUrl,169 isLoggedIn: req.session.isLoggedIn,170 userRole: req.session.userRole,171 text: "",172 errorMessage: messageHandler.retrieveErrorMessage(req),173 noticeMessage: messageHandler.retrieveNoticeMessage(req)174 });175 }176 else{177 messageHandler.setErrorMessage(req, "adminRoleRequired");178 res.redirect("/");179 }180 },181 removeCategory(req, res) {182 if (req.session.userRole === 1) {183 admin.removeCategory(req.body.categoryName, (error) => {184 if (!error) {185 messageHandler.setErrorMessage(req, "justError");186 }187 else {188 messageHandler.setNoticeMessage(req, "removedCategory");189 }190 res.redirect("/admin/");191 });192 }193 else {194 messageHandler.setErrorMessage(req, "adminRoleRequired");195 res.redirect("/");196 }197 },198 removeSubforum(req, res) {199 if (req.session.userRole === 1) {200 admin.removeSubforum(req.body.categoryName, (error) => {201 if (!error) {202 messageHandler.setErrorMessage(req, "justError");203 }204 else {205 messageHandler.setNoticeMessage(req, "removedSubforum");206 }207 res.redirect("/admin/");208 });209 }210 else {211 messageHandler.setErrorMessage(req, "adminRoleRequired");212 res.redirect("/");213 }214 },215}...
moderatorController.js
Source:moderatorController.js
1"use strict";2var languages = require("../languages.json");3var moderator = require("../models/moderator");4var messageHandler = require("../utilities/messageHandler");5var moderatorController = {6 retreiveUsers(req, res) { 7 if (req.session.userRole === 1 || req.session.userRole === 2) { 8 moderator.retreiveUsers(users => { 9 res.render("banUserPage.ejs", {10 language: languages[req.session.language],11 lastVisitedUrl: req.originalUrl,12 isLoggedIn: req.session.isLoggedIn,13 userRole: req.session.userRole,14 users: users,15 errorMessage: messageHandler.retrieveErrorMessage(req),16 noticeMessage: messageHandler.retrieveNoticeMessage(req)17 }); 18 }); 19 }20 else{21 messageHandler.setErrorMessage(req, "moderatorRoleRequired");22 res.redirect("/");23 }24 },25 retreiveReportedPosts(req, res) { 26 if (req.session.userRole === 1 || req.session.userRole === 2) {27 moderator.retreiveReportedPosts(reportedPosts => { 28 res.render("reportedPostsPage.ejs", {29 language: languages[req.session.language],30 lastVisitedUrl: req.originalUrl,31 isLoggedIn: req.session.isLoggedIn,32 userRole: req.session.userRole,33 reportedPosts: reportedPosts,34 errorMessage: messageHandler.retrieveErrorMessage(req),35 noticeMessage: messageHandler.retrieveNoticeMessage(req)36 }); 37 }); 38 } 39 else{40 messageHandler.setErrorMessage(req, "moderatorRoleRequired");41 res.redirect("/");42 }43 },44 changeUserRole(req, res) { 45 if (req.session.userRole === 1 || req.session.userRole === 2) {46 moderator.changeUserRole(req.body.username, req.body.userRole, text => {47 res.render("moderatorPage.ejs", {48 language: languages[req.session.language],49 lastVisitedUrl: req.originalUrl,50 isLoggedIn: req.session.isLoggedIn,51 userRole: req.session.userRole,52 text: text,53 errorMessage: messageHandler.retrieveErrorMessage(req),54 noticeMessage: messageHandler.retrieveNoticeMessage(req)55 });56 }); 57 }58 else{59 messageHandler.setErrorMessage(req, "moderatorRoleRequired");60 res.redirect("/");61 } 62 },63 deletePostAndBanUser(req, res) { 64 if (req.session.userRole === 1 || req.session.userRole === 2) {65 moderator.deletePostAndBanUser(req.params.IdPost, req.params.IdUser, (error) => {66 if (!error) {67 messageHandler.setErrorMessage(req, "justError");68 }69 else {70 messageHandler.setNoticeMessage(req, "bannedUserAndDeletedPost");71 }72 res.redirect("/moderator/reports");73 });74 }75 else {76 messageHandler.setErrorMessage(req, "moderatorRoleRequired");77 res.redirect("/");78 }79 },80 deletePost(req, res) { 81 if (req.session.userRole === 1 || req.session.userRole === 2) {82 moderator.deletePost(req.params.IdPost, (error) => {83 if (!error) {84 messageHandler.setErrorMessage(req, "justError");85 }86 else {87 messageHandler.setNoticeMessage(req, "deletedPost");88 }89 res.redirect("/moderator/reports");90 });91 }92 else {93 messageHandler.setErrorMessage(req, "moderatorRoleRequired");94 res.redirect("/");95 }96 },97 deleteReport(req, res) { 98 if (req.session.userRole === 1 || req.session.userRole === 2) {99 moderator.deleteReport(req.params.IdPost, (error) => {100 if (!error) {101 messageHandler.setErrorMessage(req, "justError");102 }103 else {104 messageHandler.setNoticeMessage(req, "deletedReport");105 }106 res.redirect("/moderator/reports");107 });108 }109 else {110 messageHandler.setErrorMessage(req, "moderatorRoleRequired");111 res.redirect("/");112 }113 },114 retreiveReports(req, res) { 115 if (req.session.userRole === 1 || req.session.userRole === 2) {116 moderator.retreiveReports(req.params.IdPost, (reports) => {117 res.render("reportsPage.ejs", {118 language: languages[req.session.language],119 lastVisitedUrl: req.originalUrl,120 isLoggedIn: req.session.isLoggedIn,121 userRole: req.session.userRole,122 reports: reports,123 errorMessage: messageHandler.retrieveErrorMessage(req),124 noticeMessage: messageHandler.retrieveNoticeMessage(req) 125 });126 });127 }128 else {129 messageHandler.setErrorMessage(req, "moderatorRoleRequired");130 res.redirect("/");131 }132 },133 retreivePanel(req, res) { 134 if (req.session.userRole === 1 || req.session.userRole === 2) {135 res.render("moderatorPage.ejs", {136 language: languages[req.session.language],137 lastVisitedUrl: req.originalUrl,138 isLoggedIn: req.session.isLoggedIn,139 userRole: req.session.userRole,140 text: "",141 errorMessage: messageHandler.retrieveErrorMessage(req),142 noticeMessage: messageHandler.retrieveNoticeMessage(req)143 });144 }145 else{146 messageHandler.setErrorMessage(req, "moderatorRoleRequired");147 res.redirect("/");148 }149}150}...
Using AI Code Generation
1var wptools = require('wptools');2var wptools = require('wptools');3var fs = require('fs');4var options = {5};6var wp = new wptools.page('Albert Einstein', options);7wp.get(function(err, info) {8 if (err) {9 console.log(err);10 } else {11 fs.writeFileSync('einstein.json', JSON.stringify(info, null, 2));12 }13});14var wptools = require('wptools');15var fs = require('fs');16var options = {17};18var wp = new wptools.page('Albert Einstein', options);19wp.get(function(err, info) {20 if (err) {21 console.log(err);22 } else {23 fs.writeFileSync('einstein.json', JSON.stringify(info, null, 2));24 }25});26var wptools = require('wptools');27var fs = require('fs');28var options = {29};30var wp = new wptools.page('Albert Einstein', options);31wp.get(function(err, info) {32 if (err) {33 console.log(err);34 } else {35 fs.writeFileSync('einstein.json', JSON.stringify(info, null, 2));36 }37});38var wptools = require('wptools');39var fs = require('fs');40var options = {41};42var wp = new wptools.page('Albert Einstein', options);43wp.get(function(err, info) {44 if (err) {45 console.log(err);
Using AI Code Generation
1var wpt = require('wpt');2wpt.MessageHandler = function(msg) {3 console.log(msg);4};5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});
Using AI Code Generation
1var wptools = require('wptools');2var wiki = wptools.page('Albert Einstein');3wiki.get(function(err, data) {4 console.log(data);5});6var wptools = require('wptools');7var wiki = wptools.page('Albert Einstein');8wiki.get(function(err, data) {9 console.log(data);10});11var wptools = require('wptools');12var wiki = wptools.page('Albert Einstein');13wiki.get(function(err, data) {14 console.log(data);15});16var wptools = require('wptools');17var wiki = wptools.page('Albert Einstein');18wiki.get(function(err, data) {19 console.log(data);20});21var wptools = require('wptools');22var wiki = wptools.page('Albert Einstein');23wiki.get(function(err, data) {24 console.log(data);25});26var wptools = require('wptools');27var wiki = wptools.page('Albert Einstein');28wiki.get(function(err, data) {29 console.log(data);30});31var wptools = require('wptools');32var wiki = wptools.page('Albert Einstein');33wiki.get(function(err, data) {34 console.log(data);35});36var wptools = require('wptools');37var wiki = wptools.page('Albert Einstein');38wiki.get(function(err, data) {39 console.log(data);40});41var wptools = require('wptools');42var wiki = wptools.page('Albert Einstein');43wiki.get(function(err, data) {44 console.log(data);45});46var wptools = require('wptools');
Using AI Code Generation
1var wptb = require('wptb');2var wptbMessageHandler = new wptb.MessageHandler();3wptbMessageHandler.on('message', function(message) {4 console.log(message);5});6var wptb = require('wptb');7var wptbMessageHandler = new wptb.MessageHandler();8wptbMessageHandler.send('message', {foo: 'bar'});9wptbMessageHandler.send('message', {foo: 'bar'}, function(response) {10 console.log(response);11});12wptbMessageHandler.send('message', {foo: 'bar'}, function(response) {13 console.log(response);14}, 2000);15wptbMessageHandler.send('message', {foo: 'bar'}, function(response) {16 console.log(response);17}, 2000, function() {18 console.log('timeout');19});20wptbMessageHandler.send('message', {foo: 'bar'}, function(response) {21 console.log(response);22}, 2000, function() {23 console.log('timeout');24}, {foo: 'bar'});25wptbMessageHandler.send('message', {foo: 'bar'}, function(response) {26 console.log(response);27}, 2000, function() {28 console.log('timeout');29}, {foo: 'bar'}, {foo: 'bar'});30wptbMessageHandler.send('message', {foo: 'bar'}, function(response) {31 console.log(response);32}, 2000, function() {33 console.log('timeout');34}, {foo: 'bar'}, {foo: 'bar'}, {foo: 'bar'});
Using AI Code Generation
1var wptb_bot = require('./bot.js');2var messageHandler = new wptb_bot.MessageHandler();3messageHandler.on('message', function(message) {4 console.log(message);5});6messageHandler.start();7var events = require('events');8var util = require('util');9var MessageHandler = function() {10 events.EventEmitter.call(this);11 this.start = function() {12 setInterval(function() {13 this.emit('message', 'hello');14 }.bind(this), 1000);15 }16}17util.inherits(MessageHandler, events.EventEmitter);18exports.MessageHandler = MessageHandler;
Using AI Code Generation
1var wptools = require('wptools');2var messageHandler = wptools.messageHandler;3messageHandler("Hello World!",function(data){4 console.log(data);5});6var wptools = require('wptools');7var messageHandler = wptools.messageHandler;8messageHandler("Hello World!",function(data){9 console.log(data);10});11var wptools = require('wptools');12var messageHandler = wptools.messageHandler;13messageHandler("Hello World!",function(data){14 console.log(data);15});16var wptools = require('wptools');17var messageHandler = wptools.messageHandler;18messageHandler("Hello World!",function(data){19 console.log(data);20});21var wptools = require('wptools');22var messageHandler = wptools.messageHandler;23messageHandler("Hello World!",function(data){24 console.log(data);25});26var wptools = require('wptools');27var messageHandler = wptools.messageHandler;28messageHandler("Hello World!",function(data){29 console.log(data);30});31var wptools = require('wptools');32var messageHandler = wptools.messageHandler;33messageHandler("Hello World!",function(data){34 console.log(data);35});36var wptools = require('wptools');37var messageHandler = wptools.messageHandler;38messageHandler("Hello World!",function(data){39 console.log(data);40});41var wptools = require('wptools');42var messageHandler = wptools.messageHandler;43messageHandler("Hello World!",function(data){44 console.log(data);45});
Using AI Code Generation
1var wptools = require('wptools');2var wiki = new wptools('Barack Obama');3wiki.get(function(err, res) {4 console.log(res);5});6{ 7 revisions: [ { '*': 'Barack Hussein Obama II (born August 4, 1961) is the 44th and current President of the United States. He is the first African American to hold the office. He previously served as a U.S. Senator from Illinois (2005–2008) and as a member of the Illinois State Senate from 1997 until 2004. He is a member of the Democratic Party and was the first African American to be elected president of the United States. He was inaugurated on January 20, 2009. Obama was born in Honolulu, Hawaii. After graduating from Columbia University in 1983, he worked as a community organizer in Chicago. In 1988, he enrolled in Harvard Law School, where he was the first black president of the Harvard Law Review. After graduating, he became a civil rights attorney and professor, and taught constitutional law at the University of Chicago Law School from 1992 to 2004. He served three terms representing the 13th District in the Illinois Senate from 1997 until 2004, when he ran for the U.S. Senate. Obama was elected to the U.S. Senate in November 2004, winning with 70% of the vote. He was re-elected in 2010 with 66% of the vote. On February 10, 2007, Obama announced his candidacy for the Democratic nomination for president in the 2008 election. He was elected over Hillary Rodham Clinton in the 2008 Democratic Party primaries, and won the general election on November 4, 2008, defeating Republican nominee John McCain and winning the electoral vote 365–173. Obama was inaugurated as president on January 20, 2009. He is the fourth consecutive Democratic president, following Jimmy Carter, Bill Clinton, and George W. Bush. Obama was the first president born outside the contiguous United States. He is also the first president whose mother was a native of Hawaii and the first with a Muslim name. Obama\'s mother, Ann Dunham, was born in Wichita, Kansas,
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!