Best JavaScript code snippet using karma
index.js
Source:index.js
1let config = require(__base + 'config'),2masterConfig = require(__base + 'components/db-master/master-configs'),3rp = require('request-promise'),4statusUpdater = require(__base +5 'components/core/helper/status-updater')({}),6tableOperations = require(__base +7 'components/db-master/table-operations')({}),8pushUpdate = require(__base +9 'components/core/push-update')({}),10isJSON = require('is-valid-json'),11isReachable = require('is-reachable'),12logger = require(__base + 'components/logger').log(),13logFormat = require(__base + 'components/logger').format;1415module.exports = (params) => {16 return {17 proceedCSM: (data) => {18 console.log('================ proceedCSM data');19 masterConfig.getConfigValue('core', 'cloud_his_url', (err, row) => {20 console.log('================ proceedCSM' + row);21 if(row) {22 let cloudUrl = row.config_val;23 console.log('================ proceedCSM' + cloudUrl);24 isReachable(cloudUrl).then(reachable => {25 console.log('================ IS REACHABLE');26 let d = {27 state: 4,28 syncRequestsId: data.sync_requests_id,29 remoteSyncRequestId: data.relative_sync_requests_id,30 hotelId: data.hotel_id31 };32 console.log('================ PRINTING DATA PACKET TO UPDATE');33 console.log(d);34 statusUpdater.updateStatus(d, (err, response) => {35 console.log('================ REPONSE FROM UPDATE');36 if(err) {37 let d = {38 state: 2,39 syncRequestsId: data.sync_requests_id,40 remoteSyncRequestId: data.relative_sync_requests_id,41 hotelId: data.hotel_id42 };43 statusUpdater.updateStatus(d, (err, response) => {44 //return true;45 });46 }47 });48 });49 }50 });51 },52 backupData: (data, callback) => {53 let d = {54 state: 7,55 syncRequestsId: data.sync_requests_id,56 remoteSyncRequestId: data.relative_sync_requests_id,57 hotelId: data.hotel_id58 };59 statusUpdater.updateStatus(d, (err, response) => {60 if(response) {61 console.log('STATUS = 7 UPDATED @ CLOUD AND INPREMISE :: CLOUD AND INPREMISE');62 tableOperations.tablesBackup(data, (err, tablesBackupRes) => {63 if(tablesBackupRes) {64 let d = {65 state: 8,66 syncRequestsId: data.sync_requests_id,67 remoteSyncRequestId: data.relative_sync_requests_id,68 hotelId: data.hotel_id69 };70 statusUpdater.updateStatus(d, (err, response) => {71 if(response) {72 // need to write logger functions73 } else {74 // need to write logger functions75 }76 });77 } else {78 let d = {79 state: 6,80 syncRequestsId: data.sync_requests_id,81 remoteSyncRequestId: data.relative_sync_requests_id,82 hotelId: data.hotel_id83 };8485 statusUpdater.updateStatus(d, (err, response) => {86 if(response) {87 // need to write logger functions88 } else {89 // need to write logger functions90 }91 });92 }93 });94 } else {95 let d = {96 state: 6,97 syncRequestsId: data.sync_requests_id,98 remoteSyncRequestId: data.relative_sync_requests_id,99 hotelId: data.hotel_id100 };101 statusUpdater.updateStatus(d, (err, response) => {102 if(response) {103 // need to write logger functions104 } else {105 // need to write logger functions106 }107 });108 }109 });110 },111 truncateTables: (data, callback) => {112 let d = {113 state: 9,114 syncRequestsId: data.sync_requests_id,115 remoteSyncRequestId: data.relative_sync_requests_id,116 hotelId: data.hotel_id117 };118 statusUpdater.updateStatus(d, (err, response) => {119 if(response) {120 tableOperations.truncateTables(data, (err, truncateDataRes) => {121 console.log('RESPONSE FROM truncateTables :: CLOUD TO INPREMISE - HEAD START');122 console.log(truncateDataRes);123 console.log('RESPONSE FROM truncateTables :: CLOUD TO INPREMISE - HEAD END');124 if(truncateDataRes) {125 console.log('ENTED IN IF CONDITION truncateTables');126 let d = {127 state: 10,128 syncRequestsId: data.sync_requests_id,129 remoteSyncRequestId: data.relative_sync_requests_id,130 hotelId: data.hotel_id131 };132133 statusUpdater.updateStatus(d, (err, response) => {134 if(response) {135 // need to write logger functions136 } else {137 // need to write logger functions138 }139 });140 } else {141 let d = {142 state: 8,143 syncRequestsId: data.sync_requests_id,144 remoteSyncRequestId: data.relative_sync_requests_id,145 hotelId: data.hotel_id146 };147148 statusUpdater.updateStatus(d, (err, response) => {149 if(response) {150 // need to write logger functions151 } else {152 // need to write logger functions153 }154 });155 }156 });157 } else {158 let d = {159 state: 8,160 syncRequestsId: data.sync_requests_id,161 remoteSyncRequestId: data.relative_sync_requests_id,162 hotelId: data.hotel_id163 };164165 statusUpdater.updateStatus(d, (err, response) => {166 if(response) {167 // need to write logger functions168 } else {169 // need to write logger functions170 }171 });172 }173 });174 },175 importTables: (data, callback) => {176 let d = {177 state: 11,178 syncRequestsId: data.sync_requests_id,179 remoteSyncRequestId: data.relative_sync_requests_id,180 hotelId: data.hotel_id181 };182 statusUpdater.updateStatus(d, (err, response) => {183 if(response) {184 tableOperations.importTables(data, (err, importDataRes) => {185 if(importDataRes) {186 let stateValue = 12;187188 if(data.generate_sqlite==0 && data.generate_push==0) {189 stateValue = 16;190 } else if(data.generate_sqlite==0 && data.generate_push==1) {191 stateValue = 14;192 }193 console.log('REQUEST FROM importTables Fn');194 console.log('WRITING TO CLOUD and IN-PREMISE');195 let d = {196 state: stateValue,197 syncRequestsId: data.sync_requests_id,198 remoteSyncRequestId: data.relative_sync_requests_id,199 hotelId: data.hotel_id200 };201202 statusUpdater.updateStatus(d, (err, response) => {203 if(response) {204 return true;205 } else {206 return false;207 }208 });209 }210 });211 } else {212 let d = {213 state: 8,214 syncRequestsId: data.sync_requests_id,215 remoteSyncRequestId: data.relative_sync_requests_id,216 hotelId: data.hotel_id217 };218219 statusUpdater.updateStatus(d, (err, response) => {220 if(response) {221 // need to write logger functions222 } else {223 // need to write logger functions224 }225 });226 }227 });228 },229 generateSQLITE: (data, callback) => {230 let d = {231 state: 13,232 syncRequestsId: data.sync_requests_id,233 remoteSyncRequestId: data.relative_sync_requests_id,234 hotelId: data.hotel_id235 };236 statusUpdater.updateStatus(d, (err, response) => {237 if(response) {238 masterConfig.getConfigValue('core', 'inpremise_his_url', (err, row) => {239 let generateSqliteUrl =240 config.inpremise.syncManager.url.generateSqlite;241 console.log(generateSqliteUrl);242 let options = {243 method: 'POST',244 uri: generateSqliteUrl,245 headers: {246 'Content-Type': config.inpremise.headers.contentType,247 'Access-Token': process.env.access_token248 },249 body: JSON.stringify({250 files: data.module_name,251 hotel_id: data.hotel_id252 }),253 rejectUnauthorized: config.server.rejectUnauthorized254 };255256 rp(options)257 .then((getSqliteRes) => {258 console.log(getSqliteRes);259 if(isJSON(getSqliteRes)) {260 console.log(getSqliteRes);261 let parsedRes = JSON.parse(getSqliteRes);262263 if(parsedRes.status) {264 let stateValue = 14;265266 if(data.generate_push==0) {267 stateValue = 16;268 }269270 let d = {271 state: stateValue,272 syncRequestsId: data.sync_requests_id,273 remoteSyncRequestId: data.relative_sync_requests_id,274 hotelId: data.hotel_id275 };276277 statusUpdater.updateStatus(d, (err, response) => {278 if(response) {279 // need to write logger functions280 } else {281 // need to write logger functions282 }283 });284 } else {285 let d = {286 state: 12,287 syncRequestsId: data.sync_requests_id,288 remoteSyncRequestId: data.relative_sync_requests_id,289 hotelId: data.hotel_id290 };291292 statusUpdater.updateStatus(d, (err, response) => {293 if(response) {294 // need to write logger functions295 } else {296 // need to write logger functions297 }298 });299 }300 } else {301 console.log('not a valid JSON');302 }303 })304 .catch((err) => {305 console.log(err);306 let d = {307 state: 12,308 syncRequestsId: data.sync_requests_id,309 remoteSyncRequestId: data.relative_sync_requests_id,310 hotelId: data.hotel_id311 };312 statusUpdater.updateStatus(d, (err, response) => {313 if(response) {314 // need to write logger functions315 } else {316 // need to write logger functions317 }318 });319 });320 });321 } else {322 // need to write logger functions323 }324 });325 }326 };
...
skills.js
Source:skills.js
1import statusUpdater from "./statusUpdater";2import store from "../store";3export default {4 extraHeart: {5 name: "extraHeart",6 text: "Extra Heart",7 desc: "Increase HP by 30% per level",8 cost: 3,9 max: 3,10 prerequisites: false,11 aquire(){12 store.player.hp.extraHeartMultiplier += 0.3;13 statusUpdater.updateHp();14 },15 remove(){16 store.player.hp.extraHeartMultiplier = 0;17 statusUpdater.updateHp();18 }19 },20 extraBeef: {21 name: "extraBeef",22 text: "Extra Beef",23 desc: "Increase Attack by 10% per level",24 cost: 1,25 max: 5,26 prerequisites: ["extraHeart"],27 aquire(){28 store.player.attack.extraBeefMultiplier += 0.1;29 statusUpdater.updateAttack();30 },31 remove(){32 store.player.attack.extraBeefMultiplier = 0;33 statusUpdater.updateAttack();34 }35 },36 longerLegs: {37 name: "longerLegs",38 text: "Longer Legs",39 desc: "Increase speed by 1 - ATB fills up one tick sooner. Base is 25 ticks.",40 cost: 4,41 max: 3,42 prerequisites: false,43 aquire(){44 store.player.atb.longerLegs += 1;45 statusUpdater.updateSpeed();46 },47 remove(){48 store.player.atb.longerLegs = 0;49 statusUpdater.updateSpeed();50 },51 },52 superiorVision: {53 name: "superiorVision",54 text: "Superior Vision",55 desc: "Increase explore speed by 5 - ATB fills up 5 ticks sooner. Base is 100 ticks.",56 cost: 1,57 max: 10,58 prerequisites: false,59 aquire(){60 store.player.exploreSpeed += 5;61 statusUpdater.updateExploreSpeed();62 },63 remove(){64 store.player.exploreSpeed = 0;65 statusUpdater.updateExploreSpeed();66 },67 },68 centepedeForcipules:{69 name: "centepedeForcipules",70 text: "Centepede Forcipules",71 desc: "Base posion damage up 1 per level - by default poison has a 5% chance of hitting",72 cost: 4,73 max: 3,74 prerequisites: false,75 aquire(){76 store.player.poisonAttack.centepedeForcipules += 1;77 statusUpdater.updatePoisonAttack();78 }, 79 remove(){80 store.player.poisonAttack.centepedeForcipules = 0;81 statusUpdater.updatePoisonAttack();82 }, 83 },84 anaphylaxis:{85 name: "anaphylaxis",86 text: "Anaphylaxis",87 desc: "Posion chance is 20% greater - multiplier - it's multiplied by 20%, not 20% more!",88 cost: 2,89 max: 5,90 prerequisites: false,91 aquire(){92 store.player.poisonAttack.anaphylaxis += 20;93 statusUpdater.updatePoisonAttackChance();94 },95 remove(){96 store.player.poisonAttack.anaphylaxis = 0;97 statusUpdater.updatePoisonAttackChance();98 }, 99 },100 formicAcid:{101 name: "formicAcid",102 text: "Formic Acid",103 desc: "Posion chance base is 1% greater - additive - it's 1% more!",104 cost: 2,105 max: 10,106 prerequisites: false,107 aquire(){108 store.player.poisonAttack.formicAcid += 1;109 statusUpdater.updatePoisonAttackChance();110 },111 remove(){112 store.player.poisonAttack.formicAcid = 0;113 statusUpdater.updatePoisonAttackChance();114 }, 115 },116 fangs:{117 name: "fangs",118 text: "Fangs",119 desc: "Your poison attack percentage will directly multiply your damage",120 cost: 20,121 max: 1,122 prerequisites: false,123 aquire(){124 store.player.attack.fangsMultiplier = store.player.poisonAttack.chance/100;125 statusUpdater.updateAttack();126 },127 remove(){128 store.player.attack.fangsMultiplier = 0;129 statusUpdater.updateAttack();130 }, 131 },132 lobsterGreed:{133 name: "lobsterGreed",134 text: "Lobster Greed",135 desc: "These greedy lobster instincts will compell you to find 10% more gold per level.",136 cost: 2,137 max: 10,138 prerequisites: false,139 aquire(){140 store.player.goldGain.lobsterGreed += 0.1;141 statusUpdater.updateGoldGain();142 },143 remove(){144 store.player.goldGain.lobsterGreed = 0;145 statusUpdater.updateGoldGain();146 }, 147 },148 shrimpWisdom:{149 name: "shrimpWisdom",150 text: "Shrimp Wisdom",151 desc: "You could learn alot from shrimps you know? Gain 10% more experience per level.",152 cost: 2,153 max: 10,154 prerequisites: false,155 aquire(){156 store.player.expGain.shrimpWisdom += 0.1;157 statusUpdater.updateExpGain();158 },159 remove(){160 store.player.expGain.shrimpWisdom = 0;161 statusUpdater.updateExpGain();162 },163 },164 necrosis:{165 name: "necrosis",166 text: "Necrosis",167 desc: "Attacks are 10% more powerfull against poisoned foes.",168 cost: 2,169 max: 5,170 prerequisites: false,171 aquire(){172 store.player.toxin.necrosis += 0.1;173 statusUpdater.updateToxin();174 },175 remove(){176 store.player.toxin.necrosis = 0;177 statusUpdater.updateToxin();178 }, 179 },180 antigens:{181 name: "antigens",182 text: "Antigens",183 desc: "You negate one poison per level.",184 cost: 3,185 max: 3,186 prerequisites: false,187 aquire(){188 store.player.poisonDefence.antigens += 1;189 statusUpdater.updatePoisonDefence();190 },191 remove(){192 store.player.poisonDefence.antigens = 0;193 statusUpdater.updatePoisonDefence();194 }195 },196 joust: {197 name: "joust",198 text: "Joust",199 desc: "Every fourth attack will do 70% more damage per level.",200 cost: 4,201 max: 3,202 prerequisites: false,203 aquire(){204 store.player.strongFourth.joust += 0.7205 statusUpdater.updateStrongFourthVal();206 },207 remove(){208 store.player.strongFourth.joust = 0;209 statusUpdater.updateStrongFourthVal();210 } 211 },212 antiJoust: {213 name: "antiJoust",214 text: "Anti-Joust",215 desc: "You block an extra 2 damage per level - but only only every fourth time your attacked.",216 cost: 3,217 max: 3,218 prerequisites: false,219 aquire(){220 store.player.fourthDefence.antiJoust += 2;221 statusUpdater.updateFourthDefenceFlat();222 },223 remove(){224 store.player.fourthDefence.antiJoust = 0;225 statusUpdater.updateFourthDefenceFlat();226 } 227 }...
povertySketch.js
Source:povertySketch.js
1var mainPlayer, edges, leftEdge, rightEdge, topEdge, bottomEdge;2var poor1, poor2, poor3, poor4, poo5, poor6, poor7, poor8, poorPeople;3var stats = [0, 0 , 0, 0, 0, 0, 0, 0];4let timer = 8;5var gameState = 1;6function preload(){7 //backImage=loadImage("background.jpg");8 9}10function setup() {11 createCanvas(500,500);12 fill(0,0,0);13 mainPlayer=createSprite(250, 250, 25, 25);14 mainPlayer.shapeColor = "blue";15 16 edges = new Group();17 leftEdge=createSprite(0,250, 2.5, 500);18 edges.add(leftEdge);19 rightEdge=createSprite(500,250, 2.5, 500);20 edges.add(rightEdge);21 topEdge=createSprite(250,0, 500, 2.5);22 edges.add(topEdge);23 bottomEdge=createSprite(250,500, 500, 2.5);24 edges.add(bottomEdge);25 poor1 = createSprite(150, 250, 25, 25);26 poor2 = createSprite(75, 50, 25, 25);27 poor3 = createSprite(125, 150, 25, 25);28 poor4 = createSprite(175, 25, 25, 25);29 poor5 = createSprite(225, 375, 25, 25);30 poor6 = createSprite(25, 125, 25, 25);31 poor7 = createSprite(125, 325, 25, 25);32 poor8 = createSprite(350, 200, 25, 25);33}34function draw() {35 background(255,255,255);36 createEdgeSprites();37 mainPlayer.bounce(edges);38 textAlign(RIGHT);39 textSize(16);40 fill(0,0,0);41 text("Seconds Left: "+timer, 450, 25);42 if (gameState == 1){43 if(keyDown(UP_ARROW)) {44 mainPlayer.y = mainPlayer.y-5;45 }46 if(keyDown(DOWN_ARROW)) {47 mainPlayer.y = mainPlayer.y+5;48 }49 if(keyDown(LEFT_ARROW)) {50 mainPlayer.x = mainPlayer.x-5;51 }52 if(keyDown(RIGHT_ARROW)) {53 mainPlayer.x = mainPlayer.x+5;54 }55 56 //poor1.debug = true;57 58 if (mainPlayer.isTouching(poor1) && keyDown("space")){59 poor1.shapeColor = "green";60 stats[0] = 1; 61 }62 if (mainPlayer.isTouching(poor2) && keyDown("space")){63 poor2.shapeColor = "green";64 stats[1] = 1; 65 }66 if (mainPlayer.isTouching(poor3) && keyDown("space")){67 poor3.shapeColor = "green";68 stats[2] = 1; 69 }70 if (mainPlayer.isTouching(poor4) && keyDown("space")){71 poor4.shapeColor = "green"; 72 stats[3] = 1; 73 }74 if (mainPlayer.isTouching(poor5) && keyDown("space")){75 poor5.shapeColor = "green"; 76 statusbar[4] = 1; 77 }78 if (mainPlayer.isTouching(poor6) && keyDown("space")){79 poor6.shapeColor = "green"; 80 stats[5] = 1; 81 }82 if (mainPlayer.isTouching(poor7) && keyDown("space")){83 poor7.shapeColor = "green"; 84 stats[6] = 1; 85 }86 if (mainPlayer.isTouching(poor8) && keyDown("space")){87 poor8.shapeColor = "green"; 88 stats[7] = 1; 89 }90 91 if (frameCount % 60 == 0 && timer > 0) { // if the frameCount is divisible by 60, then a second has passed. it will stop at 092 timer --;93 }94 if (timer == 0) {95 gameState = 0;96 }97 //console.log(stats);98 drawSprites();99 } else if (gameState == 0){100 textSize(50);101 text("TIMES UP!", 400, 250);102 textSize(18);103 if (statusUpdater() == 0){104 text("You gave money to "+statusUpdater()+" people. Please try to give more money next time.", 400, 350);105 } else if (statusUpdater() == 1){106 text("You gave money to "+statusUpdater()+" person. Good Job!", 450, 350); 107 } else{108 text("You gave money to "+statusUpdater()+" people. Good Job!", 450, 350);109 }110 }111}112function statusUpdater(){113 var sum = 0;114 for (var i = 0; i < stats.length; i++){115 if (stats[i]== 1){116 sum++;117 }118 }119 return sum;...
artifacts.js
Source:artifacts.js
1import store from "../store";2import statusUpdater from "./statusUpdater";3export default {4 dodgyTicker:{5 name:"dodgyTicker",6 text: "The Dodgy Ticker",7 desc: "Beep Beep Beep BONG. Your fourth attack is greater so your other attacks are nerfed.",8 equip(){9 store.artifacts.dodgyTicker.equipped = true;10 store.player.attack.dodgyTicker += 1;11 store.player.strongFourth.dodgyTicker += 3;12 statusUpdater.updateAttack();13 statusUpdater.updateStrongFourthVal();14 },15 unequip(){16 store.artifacts.dodgyTicker.equipped = false;17 store.player.attack.dodgyTicker -= 1;18 store.player.strongFourth.dodgyTicker -= 3;19 statusUpdater.updateAttack();20 statusUpdater.updateStrongFourthVal();21 }22 },23 experimentalVaccine:{24 name:"experimentalVaccine",25 text: "Experimental Vaccine",26 desc: "You will become more immune to poison, your long term heath will suffer",27 equip(){28 store.artifacts.experimentalVaccine.equipped = true;29 store.player.hp.experimentalVaccine += 1;30 store.player.poisonDefence.experimentalVaccine += 2;31 statusUpdater.updateHp();32 statusUpdater.updatePoisonDefence();33 },34 unequip(){35 store.artifacts.experimentalVaccine.equipped = false;36 store.player.hp.experimentalVaccine -= 1;37 store.player.poisonDefence.experimentalVaccine -= 2;38 statusUpdater.updateHp();39 statusUpdater.updatePoisonDefence();40 }41 },42 pillow:{43 name:"pillow",44 text: "The Pillow",45 desc: "Life just got more comfortable - you will rely less on violence.",46 equip(){47 store.artifacts.pillow.equipped = true;48 store.player.hp.pillow += 0.3;49 store.player.attack.pillow += 1;50 statusUpdater.updateHp();51 statusUpdater.updateAttack();52 },53 unequip(){54 store.artifacts.pillow.equipped = false;55 store.player.hp.pillow -= 0.3;56 store.player.attack.pillow -= 1;57 statusUpdater.updateHp();58 statusUpdater.updateAttack();59 }60 },61 plusSign:{62 name:"plusSign",63 text: "A Plus Sign",64 desc: "Yay, no drabacks.",65 equip(){66 store.artifacts.plusSign.equipped = true;67 store.player.hp.plusSign += 13;68 store.player.attack.plusSign += 3;69 statusUpdater.updateHp();70 statusUpdater.updateAttack();71 },72 unequip(){73 store.artifacts.plusSign.equipped = false;74 store.player.hp.plusSign -= 13;75 store.player.attack.plusSign -= 3;76 statusUpdater.updateHp();77 statusUpdater.updateAttack();78 },79 },...
status-updater.factory.test.js
Source:status-updater.factory.test.js
1'use strict';2var $q;3var $timeout;4// Weblab mock.5var Weblab = new function() {6 var _cmd = "";7 var _result = "";8 this.dbgSetOfflineSendCommandResponse = function(cmd, result) {9 _cmd = cmd;10 if(result == undefined)11 result = true;12 _result = result;13 };14 this.sendCommand = function(cmd, success, failure) {15 if(_result) {16 success(_cmd);17 }18 if(!_result)19 failure(_cmd);20 };21};22describe('Factory: statusUpdater', function () {23 // load the controller's module24 beforeEach(module('hwboard'));25 // Initialize the controller and a mock scope26 beforeEach(inject(function (_statusUpdater_, _$q_, _$timeout_) {27 statusUpdater = _statusUpdater_;28 $timeout = _$timeout_;29 $q = _$q_;30 }));31 it('should pass', function () {32 expect(3).toBe(3);33 });34 it('should call callback just after starting', function(done) {35 expect(statusUpdater).toBeDefined();36 statusUpdater.setOnStatusUpdate(onStatusUpdateSimple);37 statusUpdater.start();38 $timeout.flush();39 // --------------40 // Implementations41 // --------------42 function onStatusUpdateSimple(status) {43 done();44 } // !onStatusUpdate45 });46 it('should call callback after a while through $timeout', function(done) {47 expect(statusUpdater).toBeDefined();48 statusUpdater.setOnStatusUpdate(onStatusUpdateDeferred);49 statusUpdater.start();50 var times_called = 0;51 $timeout.flush();52 $timeout.flush();53 // ---------------54 // Implementations55 // ---------------56 function onStatusUpdateDeferred(status) {57 times_called += 1;58 if(times_called > 1) {59 done();60 }61 } // !onStatusUpdate62 });63 it('should report a "programming" test status', function(done) {64 expect(statusUpdater).toBeDefined();65 statusUpdater.setOnStatusUpdate(onStatusUpdateCheck);66 statusUpdater.start();67 $timeout.flush();68 // ---------------69 // Implementations70 // ---------------71 function onStatusUpdateCheck(status) {72 expect(status).toBeDefined();73 expect(status).toEqual(jasmine.any(String));74 expect(status).toBe("programming");75 done();76 }77 });...
levelModule.js
Source:levelModule.js
1import store from "../store";2import enemies from "../gameData/enemyData";3import playerLevelData from "../gameData/playerLevelData";4import log from "./log";5import statusUpdater from "./statusUpdater";6export default {7 getXp(enemyName){8 let xp = enemies[enemyName].xp * store.player.expGain.val/100;9 let relativeLevel = store.player.level.val - enemies[enemyName].level;10 if (relativeLevel > 4){11 return 1;12 }13 if ( relativeLevel < -4){14 return Math.floor(xp * 3);15 }16 switch( relativeLevel ){17 case -4:18 return Math.floor(xp * 2.5);19 case -3:20 return Math.floor(xp * 1.9);21 case -2:22 return Math.floor(xp * 1.4);23 case -1:24 return Math.floor(xp * 1.1);25 case 0:26 return xp;27 case 1:28 return Math.ceil(xp * 0.9);29 case 2:30 return Math.ceil(xp * 0.8);31 case 3:32 return Math.ceil(xp * 0.6);33 case 4:34 return Math.ceil(xp * 0.3);35 36 }37 },38 applyXp(enemyName){39 let xp = this.getXp(enemyName);40 let level = store.player.level;41 level.toNext -= xp;42 if (level.toNext <= 0){43 level.val += 1;44 level.toNext = level.toNextMax = playerLevelData.levelThresholds[level.val]45 log.updateMessage("You have gained a level!");46 levelUp();47 }48 },49 unqueEnemyUpdate(enemyKilled){50 if( store.enemiesKilledList[enemyKilled] === 0 ){51 uniqueEnemyUp();52 }53 store.enemiesKilledList[enemyKilled]++;54 }55}56function levelUp(){57 let statusToApply = playerLevelData.levelRewards[store.player.level.val];58 store.player.resources.sp += statusToApply.sp;59 store.player.hp.levelModifier += statusToApply.hp;60 statusUpdater.updateHp();61 store.player.attack.levelModifier += statusToApply.attack;62 statusUpdater.updateAttack();63}64function uniqueEnemyUp(){65 store.player.uniqueEnemiesLevel.val++;66 let statusToApply = playerLevelData.uniqueEnemyRewards[store.player.uniqueEnemiesLevel.val];67 store.player.resources.sp += statusToApply.sp;68 store.player.hp.uniqueEnemiesLevelModifier += statusToApply.hp;69 statusUpdater.updateHp();70 store.player.attack.uniqueEnemiesLevelModifier += statusToApply.attack;71 statusUpdater.updateAttack(); ...
barrel-update.router.js
Source:barrel-update.router.js
1const express = require("express");2const pool = require("../modules/pool");3const {4 rejectUnauthenticated,5} = require("../modules/authentication-middleware");6const { query } = require("../modules/pool");7const router = express.Router();8/**9 * UPDATE BARREL STATUS ACTIVE/DEACTIVATED10 */11router.put("/update/:id", rejectUnauthenticated, (req, res) => {12 let status = req.body.status;13 let id = req.body.id;14 let statusUpdater = !status;15 const queryText = `UPDATE barrels set status = $2 WHERE id = $1;`;16 pool17 .query(queryText, [id, statusUpdater])18 .then((result) => {19 res.sendStatus(200);20 })21 .catch((error) => {22 console.log("ERROR IN SERVER PUT", error);23 res.sendStatus(500);24 });25});26/**27 * UPDATE BARREL STATUS PUBLIC/PRIVATFE28 */29router.put("/barrel-status/:id", rejectUnauthenticated, (req, res) => {30 let public = req.body.public;31 let id = req.body.id;32 let statusUpdater = !public;33 // console.log(!public);34 const queryText = `UPDATE barrels set public = $2 WHERE id = $1;`;35 pool36 .query(queryText, [id, statusUpdater])37 .then((result) => {38 // console.log(result);39 res.sendStatus(200);40 })41 .catch((error) => {42 console.log("ERROR IN SERVER PUT", error);43 res.sendStatus(500);44 });45});...
index.jsx
Source:index.jsx
1import React from 'react';2import StatusUpdater from './StatusUpdater';3import {Formik} from 'formik';4const FormFormik = ({isLoading, children, ...props}) => {5 return (6 <Formik {...props}>7 <StatusUpdater isLoading={isLoading}>8 {children}9 </StatusUpdater>10 </Formik>11 );12};...
Using AI Code Generation
1var karma = require('karma').server;2karma.start({3}, function(exitCode) {4 console.log('Karma has exited with ' + exitCode);5 process.exit(exitCode);6});7module.exports = function(config) {8 config.set({9 junitReporter: {10 }11 });12};
Using AI Code Generation
1var karma = require('karma');2var karmaServer = new karma.Server({3}, function(exitCode) {4 console.log('Karma has exited with ' + exitCode);5 process.exit(exitCode);6});7karmaServer.start();8karmaServer.on('browser_register', function(browser) {9 console.log('New browser has registered: ' + browser.name);10 karmaServer.StatusUpdater.set('New browser has registered: ' + browser.name);11});12karmaServer.on('browser_complete', function(browser) {13 console.log('Browser has completed: ' + browser.name);14 karmaServer.StatusUpdater.set('Browser has completed: ' + browser.name);15});16karmaServer.on('browser_error', function(browser) {17 console.log('Browser has errored: ' + browser.name);18 karmaServer.StatusUpdater.set('Browser has errored: ' + browser.name);19});20karmaServer.on('browser_start', function(browser) {21 console.log('Browser has started: ' + browser.name);22 karmaServer.StatusUpdater.set('Browser has started: ' + browser.name);23});24karmaServer.on('browser_complete', function(browser) {25 console.log('Browser has completed: ' + browser.name);26 karmaServer.StatusUpdater.set('Browser has completed: ' + browser.name);27});28karmaServer.on('browser_error', function(browser) {29 console.log('Browser has errored: ' + browser.name);30 karmaServer.StatusUpdater.set('Browser has errored: ' + browser.name);31});32karmaServer.on('browser_start', function(browser) {33 console.log('Browser has started: ' + browser.name);34 karmaServer.StatusUpdater.set('Browser has started: ' + browser.name);35});36karmaServer.on('browser_complete', function(browser) {37 console.log('Browser has completed: ' + browser.name);38 karmaServer.StatusUpdater.set('Browser has completed: ' + browser.name);39});40karmaServer.on('browser_error', function(browser) {41 console.log('Browser has errored: ' + browser.name);42 karmaServer.StatusUpdater.set('Browser has errored: ' + browser.name);43});44karmaServer.on('browser_start', function(browser) {45 console.log('Browser has started: ' + browser.name);46 karmaServer.StatusUpdater.set('Browser has started: ' + browser.name);47});
Using AI Code Generation
1var karma = require('karma').server;2karma.start({3 junitReporter: {4 },5 coverageReporter: {6 }7}, function (exitCode) {8 if (exitCode === 0) {9 console.log('Karma completed successfully');10 process.exit(0);11 } else {12 console.log('Karma failed with exit code: ' + exitCode);13 process.exit(exitCode);14 }15});
Using AI Code Generation
1var statusUpdater = require('karma/lib/status-updater');2var logger = require('karma/lib/logger');3var config = require('karma/lib/config');4var server = require('karma/lib/server');5var karmaServer = new server.Server(config.parseConfig("karma.conf.js", {}), function(exitCode) {6 console.log('Karma has exited with ' + exitCode);7 process.exit(exitCode);8 });9 karmaServer.start();
Using AI Code Generation
1module.exports = function(config) {2 config.set({3 require('karma-status-updater'),4 });5};6module.exports = function(config) {7 config.set({8 require('karma-status-updater'),9 });10};11module.exports = function(config) {12 config.set({13 require('karma-status-updater'),14 });15};16module.exports = function(config) {17 config.set({18 require('karma-status-updater'),19 });20};21module.exports = function(config) {22 config.set({23 require('karma-status-updater'),24 });25};26module.exports = function(config) {27 config.set({28 require('karma-status-updater'),29 });30};31module.exports = function(config) {32 config.set({
Using AI Code Generation
1var statusUpdater = require('karma/lib/reporter').StatusUpdater;2statusUpdater.prototype.update = function (results, callback) {3 console.log('update called');4 callback(results);5};6var karma = require('karma/lib/server');7karma.start(config, function (exitCode) {8 console.log('Karma has exited with ' + exitCode);9 process.exit(exitCode);10});
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!!