Best JavaScript code snippet using wpt
h1bRecordRouter.test.js
Source:h1bRecordRouter.test.js
1const log4js = require('log4js')2log4js.configure({3 // appenders: { h1bData: { type: 'file', filename: 'h1bData.log' } },4 appenders: { h1bData: { type: 'console' } },5 categories: { default: { appenders: ['h1bData'], level: 'info' } }6});7const request = require('supertest')8const log = console.log;9const logger = log4js.getLogger('h1bData');10const chalk = require('chalk')11const { asyncForEach, asyncForLoop } = require('../src/utilities/asyncRoutines')12const { summarize, decompressSummaryRecord, readSummarizedQueries,13 createKey } = require('../src/utilities/summarize')14var { summaryMap } = require('../src/utilities/summarize')15 16const { h1bRecordRouter, performQuery, processWsState, createCaseNumberQueryArray } 17 = require('../src/routers/h1bRecordRouter')18const { app } = require('../src/app')19const expect = require('chai').expect20const sinon = require('sinon')21const _ = require('lodash')22const { compress, decompress } = require('../src/utilities/compression')23const { CASE_NUMBER, YEAR, WAGE_LEVEL, EMPLOYER_NAME, EMPLOYER_ADDRESS,24 EMPLOYER_CITY, EMPLOYER_STATE, WORKSITE_CONGRESS_DISTRICT,25 WORKSITE_LATITUDE, WORKSITE_LONGITUDE, WORKSITE_ADDR1, WORKSITE_ADDR2,26 WORKSITE_CITY, WORKSITE_COUNTY, WORKSITE_STATE, TOTAL_WORKERS, TOTAL_LCAS, SOC_CODE, 27 JOB_TITLE, LEVEL_1, LEVEL_2, LEVEL_3, LEVEL_4,28 NEW_EMPLOYMENT, CONTINUED_EMPLOYMENT, CHANGE_PREVIOUS_EMPLOYMENT,29 NEW_CONCURRENT_EMPLOYMENT, CHANGE_EMPLOYER, AMENDED_PETITION,30 UNSPECIFIED, ANNUALIZED_PREVAILING_WAGE, ANNUALIZED_WAGE_RATE_OF_PAY,31 salaryLevels, h1bRecord } 32 = require('../src/models/h1bRecordSchema')33class JsonTest {34 constructor(res, stat, query){35 this.res = res36 this.stat = stat37 this.query = query38 var queryCopy = _.clone(query)39 delete queryCopy['YEAR']40 if(_.isEmpty(queryCopy)){41 this.yearRequest = true42 }else{43 this.yearRequest = false44 }45 }46 status(val) {47 expect(val).to.be.equal(this.stat)48 return this.res49 }50 json(h1bSummary) {51 const keys = Object.getOwnPropertyNames(this.query)52 const h1bSummaryKeys = Object.getOwnPropertyNames(h1bSummary)53 logger.trace(chalk.bgRed.white.bold(`query keys result: ${JSON.stringify(keys)}`))54 logger.trace(chalk.bgRed.white.bold(`h1bSummaryKeys result: ${JSON.stringify(h1bSummaryKeys)}`))55 keys.forEach((key) => {56 expect(this.query[key]).to.be.equal(h1bSummary[key])57 delete h1bSummary[key]58 })59 expect(!_.isEmpty(h1bSummary)).to.be.true60 expect(_.isNumber(h1bSummary[TOTAL_LCAS])).to.be.true61 expect(_.isNumber(h1bSummary[TOTAL_WORKERS])).to.be.true62 expect(!_.isEmpty(h1bSummary.status)).to.be.true63 expect(_.isEmpty(h1bSummary.occupations)).to.be.true64 expect(_.isEmpty(h1bSummary.categories)).to.be.true65 expect(_.isEmpty(h1bSummary.latLngMap)).to.be.true66 expect(_.isEmpty(h1bSummary.percentiles)).to.be.true67 expect(_.isEmpty(h1bSummary.wageMap)).to.be.true68 expect(_.isEmpty(h1bSummary.wageLevels)).to.be.true69 expect(_.isEmpty(h1bSummary.lcas)).to.be.true70 logger.trace(chalk.bgRed.white.bold(`Unit test result: ${JSON.stringify(h1bSummary)}`))71 const decompressed = decompress(h1bSummary.status)72 expect(_.isEmpty(decompressed.status)).to.be.true73 expect(_.isEmpty(decompressed.occupations)).to.be.false74 expect(_.isEmpty(decompressed.categories)).to.be.false75 if(!this.yearRequest){76 expect(_.isEmpty(decompressed.latLngMap)).to.be.false77 expect(_.isEmpty(decompressed.percentiles)).to.be.false78 expect(_.isEmpty(decompressed.wageMap)).to.be.false79 }80 expect(_.isEmpty(decompressed.wageLevels)).to.be.false81 expect(_.isEmpty(decompressed.wageLevels.workers)).to.be.false82 expect(_.isEmpty(decompressed.wageLevels.lcas)).to.be.false83 delete decompressed.occupations84 delete decompressed.categories85 delete decompressed.latLngMap86 delete decompressed.percentiles87 delete decompressed.wageMap88 delete decompressed.wageLevels.workers89 delete decompressed.wageLevels.lcas90 expect(_.isEmpty(decompressed.wageLevels)).to.be.true91 delete decompressed.wageLevels92 expect(_.isEmpty(decompressed)).to.be.true93 delete h1bSummary[TOTAL_LCAS]94 delete h1bSummary[TOTAL_WORKERS]95 delete h1bSummary.status96 logger.trace(chalk.bgRed.white.bold(`h1bSummary: ${JSON.stringify(h1bSummary, undefined, 2)}`))97 expect(_.isEmpty(h1bSummary)).to.be.true98 }99}100describe('Test h1bRecordRouter', () => {101 describe('Test performQuery() handling a single year parameter', () => {102 beforeEach(async() => {103 summaryMap = await readSummarizedQueries()104 logger.trace(`summaryMap: ${JSON.stringify(summaryMap, undefined, 2)}`)105 log4js.configure({106 // appenders: { h1bData: { type: 'file', filename: 'h1bData.log' } },107 appenders: { h1bData: { type: 'console'} },108 categories: { default: { appenders: ['h1bData'], level: 'warn' } }109 });110 })111 afterEach(() => {112 log4js.configure({113 // appenders: { h1bData: { type: 'file', filename: 'h1bData.log' } },114 appenders: { h1bData: { type: 'console'} },115 categories: { default: { appenders: ['h1bData'], level: 'info' } }116 });117 sinon.restore()118 }) 119 logger.trace('Testing h1bRecordRouter');120 it('1) Testing performQuery() (year-2017) with key in summaryMap', async () => {121 expect(_.isEmpty(summaryMap)).to.be.false122 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))123 const year = 2017124 var query = {}125 query[YEAR] = year126 const req = { "body": query }127 const res = {}128 var jsonTest = new JsonTest(res, 200, query)129 res.status = (val) => jsonTest.status(val)130 res.json = (h1bRecord) => jsonTest.json(h1bRecord)131 await performQuery(req, res) 132 })133 it('2) Testing performQuery() (year-2016) with key in summaryMap', async () => {134 expect(_.isEmpty(summaryMap)).to.be.false135 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))136 const year = 2016137 var query = {}138 query[YEAR] = year139 const req = { "body": query }140 const res = {}141 var jsonTest = new JsonTest(res, 200, query)142 res.status = (val) => jsonTest.status(val)143 res.json = (h1bRecord) => jsonTest.json(h1bRecord)144 await performQuery(req, res) 145 })146 it('3) Testing performQuery() (year-2015) with key in summaryMap', async () => {147 expect(_.isEmpty(summaryMap)).to.be.false148 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))149 const year = 2015150 var query = {}151 query[YEAR] = year152 const req = { "body": query }153 const res = {}154 var jsonTest = new JsonTest(res, 200, query)155 res.status = (val) => jsonTest.status(val)156 res.json = (h1bRecord) => jsonTest.json(h1bRecord)157 await performQuery(req, res) 158 })159 it('4) Testing performQuery() (year-2014) with key in summaryMap', async () => {160 expect(_.isEmpty(summaryMap)).to.be.false161 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))162 const year = 2014163 var query = {}164 query[YEAR] = year165 const req = { "body": query }166 const res = {}167 var jsonTest = new JsonTest(res, 200, query)168 res.status = (val) => jsonTest.status(val)169 res.json = (h1bRecord) => jsonTest.json(h1bRecord)170 await performQuery(req, res) 171 })172 it('5) Testing performQuery() (year-2013) with key in summaryMap', async () => {173 expect(_.isEmpty(summaryMap)).to.be.false174 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))175 const year = 2013176 var query = {}177 query[YEAR] = year178 const req = { "body": query }179 const res = {}180 var jsonTest = new JsonTest(res, 200, query)181 res.status = (val) => jsonTest.status(val)182 res.json = (h1bRecord) => jsonTest.json(h1bRecord)183 await performQuery(req, res) 184 })185 it('6) Testing performQuery() (year-2012) with key in summaryMap', async () => {186 expect(_.isEmpty(summaryMap)).to.be.false187 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))188 const year = 2012189 var query = {}190 query[YEAR] = year191 const req = { "body": query }192 const res = {}193 var jsonTest = new JsonTest(res, 200, query)194 res.status = (val) => jsonTest.status(val)195 res.json = (h1bRecord) => jsonTest.json(h1bRecord)196 await performQuery(req, res) 197 })198 it('7) Testing performQuery() (year-2011) with key in summaryMap', async () => {199 expect(_.isEmpty(summaryMap)).to.be.false200 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))201 const year = 2011202 var query = {}203 query[YEAR] = year204 const req = { "body": query }205 const res = {}206 var jsonTest = new JsonTest(res, 200, query)207 res.status = (val) => jsonTest.status(val)208 res.json = (h1bRecord) => jsonTest.json(h1bRecord)209 await performQuery(req, res) 210 })211 it('8) Testing performQuery() (year-2010) with key in summaryMap', async () => {212 expect(_.isEmpty(summaryMap)).to.be.false213 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))214 const year = 2010215 var query = {}216 query[YEAR] = year217 const req = { "body": query }218 const res = {}219 var jsonTest = new JsonTest(res, 200, query)220 res.status = (val) => jsonTest.status(val)221 res.json = (h1bRecord) => jsonTest.json(h1bRecord)222 await performQuery(req, res) 223 })224 })225 describe('Test performQuery()', () => {226 beforeEach(async() => {227 summaryMap = await readSummarizedQueries()228 logger.trace(`summaryMap: ${JSON.stringify(summaryMap, undefined, 2)}`)229 log4js.configure({230 // appenders: { h1bData: { type: 'file', filename: 'h1bData.log' } },231 appenders: { h1bData: { type: 'console'} },232 categories: { default: { appenders: ['h1bData'], level: 'warn' } }233 });234 })235 afterEach(() => {236 log4js.configure({237 // appenders: { h1bData: { type: 'file', filename: 'h1bData.log' } },238 appenders: { h1bData: { type: 'console'} },239 categories: { default: { appenders: ['h1bData'], level: 'info' } }240 });241 sinon.restore()242 }) 243 it('1) Testing performQuery() (year, state) with undefined summaryMap', async () => {244 summaryMap = undefined245 expect(_.isEmpty(summaryMap)).to.be.true246 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))247 const year = 2016248 const wsState = "WY"249 var query = {}250 query[YEAR] = year251 query[WORKSITE_STATE] = wsState252 const req = { "body": query }253 const res = {}254 var jsonTest = new JsonTest(res, 200, query)255 res.status = (val) => jsonTest.status(val)256 res.json = (h1bRecord) => jsonTest.json(h1bRecord)257 await performQuery(req, res)258 })259 it('2) Testing performQuery() (year, state) without key in summaryMap', async () => {260 summaryMap = {}261 expect(_.isEmpty(summaryMap)).to.be.true262 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))263 const year = 2017264 const wsState = "WV"265 var query = {}266 query[YEAR] = year267 query[WORKSITE_STATE] = wsState268 const req = { "body": query }269 const res = {}270 var jsonTest = new JsonTest(res, 200, query)271 res.status = (val) => jsonTest.status(val)272 res.json = (h1bRecord) => jsonTest.json(h1bRecord)273 await performQuery(req, res)274 })275 it('3) Testing performQuery() (year, state) with key in summaryMap', async () => {276 expect(_.isEmpty(summaryMap)).to.be.false277 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))278 const year = 2017279 const wsState = "AK"280 var query = {}281 query[YEAR] = year282 query[WORKSITE_STATE] = wsState283 const req = { "body": query }284 const res = {}285 var jsonTest = new JsonTest(res, 200, query)286 res.status = (val) => jsonTest.status(val)287 res.json = (h1bRecord) => jsonTest.json(h1bRecord)288 await performQuery(req, res)289 })290 it('4) Testing performQuery() (year, employer) with undefined summaryMap', async () => {291 summaryMap = undefined292 expect(_.isEmpty(summaryMap)).to.be.true293 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))294 const year = 2016295 const empName = "PRICEWATERHOUSECOOPERS LLP"296 var query = {}297 query[YEAR] = year298 query[EMPLOYER_NAME] = empName299 const req = { "body": query }300 const res = {}301 var jsonTest = new JsonTest(res, 200, query)302 res.status = (val) => jsonTest.status(val)303 res.json = (h1bRecord) => jsonTest.json(h1bRecord)304 await performQuery(req, res)305 })306 it('5) Testing performQuery() (year, employer) without key in summaryMap', async () => {307 summaryMap = {}308 expect(_.isEmpty(summaryMap)).to.be.true309 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))310 const year = 2017311 const empName = "ADOBE SYSTEMS INCORPORATED"312 var query = {}313 query[YEAR] = year314 query[EMPLOYER_NAME] = empName315 const req = { "body": query }316 const res = {}317 var jsonTest = new JsonTest(res, 200, query)318 res.status = (val) => jsonTest.status(val)319 res.json = (h1bRecord) => jsonTest.json(h1bRecord)320 await performQuery(req, res)321 })322 it('6) Testing performQuery() (year, employer) with key in summaryMap', async () => {323 expect(_.isEmpty(summaryMap)).to.be.false324 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))325 const year = 2016326 const empName = "MCKINSEY & COMPANY, INC. UNITED STATES"327 var query = {}328 query[YEAR] = year329 query[EMPLOYER_NAME] = empName330 const req = { "body": query }331 const res = {}332 var jsonTest = new JsonTest(res, 200, query)333 res.status = (val) => jsonTest.status(val)334 res.json = (h1bRecord) => jsonTest.json(h1bRecord)335 await performQuery(req, res)336 })337 it('7) Testing performQuery() (year, state, city) with undefined summaryMap', async () => {338 summaryMap = undefined339 expect(_.isEmpty(summaryMap)).to.be.true340 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))341 const year = 2016342 const wsState = "TX"343 const wsCity = "PLANO"344 var query = {}345 query[YEAR] = year346 query[WORKSITE_STATE] = wsState347 query[WORKSITE_CITY] = wsCity348 const req = { "body": query }349 const res = {}350 var jsonTest = new JsonTest(res, 200, query)351 res.status = (val) => jsonTest.status(val)352 res.json = (h1bRecord) => jsonTest.json(h1bRecord)353 await performQuery(req, res)354 })355 it('8) Testing performQuery() (year, state, city) without key in summaryMap', async () => {356 summaryMap = {}357 expect(_.isEmpty(summaryMap)).to.be.true358 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))359 const year = 2016360 const wsState = "NC"361 const wsCity = "GREENSBORO"362 var query = {}363 query[YEAR] = year364 query[WORKSITE_STATE] = wsState365 query[WORKSITE_CITY] = wsCity366 const req = { "body": query }367 const res = {}368 var jsonTest = new JsonTest(res, 200, query)369 res.status = (val) => jsonTest.status(val)370 res.json = (h1bRecord) => jsonTest.json(h1bRecord)371 await performQuery(req, res)372 })373 it('9) Testing performQuery() (year, state, city) with key in summaryMap', async () => {374 expect(_.isEmpty(summaryMap)).to.be.false375 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))376 const year = 2017377 const wsState = "NC"378 const wsCity = "GREENSBORO"379 var query = {}380 query[YEAR] = year381 query[WORKSITE_STATE] = wsState382 query[WORKSITE_CITY] = wsCity383 const req = { "body": query }384 const res = {}385 var jsonTest = new JsonTest(res, 200, query)386 res.status = (val) => jsonTest.status(val)387 res.json = (h1bRecord) => jsonTest.json(h1bRecord)388 await performQuery(req, res)389 })390 it('10) Testing performQuery() (year, state, county) with undefined summaryMap', async () => {391 summaryMap = undefined392 expect(_.isEmpty(summaryMap)).to.be.true393 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))394 const year = 2017395 const wsState = "MD"396 const wsCounty = "ANNE ARUNDEL"397 var query = {}398 query[YEAR] = year399 query[WORKSITE_STATE] = wsState400 query[WORKSITE_COUNTY] = wsCounty401 const req = { "body": query }402 const res = {}403 var jsonTest = new JsonTest(res, 200, query)404 res.status = (val) => jsonTest.status(val)405 res.json = (h1bRecord) => jsonTest.json(h1bRecord)406 await performQuery(req, res)407 })408 it('11) Testing performQuery() (year, state, county) without key in summaryMap', async () => {409 summaryMap = {}410 expect(_.isEmpty(summaryMap)).to.be.true411 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))412 const year = 2017413 const wsState = "FL"414 const wsCounty = "PALM BEACH"415 var query = {}416 query[YEAR] = year417 query[WORKSITE_STATE] = wsState418 query[WORKSITE_COUNTY] = wsCounty419 const req = { "body": query }420 const res = {}421 var jsonTest = new JsonTest(res, 200, query)422 res.status = (val) => jsonTest.status(val)423 res.json = (h1bRecord) => jsonTest.json(h1bRecord)424 await performQuery(req, res)425 })426 it('12) Testing performQuery() (year, state, county) with key in summaryMap', async () => {427 expect(_.isEmpty(summaryMap)).to.be.false428 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))429 const year = 2017430 const wsState = "NC"431 const wsCounty = "DURHAM"432 var query = {}433 query[YEAR] = year434 query[WORKSITE_STATE] = wsState435 query[WORKSITE_COUNTY] = wsCounty436 const req = { "body": query }437 const res = {}438 var jsonTest = new JsonTest(res, 200, query)439 res.status = (val) => jsonTest.status(val)440 res.json = (h1bRecord) => jsonTest.json(h1bRecord)441 await performQuery(req, res)442 })443 it('13) Testing performQuery() (year, state, city) with key in summaryMap', async () => {444 expect(_.isEmpty(summaryMap)).to.be.false445 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))446 const year = 2016447 const wsState = "NC"448 const wsCity = "DURHAM"449 var query = {}450 query[YEAR] = year451 query[WORKSITE_STATE] = wsState452 query[WORKSITE_CITY] = wsCity453 const req = { "body": query }454 const res = {}455 var jsonTest = new JsonTest(res, 200, query)456 res.status = (val) => jsonTest.status(val)457 res.json = (h1bRecord) => jsonTest.json(h1bRecord)458 await performQuery(req, res)459 })460 it('14) Testing performQuery() (year, state, congress district) with undefined summaryMap', async () => {461 summaryMap = undefined462 expect(_.isEmpty(summaryMap)).to.be.true463 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))464 const year = 2017465 const wsState = "VA"466 const wsCongressDist = 2467 var query = {}468 query[YEAR] = year469 query[WORKSITE_STATE] = wsState470 query[WORKSITE_CONGRESS_DISTRICT] = wsCongressDist471 const req = { "body": query }472 const res = {}473 var jsonTest = new JsonTest(res, 200, query)474 res.status = (val) => jsonTest.status(val)475 res.json = (h1bRecord) => jsonTest.json(h1bRecord)476 await performQuery(req, res)477 })478 it('15) Testing performQuery() (year, state, congress district) without key in summaryMap', async () => {479 summaryMap = {}480 expect(_.isEmpty(summaryMap)).to.be.true481 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))482 const year = 2017483 const wsState = "NY"484 const wsCongressDist = 10485 var query = {}486 query[YEAR] = year487 query[WORKSITE_STATE] = wsState488 query[WORKSITE_CONGRESS_DISTRICT] = wsCongressDist489 const req = { "body": query }490 const res = {}491 var jsonTest = new JsonTest(res, 200, query)492 res.status = (val) => jsonTest.status(val)493 res.json = (h1bRecord) => jsonTest.json(h1bRecord)494 await performQuery(req, res)495 })496 it('16) Testing performQuery() (year, state, congress district) with key in summaryMap', async () => {497 expect(_.isEmpty(summaryMap)).to.be.false498 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))499 const year = 2016500 const wsState = "NC"501 const wsCongressDist = 4502 var query = {}503 query[YEAR] = year504 query[WORKSITE_STATE] = wsState505 query[WORKSITE_CONGRESS_DISTRICT] = wsCongressDist506 const req = { "body": query }507 const res = {}508 var jsonTest = new JsonTest(res, 200, query)509 res.status = (val) => jsonTest.status(val)510 res.json = (h1bRecord) => jsonTest.json(h1bRecord)511 await performQuery(req, res)512 })513 it('17) Testing performQuery() (year, state, county) with undefined summaryMap', async () => {514 summaryMap = undefined515 expect(_.isEmpty(summaryMap)).to.be.true516 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))517 const year = 2017518 const wsState = "CA"519 const wsCounty = 'ALAMEDA'520 var query = {}521 query[YEAR] = year522 query[WORKSITE_STATE] = wsState523 query[WORKSITE_COUNTY] = wsCounty524 const req = { "body": query }525 const res = {}526 var jsonTest = new JsonTest(res, 200, query)527 res.status = (val) => jsonTest.status(val)528 res.json = (h1bRecord) => jsonTest.json(h1bRecord)529 await performQuery(req, res)530 })531 it('18) Testing performQuery() (year, state, county) without key in summaryMap', async () => {532 summaryMap = {}533 expect(_.isEmpty(summaryMap)).to.be.true534 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))535 const year = 2014536 const wsState = "PA"537 const wsCounty = 'PHILADELPHIA'538 var query = {}539 query[YEAR] = year540 query[WORKSITE_STATE] = wsState541 query[WORKSITE_COUNTY] = wsCounty542 const req = { "body": query }543 const res = {}544 var jsonTest = new JsonTest(res, 200, query)545 res.status = (val) => jsonTest.status(val)546 res.json = (h1bRecord) => jsonTest.json(h1bRecord)547 await performQuery(req, res)548 })549 it('19) Testing performQuery() (year, state, county) with key in summaryMap', async () => {550 expect(_.isEmpty(summaryMap)).to.be.false551 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))552 const year = 2016553 const wsState = "NC"554 const wsCounty = 'MECKLENBURG'555 var query = {}556 query[YEAR] = year557 query[WORKSITE_STATE] = wsState558 query[WORKSITE_COUNTY] = wsCounty559 const req = { "body": query }560 const res = {}561 var jsonTest = new JsonTest(res, 200, query)562 res.status = (val) => jsonTest.status(val)563 res.json = (h1bRecord) => jsonTest.json(h1bRecord)564 await performQuery(req, res)565 })566 })567 describe('Test \'/h1bWsState\'', () => {568 beforeEach(async() => {569 summaryMap = await readSummarizedQueries()570 logger.trace(`summaryMap: ${JSON.stringify(summaryMap, undefined, 2)}`)571 log4js.configure({572 // appenders: { h1bData: { type: 'file', filename: 'h1bData.log' } },573 appenders: { h1bData: { type: 'console'} },574 categories: { default: { appenders: ['h1bData'], level: 'warn' } }575 });576 })577 afterEach(() => {578 log4js.configure({579 // appenders: { h1bData: { type: 'file', filename: 'h1bData.log' } },580 appenders: { h1bData: { type: 'console'} },581 categories: { default: { appenders: ['h1bData'], level: 'info' } }582 });583 sinon.restore()584 })585 it('1) Testing \'/h1bWsState\' without key in summaryMap', async () => {586 summaryMap = {}587 expect(_.isEmpty(summaryMap)).to.be.true588 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))589 const year = 2017590 const wsState = "ID"591 var query = {}592 query[YEAR] = year593 query[WORKSITE_STATE] = wsState594 await request(app).get('/h1bWsState').send(query).expect(200)595 })596 it('2) Testing \'/h1bWsState\' with no state', async () => {597 summaryMap = {}598 expect(_.isEmpty(summaryMap)).to.be.true599 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))600 const year = 2017601 var query = {}602 query[YEAR] = year603 await request(app).get('/h1bWsState').send(query).expect(500)604 })605 it('3) Testing \'/h1bWsState\' with empty state', async () => {606 summaryMap = {}607 expect(_.isEmpty(summaryMap)).to.be.true608 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))609 const year = 2017610 const wsState = ""611 var query = {}612 query[YEAR] = year613 query[WORKSITE_STATE] = wsState614 await request(app).get('/h1bWsState').send(query).expect(500)615 })616 it('4) Testing \'/h1bWsState\' with undefined summaryMap', async () => {617 summaryMap = undefined618 expect(_.isEmpty(summaryMap)).to.be.true619 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))620 const year = 2017621 const wsState = "WY"622 var query = {}623 query[YEAR] = year624 query[WORKSITE_STATE] = wsState625 await request(app).get('/h1bWsState').send(query).expect(200)626 })627 it('5) Testing \'/h1bWsState\' with key in summaryMap', async () => {628 expect(_.isEmpty(summaryMap)).to.be.false629 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))630 const year = 2017631 const wsState = "AK"632 var query = {}633 query[YEAR] = year634 query[WORKSITE_STATE] = wsState635 await request(app).get('/h1bWsState').send(query).expect(200)636 })637 it('6) Testing \'/h1bWsState\' with invalid year', async () => {638 expect(_.isEmpty(summaryMap)).to.be.false639 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))640 const year = 2009641 const wsState = "WY"642 var query = {}643 query[YEAR] = year644 query[WORKSITE_STATE] = wsState645 await request(app).get('/h1bWsState').send(query).expect(500)646 })647 })648 describe('Test \'/h1bWsCd\'', () => {649 beforeEach(async() => {650 summaryMap = await readSummarizedQueries()651 logger.trace(`summaryMap: ${JSON.stringify(summaryMap, undefined, 2)}`)652 log4js.configure({653 // appenders: { h1bData: { type: 'file', filename: 'h1bData.log' } },654 appenders: { h1bData: { type: 'console'} },655 categories: { default: { appenders: ['h1bData'], level: 'warn' } }656 });657 })658 afterEach(() => {659 log4js.configure({660 // appenders: { h1bData: { type: 'file', filename: 'h1bData.log' } },661 appenders: { h1bData: { type: 'console'} },662 categories: { default: { appenders: ['h1bData'], level: 'info' } }663 });664 sinon.restore()665 })666 it('1) Testing \'/h1bWsCd\' without key in summaryMap', async () => {667 summaryMap = {}668 expect(_.isEmpty(summaryMap)).to.be.true669 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))670 const year = 2017671 const wsState = "FL"672 const wsCongressDist = 21673 var query = {}674 query[YEAR] = year675 query[WORKSITE_STATE] = wsState676 query[WORKSITE_CONGRESS_DISTRICT] = wsCongressDist677 await request(app).get('/h1bWsState').send(query).expect(200)678 })679 it('2) Testing \'/h1bWsCd\' with no state', async () => {680 summaryMap = {}681 expect(_.isEmpty(summaryMap)).to.be.true682 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))683 const year = 2017684 const wsCongressDist = 21685 var query = {}686 query[YEAR] = year687 query[WORKSITE_CONGRESS_DISTRICT] = wsCongressDist688 await request(app).get('/h1bWsCd').send(query).expect(500)689 })690 it('3) Testing \'/h1bWsCd\' with no congressional district', async () => {691 summaryMap = {}692 expect(_.isEmpty(summaryMap)).to.be.true693 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))694 const year = 2017695 const wsState = "GA"696 var query = {}697 query[YEAR] = year698 query[WORKSITE_STATE] = wsState699 await request(app).get('/h1bWsCd').send(query).expect(500)700 })701 it('4) Testing \'/h1bWsCd\' with empty state', async () => {702 summaryMap = {}703 expect(_.isEmpty(summaryMap)).to.be.true704 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))705 const year = 2017706 const wsState = ""707 var query = {}708 query[YEAR] = year709 query[WORKSITE_STATE] = wsState710 await request(app).get('/h1bWsCd').send(query).expect(500)711 })712 it('5) Testing \'/h1bWsCd\' with congress district as char string', async () => {713 summaryMap = {}714 expect(_.isEmpty(summaryMap)).to.be.true715 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))716 const year = 2017717 const wsState = "FL"718 const wsCongressDist = "2"719 var query = {}720 query[YEAR] = year721 query[WORKSITE_STATE] = wsState722 query[WORKSITE_CONGRESS_DISTRICT] = wsCongressDist723 await request(app).get('/h1bWsCd').send(query).expect(500)724 })725 it('6) Testing \'/h1bWsCd\' with congress district as object', async () => {726 summaryMap = {}727 expect(_.isEmpty(summaryMap)).to.be.true728 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))729 const year = 2017730 const wsState = "FL"731 const wsCongressDist = {"id":"2"}732 var query = {}733 query[YEAR] = year734 query[WORKSITE_STATE] = wsState735 query[WORKSITE_CONGRESS_DISTRICT] = wsCongressDist736 await request(app).get('/h1bWsCd').send(query).expect(500)737 })738 it('7) Testing \'/h1bWsCd\' with congress district as array', async () => {739 summaryMap = {}740 expect(_.isEmpty(summaryMap)).to.be.true741 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))742 const year = 2017743 const wsState = "FL"744 const wsCongressDist = [2]745 var query = {}746 query[YEAR] = year747 query[WORKSITE_STATE] = wsState748 query[WORKSITE_CONGRESS_DISTRICT] = wsCongressDist749 await request(app).get('/h1bWsCd').send(query).expect(500)750 })751 it('8) Testing \'/h1bWsCd\' with undefined summaryMap', async () => {752 summaryMap = undefined753 expect(_.isEmpty(summaryMap)).to.be.true754 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))755 const year = 2017756 const wsState = "FL"757 const wsCongressDist = 2758 var query = {}759 query[YEAR] = year760 query[WORKSITE_STATE] = wsState761 query[WORKSITE_CONGRESS_DISTRICT] = wsCongressDist762 await request(app).get('/h1bWsCd').send(query).expect(200)763 })764 it('9) Testing \'/h1bWsCd\' with key in summaryMap', async () => {765 expect(_.isEmpty(summaryMap)).to.be.false766 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))767 const year = 2017768 const wsState = "AK"769 const wsCongressDist = 1770 var query = {}771 query[YEAR] = year772 query[WORKSITE_STATE] = wsState773 query[WORKSITE_CONGRESS_DISTRICT] = wsCongressDist774 await request(app).get('/h1bWsCd').send(query).expect(200)775 })776 it('10) Testing \'/h1bWsCd\' with invalid year', async () => {777 expect(_.isEmpty(summaryMap)).to.be.false778 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))779 const year = 2009780 const wsState = "WY"781 const wsCongressDist = 1782 var query = {}783 query[YEAR] = year784 query[WORKSITE_STATE] = wsState785 query[WORKSITE_CONGRESS_DISTRICT] = wsCongressDist786 await request(app).get('/h1bWsCd').send(query).expect(500)787 })788 })789 describe('Test \'/h1bSummary\'', () => {790 beforeEach(async() => {791 summaryMap = await readSummarizedQueries()792 logger.trace(`summaryMap: ${JSON.stringify(summaryMap, undefined, 2)}`)793 log4js.configure({794 // appenders: { h1bData: { type: 'file', filename: 'h1bData.log' } },795 appenders: { h1bData: { type: 'console'} },796 categories: { default: { appenders: ['h1bData'], level: 'warn' } }797 });798 })799 afterEach(() => {800 log4js.configure({801 // appenders: { h1bData: { type: 'file', filename: 'h1bData.log' } },802 appenders: { h1bData: { type: 'console'} },803 categories: { default: { appenders: ['h1bData'], level: 'info' } }804 });805 sinon.restore()806 })807 it('1) Testing \'/h1bSummary\' (year, state) without key in summaryMap', async () => {808 summaryMap = {}809 expect(_.isEmpty(summaryMap)).to.be.true810 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))811 const year = 2016812 const wsState = "ID"813 var query = {}814 query[YEAR] = year815 query[WORKSITE_STATE] = wsState816 const response = await request(app).get('/h1bSummary').send(query).expect(200)817 const respObj = JSON.parse(response.text)818 expect(1215).to.be.equal(respObj[TOTAL_WORKERS])819 expect(765).to.be.equal(respObj[TOTAL_LCAS])820 })821 it('2) Testing \'/h1bSummary\' (year, state) with undefined summaryMap', async () => {822 summaryMap = undefined823 expect(_.isEmpty(summaryMap)).to.be.true824 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))825 const year = 2017826 const wsState = "WY"827 var query = {}828 query[YEAR] = year829 query[WORKSITE_STATE] = wsState830 const response = await request(app).get('/h1bSummary').send(query).expect(200)831 const respObj = JSON.parse(response.text)832 expect(170).to.be.equal(respObj[TOTAL_WORKERS])833 expect(113).to.be.equal(respObj[TOTAL_LCAS])834 })835 it('3) Testing \'/h1bSummary\' (year, state) with key in summaryMap', async () => {836 expect(_.isEmpty(summaryMap)).to.be.false837 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))838 const year = 2016839 const wsState = "AK"840 var query = {}841 query[YEAR] = year842 query[WORKSITE_STATE] = wsState843 const response = await request(app).get('/h1bSummary').send(query).expect(200)844 const respObj = JSON.parse(response.text)845 expect(329).to.be.equal(respObj[TOTAL_WORKERS])846 expect(154).to.be.equal(respObj[TOTAL_LCAS])847 })848 it('4) Testing \'/h1bSummary\' (year, state) with invalid year', async () => {849 expect(_.isEmpty(summaryMap)).to.be.false850 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))851 const year = 2007852 const wsState = "WY"853 var query = {}854 query[YEAR] = year855 query[WORKSITE_STATE] = wsState856 const response = await request(app).get('/h1bSummary').send(query).expect(500)857 expect(h1bRecordRouter.INVALID_YEAR).to.be.equal(response.text)858 logger.trace(chalk.bgRed.white.bold(`response: ${JSON.stringify(response)}`))859 })860 it('5) Testing \'/h1bSummary\' (year, employerName) without key in summaryMap', async () => {861 summaryMap = {}862 expect(_.isEmpty(summaryMap)).to.be.true863 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))864 const year = 2016865 const empName = "DELOITTE CONSULTING LLP"866 var query = {}867 query[YEAR] = year868 query[EMPLOYER_NAME] = empName869 const response = await request(app).get('/h1bSummary').send(query).expect(200)870 const respObj = JSON.parse(response.text)871 expect(122189).to.be.equal(respObj[TOTAL_WORKERS])872 expect(7500).to.be.equal(respObj[TOTAL_LCAS])873 })874 it('6) Testing \'/h1bSummary\' (year, employerName) with undefined summaryMap', async () => {875 summaryMap = undefined876 expect(_.isEmpty(summaryMap)).to.be.true877 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))878 const year = 2017879 const empName = "COGNIZANT TECHNOLOGY SOLUTIONS U.S. CORPORATION"880 var query = {}881 query[YEAR] = year882 query[EMPLOYER_NAME] = empName883 const response = await request(app).get('/h1bSummary').send(query).expect(200)884 const respObj = JSON.parse(response.text)885 expect(50755).to.be.equal(respObj[TOTAL_WORKERS])886 expect(2364).to.be.equal(respObj[TOTAL_LCAS])887 })888 it('7) Testing \'/h1bSummary\' (year, employerName) with key in summaryMap', async () => {889 expect(_.isEmpty(summaryMap)).to.be.false890 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))891 const year = 2016892 const empName = "ORACLE AMERICA, INC."893 var query = {}894 query[YEAR] = year895 query[EMPLOYER_NAME] = empName896 const response = await request(app).get('/h1bSummary').send(query).expect(200)897 const respObj = JSON.parse(response.text)898 expect(7307).to.be.equal(respObj[TOTAL_WORKERS])899 expect(799).to.be.equal(respObj[TOTAL_LCAS])900 })901 it('8) Testing \'/h1bSummary\' (year, employerName) with invalid year', async () => {902 expect(_.isEmpty(summaryMap)).to.be.false903 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))904 const year = 2007905 const empName = "ERNST & YOUNG U.S. LLP"906 var query = {}907 query[YEAR] = year908 query[EMPLOYER_NAME] = empName909 const response = await request(app).get('/h1bSummary').send(query).expect(500)910 logger.trace(chalk.bgRed.white.bold(`response: ${JSON.stringify(response.text)}`))911 expect(h1bRecordRouter.INVALID_YEAR).to.be.equal(response.text)912 })913 it('9) Testing \'/h1bSummary\' (year, caseNumbers) with valid year', async () => {914 const year = 2017915 const caseNumbers = ["I-200-16293-304765", "I-200-16287-943040", "I-200-16305-330106"]916 var query = {}917 query[YEAR] = year918 query[CASE_NUMBER] = caseNumbers919 const response = await request(app).get('/h1bSummary').send(query).expect(200)920 const respObj = JSON.parse(response.text)921 expect(8).to.be.equal(respObj[TOTAL_WORKERS])922 expect(3).to.be.equal(respObj[TOTAL_LCAS])923 })924 })925 describe('Test \'/h1bCount\'', () => {926 beforeEach(async() => {927 summaryMap = await readSummarizedQueries()928 logger.trace(`summaryMap: ${JSON.stringify(summaryMap, undefined, 2)}`)929 log4js.configure({930 // appenders: { h1bData: { type: 'file', filename: 'h1bData.log' } },931 appenders: { h1bData: { type: 'console'} },932 categories: { default: { appenders: ['h1bData'], level: 'warn' } }933 });934 })935 afterEach(() => {936 log4js.configure({937 // appenders: { h1bData: { type: 'file', filename: 'h1bData.log' } },938 appenders: { h1bData: { type: 'console'} },939 categories: { default: { appenders: ['h1bData'], level: 'info' } }940 });941 sinon.restore()942 })943 it('1) Testing \'/h1bCount\' (year, state)', async () => {944 summaryMap = {}945 expect(_.isEmpty(summaryMap)).to.be.true946 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))947 const year = 2016948 const wsState = "ID"949 var query = {}950 query[YEAR] = year951 query[WORKSITE_STATE] = wsState952 await request(app).get('/h1bCount').send(query).expect(200)953 })954 it('2) Testing \'/h1bCount\' (year, county)', async () => {955 summaryMap = {}956 expect(_.isEmpty(summaryMap)).to.be.true957 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))958 const year = 2016959 const wsCounty = "WAKE"960 var query = {}961 query[YEAR] = year962 query[WORKSITE_COUNTY] = wsCounty963 await request(app).get('/h1bCount').send(query).expect(200)964 })965 it('3) Testing \'/h1bCount\' (year, state); invalid year', async () => {966 summaryMap = {}967 expect(_.isEmpty(summaryMap)).to.be.true968 logger.trace(chalk.bgRed.white.bold(`summaryMap: ${JSON.stringify(summaryMap)}`))969 const year = 2006970 const wsState = "ID"971 var query = {}972 query[YEAR] = year973 query[WORKSITE_STATE] = wsState974 await request(app).get('/h1bCount').send(query).expect(500)975 })976 })977 describe('Test createCaseNumberQueryArray()', () => {978 // It appears that I do not need this routine. I am leaving it because I may need979 // it at a later date.980 const goodStringArray = ['String 1', 'String 2', 'String 3']981 const goodStringArrayTranslated = { $or: [{ CASE_NUMBER: goodStringArray[0]},982 { CASE_NUMBER: goodStringArray[1]},983 { CASE_NUMBER: goodStringArray[2]}984 ]}985 const badStringArray = ['String 1', 55]986 beforeEach(async() => {987 logger.trace(`summaryMap: ${JSON.stringify(summaryMap, undefined, 2)}`)988 log4js.configure({989 // appenders: { h1bData: { type: 'file', filename: 'h1bData.log' } },990 appenders: { h1bData: { type: 'console'} },991 categories: { default: { appenders: ['h1bData'], level: 'warn' } }992 });993 })994 afterEach(() => {995 log4js.configure({996 // appenders: { h1bData: { type: 'file', filename: 'h1bData.log' } },997 appenders: { h1bData: { type: 'console'} },998 categories: { default: { appenders: ['h1bData'], level: 'info' } }999 });1000 sinon.restore()1001 })1002 it('1) Testing createCaseNumberQueryArray with good array of strings', () => {1003 logger.trace(chalk.bgRed.white.bold1004 (`good: ${JSON.stringify(createCaseNumberQueryArray(goodStringArray), undefined, 2)}`))1005 logger.trace(chalk.bgRed.white.bold1006 (`expected: ${JSON.stringify(goodStringArrayTranslated, undefined, 2)}`))1007 expect(goodStringArrayTranslated).to.deep.equal(createCaseNumberQueryArray(goodStringArray))1008 })1009 it('2) Testing createCaseNumberQueryArray with a good single string', () => {1010 const singleString = "singleString"1011 expect(singleString).to.equal(createCaseNumberQueryArray(singleString))1012 })1013 it('3) Testing createCaseNumberQueryArray with bad array of strings', () => {1014 try{1015 const badValue = createCaseNumberQueryArray(badStringArray)1016 expect(false).to.be.true1017 }catch(e){1018 logger.trace(chalk.bgRed.white.bold(`e: ${JSON.stringify(e, undefined, 2)}`))1019 expect(e).to.be.equal(`${h1bRecordRouter.INVALID_CASE_NUMBER}55`)1020 }1021 }) 1022 it('4) Testing createCaseNumberQueryArray with a number', () => {1023 try{1024 const badValue = createCaseNumberQueryArray(55)1025 expect(false).to.be.true1026 }catch(e){1027 logger.trace(chalk.bgRed.white.bold(`e: ${JSON.stringify(e, undefined, 2)}`))1028 expect(e).to.be.equal(`${h1bRecordRouter.INVALID_CASE_NUMBER}55`)1029 }1030 }) 1031 it('5) Testing createCaseNumberQueryArray with an object', () => {1032 try{1033 const badValue = createCaseNumberQueryArray({})1034 expect(false).to.be.true1035 }catch(e){1036 logger.trace(chalk.bgRed.white.bold(`e: ${JSON.stringify(e, undefined, 2)}`))1037 expect(e).to.be.equal(`${h1bRecordRouter.INVALID_CASE_NUMBER}\{\}`)1038 }1039 }) 1040 })1041 describe('Test \'/h1bCaseNumber\'', () => {1042 beforeEach(async() => {1043 log4js.configure({1044 // appenders: { h1bData: { type: 'file', filename: 'h1bData.log' } },1045 appenders: { h1bData: { type: 'console'} },1046 categories: { default: { appenders: ['h1bData'], level: 'warn' } }1047 });1048 })1049 afterEach(() => {1050 log4js.configure({1051 // appenders: { h1bData: { type: 'file', filename: 'h1bData.log' } },1052 appenders: { h1bData: { type: 'console'} },1053 categories: { default: { appenders: ['h1bData'], level: 'info' } }1054 });1055 sinon.restore()1056 })1057 it('1) Testing \'/h1bCaseNumber\' with single Case Number', async() => {1058 const year = 20171059 var query = {}1060 query[YEAR] = year1061 query[CASE_NUMBER] = "I-200-16274-852162"1062 const response = await request(app).get('/h1bCaseNumber').send(query).expect(200)1063 const respObj = JSON.parse(response.text)1064 logger.trace(`respObj: ${JSON.stringify(respObj, undefined, 2)}`)1065 expect(!_.isEmpty(respObj)).to.be.true1066 expect(_.isArray(respObj)).to.be.true1067 expect(1).to.be.equal(respObj.length)1068 const lca = respObj[0]1069 expect('HOME DEPOT USA, INC.').to.be.equal(lca[EMPLOYER_NAME])1070 })1071 it('2) Testing \'/h1bCaseNumber\' with an array of one Case Number', async() => {1072 const year = 20171073 var query = {}1074 query[YEAR] = year1075 query[CASE_NUMBER] = ["I-200-16307-654309"]1076 const response = await request(app).get('/h1bCaseNumber').send(query).expect(200)1077 const respObj = JSON.parse(response.text)1078 logger.trace(`respObj: ${JSON.stringify(respObj, undefined, 2)}`)1079 expect(!_.isEmpty(respObj)).to.be.true1080 expect(_.isArray(respObj)).to.be.true1081 expect(1).to.be.equal(respObj.length)1082 const lca = respObj[0]1083 expect('PROGRAMMER ANALYST').to.be.equal(lca[JOB_TITLE])1084 expect('SYNTEL INC').to.be.equal(lca[EMPLOYER_NAME])1085 })1086 it('3) Testing \'/h1bCaseNumber\' with an array of three Case Numbers', async() => {1087 const year = 20171088 var query = {}1089 query[YEAR] = year1090 query[CASE_NUMBER] = ["I-200-16293-304765", "I-200-16287-943040", "I-200-16305-330106"]1091 const response = await request(app).get('/h1bCaseNumber').send(query).expect(200)1092 const respObj = JSON.parse(response.text)1093 logger.trace(`respObj: ${JSON.stringify(respObj, undefined, 2)}`)1094 expect(!_.isEmpty(respObj)).to.be.true1095 expect(_.isArray(respObj)).to.be.true1096 expect(3).to.be.equal(respObj.length)1097 var lcas = respObj.sort((a, b) => (a[CASE_NUMBER] > b[CASE_NUMBER]) ? 1 : -1)1098 logger.trace(`lcas: ${JSON.stringify(lcas, undefined, 2)}`)1099 expect("I-200-16287-943040").to.be.equal(lcas[0][CASE_NUMBER])1100 expect("I-200-16293-304765").to.be.equal(lcas[1][CASE_NUMBER])1101 expect("I-200-16305-330106").to.be.equal(lcas[2][CASE_NUMBER])1102 var lca = respObj[0]1103 expect('ARCHITECT').to.be.equal(lca[JOB_TITLE])1104 expect(1).to.be.equal(lca[TOTAL_WORKERS])1105 expect(LEVEL_2).to.be.equal(lca[WAGE_LEVEL])1106 var lca = respObj[1]1107 expect('SENIOR SOFTWARE DEVELOPER').to.be.equal(lca[JOB_TITLE])1108 expect(6).to.be.equal(lca[TOTAL_WORKERS])1109 expect(LEVEL_3).to.be.equal(lca[WAGE_LEVEL])1110 var lca = respObj[2]1111 expect('ANALYST').to.be.equal(lca[JOB_TITLE])1112 expect('TATA CONSULTANCY SERVICES LIMITED').to.be.equal(lca[EMPLOYER_NAME])1113 expect(1).to.be.equal(lca[TOTAL_WORKERS])1114 expect(LEVEL_2).to.be.equal(lca[WAGE_LEVEL])1115 })1116 it('4) Testing \'/h1bCaseNumber\' with invalid year', async() => {1117 const year = 20011118 var query = {}1119 query[YEAR] = year1120 query[CASE_NUMBER] = ["I-200-16307-654309"]1121 const response = await request(app).get('/h1bCaseNumber').send(query).expect(500)1122 })1123 })...
json_attributes-test.js
Source:json_attributes-test.js
1var should = require('should')2var path = require('path')3var Store = require('../../../store/postgres')4describe('Postgres: Json/Jsonb Attributes', function() {5 var store6 var database = 'json_attributes_test'7 before(function(next) {8 this.timeout(5000)9 beforePG(database, [], next)10 })11 before(function() {12 store = new Store({13 host: 'localhost',14 type: 'postgres',15 database: database,16 user: 'postgres',17 password: '',18 migrations: path.join(__dirname, 'fixtures', 'migrations', '*'),19 plugins: require('../../../lib/base/dynamic_loading')20 })21 store.Model('JsonTest', function() {})22 })23 after(function(next) {24 afterPG(database, next)25 })26 it('writes and ready json data', function() {27 return store.ready(function() {28 var JsonTest = store.Model('JsonTest')29 var test = new JsonTest({ json_attr: { foo: { bar: [1, 2, 3] } } })30 return test.save().then(function() {31 return JsonTest.find(test.id).exec(function(t) {32 t.json_attr.should.be.eql({ foo: { bar: [1, 2, 3] } })33 })34 })35 })36 })37 it('writes and ready jsonb data', function() {38 return store.ready(function() {39 var JsonTest = store.Model('JsonTest')40 var test = new JsonTest({ jsonb_attr: { foo: { bar: [1, 2, 3] } } })41 return test.save().then(function() {42 return JsonTest.find(test.id).exec(function(t) {43 t.jsonb_attr.should.be.eql({ foo: { bar: [1, 2, 3] } })44 })45 })46 })47 })48 it('updates json data', function() {49 return store.ready(function() {50 var JsonTest = store.Model('JsonTest')51 return JsonTest.find(1).exec(function(test) {52 test.json_attr.foo.bar.push(4)53 test.json_attr.bar = 'test'54 return test.save().then(function() {55 return JsonTest.find(test.id).exec(function(t) {56 t.json_attr.should.be.eql({57 foo: { bar: [1, 2, 3, 4] },58 bar: 'test'59 })60 })61 })62 })63 })64 })65 it('sort by json attribute', function() {66 return store.ready(function() {67 var JsonTest = store.Model('JsonTest')68 var test = new JsonTest({ json_attr: { bar: 'foo' } })69 return test.save().then(function() {70 return JsonTest.order('json_attr.bar').exec(function(result) {71 result[0].json_attr.bar.should.be.equal('foo')72 result[1].json_attr.bar.should.be.equal('test')73 should.not.exist(result[2].json_attr.bar)74 result.length.should.be.equal(3)75 })76 })77 })78 })79 it('condition with json attribute', function() {80 return store.ready(function() {81 var JsonTest = store.Model('JsonTest')82 return JsonTest.where({ json_attr: { bar: 'test' } }).exec(function(83 result84 ) {85 result[0].json_attr.bar.should.be.equal('test')86 result.length.should.be.equal(1)87 })88 })89 })90 it('updates json data (root)', function() {91 return store.ready(function() {92 var JsonTest = store.Model('JsonTest')93 return JsonTest.find(1).exec(function(test) {94 test.json_attr = [{ a: 1, b: 2 }, { b: 2 }]95 return test.save().then(function() {96 return JsonTest.find(test.id).exec(function(t) {97 t.json_attr.should.be.eql([{ a: 1, b: 2 }, { b: 2 }])98 })99 })100 })101 })102 })...
displayQuestions.js
Source:displayQuestions.js
1/**2 * Created by paulo on 06/11/15.3 */4$(document).ready(function(){ exibe()})5function exibe(){6 var nudeTest = $('.inputQ').text();7 var jsonTest = JSON.parse(nudeTest);8 $(".visualizacao").append(jsonTest.name+"<br>");9 for (var i = 0; i < jsonTest.test.length; i++){10 if (jsonTest.test[i].tipo == "objetiva"){11 var retorno = jsonTest.test[i].enunciado;12 $(".visualizacao").append(retorno+"<br>");13 var numDeAlternativas = jsonTest.test[i].resposta.length;14 for (var y = 0; y < numDeAlternativas; y++){15 $(".visualizacao").append(jsonTest.test[i].resposta[y].txt+"<br>");16 $(".visualizacao").append(jsonTest.test[i].resposta[y].alt+"<br>");17 }18 }else{19 var retorno = jsonTest.test[i].enunciado;20 $(".visualizacao").append(retorno+"<br>");21 }22 }...
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3};4var test = new wpt('www.webpagetest.org', options);5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11{ [Error: connect ECONNREFUSED] code: 'ECONNREFUSED', errno: 'ECONNREFUSED', syscall: 'connect' }12var wpt = require('webpagetest');13var options = {14};15var test = new wpt('www.webpagetest.org', options);16 if (err) {17 console.log(err);18 } else {19 console.log(data);20 }21});22{ [Error: connect ECONNREFUSED] code: 'ECONNREFUSED', errno: 'ECONNREFUSED', syscall: 'connect' }23var wpt = require('webpagetest');24var options = {25};26var test = new wpt('www.webpagetest.org', options);27 if (err) {
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3 console.log(data);4});5var wpt = require('wpt');6var wpt = new WebPageTest('www.webpagetest.org');7 console.log(data);8});9var wpt = require('wpt');10var wpt = new WebPageTest('www.webpagetest.org');11 console.log(data);12});13var wpt = require('wpt');14var wpt = new WebPageTest('www.webpagetest.org');15 console.log(data);16});17var wpt = require('wpt');18var wpt = new WebPageTest('www.webpagetest.org');19 console.log(data);20});21var wpt = require('wpt');22var wpt = new WebPageTest('www.webpagetest.org');23 console.log(data);24});25var wpt = require('wpt');26var wpt = new WebPageTest('www.webpagetest.org');27 console.log(data);28});29var wpt = require('wpt');30var wpt = new WebPageTest('www.webpagetest.org');
Using AI Code Generation
1var wpt = require('webpagetest');2var test = new wpt('www.webpagetest.org');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpt = require('webpagetest');10var test = new wpt('www.webpagetest.org');11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var wpt = require('webpagetest');18var test = new wpt('www.webpagetest.org');19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var wpt = require('webpagetest');26var test = new wpt('www.webpagetest.org');27 if (err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var wpt = require('webpagetest');34var test = new wpt('www.webpagetest.org');35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});41var wpt = require('webpagetest');42var test = new wpt('www.webpagetest.org');
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('Barack_Obama');3page.json(function(err, info) {4 console.log(info);5});6var wptools = require('wptools');7var page = wptools.page('Barack_Obama');8page.get(function(err, info) {9 console.log(info);10});11var wptools = require('wptools');12var page = wptools.page('Barack_Obama');13page.get(function(err, info) {14 console.log(info);15});16var wptools = require('wptools');17var page = wptools.page('Barack_Obama');18page.get(function(err, info) {19 console.log(info);20});21var wptools = require('wptools');22var page = wptools.page('Barack_Obama');23page.get(function(err, info) {24 console.log(info);25});26var wptools = require('wptools');27var page = wptools.page('Barack_Obama');28page.get(function(err, info) {29 console.log(info);30});31var wptools = require('wptools');32var page = wptools.page('Barack_Obama');33page.get(function(err, info) {34 console.log(info);35});36var wptools = require('wptools');37var page = wptools.page('Barack_Obama');38page.get(function(err, info) {39 console.log(info);40});41var wptools = require('wptools');42var page = wptools.page('Barack_Obama');43page.get(function(err, info) {44 console.log(info);45});
Using AI Code Generation
1var wptool = require('wptool');2var json = wptool.JSONtest();3console.log(json);4var wptool = require('wptool');5var json = wptool.JSONtest();6console.log(json);7var wptool = require('wptool');8var json = wptool.JSONtest();9console.log(json);10var wptool = require('wptool');11var json = wptool.JSONtest();12console.log(json);13var wptool = require('wptool');14var json = wptool.JSONtest();15console.log(json);16var wptool = require('wptool');17var json = wptool.JSONtest();18console.log(json);19var wptool = require('wptool');20var json = wptool.JSONtest();21console.log(json);22var wptool = require('wptool');23var json = wptool.JSONtest();24console.log(json);25var wptool = require('wptool');26var json = wptool.JSONtest();27console.log(json);28var wptool = require('wptool');29var json = wptool.JSONtest();30console.log(json);31var wptool = require('wptool');32var json = wptool.JSONtest();33console.log(json);34var wptool = require('wptool');35var json = wptool.JSONtest();36console.log(json);37var wptool = require('wptool');38var json = wptool.JSONtest();39console.log(json);
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!!