11import path , { dirname } from 'path'
22import _ from 'lodash'
33import moment from 'moment'
4- import request from 'request'
54import utils from 'util'
65import fs from 'fs-extra'
76import mongodb from 'mongodb'
@@ -66,9 +65,10 @@ describe('krawler:cli', () => {
6665 fs . removeSync ( path . join ( outputPath , 'RJTT-30-18000-2-1.tif.csv' ) )
6766 appServer = await cli ( jobfile , { mode : 'setup' , api : true , apiPrefix : '/api' , port : 3030 , messageTemplate : process . env . MESSAGE_TEMPLATE , debug : true , slackWebhook : process . env . SLACK_WEBHOOK_URL } )
6867 // Submit a job to be run
69- const response = await utils . promisify ( request . post ) ( {
70- url : 'http://localhost:3030/api/jobs' ,
71- body : {
68+ const response = await fetch ( 'http://localhost:3030/api/jobs' , {
69+ method : 'POST' ,
70+ headers : { 'content-type' : 'application/json' } ,
71+ body : JSON . stringify ( {
7272 id : 'job' ,
7373 store : 'job-store' ,
7474 tasks : [ {
@@ -78,10 +78,9 @@ describe('krawler:cli', () => {
7878 store : 'task-store'
7979 }
8080 } ]
81- } ,
82- json : true
81+ } )
8382 } )
84- const tasks = response . body
83+ const tasks = await response . json ( )
8584 await appServer . close ( )
8685 expect ( tasks . length ) . toBe ( 1 )
8786 // Check intermediate products have been erased and final product are here
@@ -134,10 +133,9 @@ describe('krawler:cli', () => {
134133 // Only run as we already setup the app
135134 await cli ( jobfile , { mode : 'runJob' , port : 3030 , cron : '*/10 * * * * *' , run : true , messageTemplate : process . env . MESSAGE_TEMPLATE , debug : false , slackWebhook : process . env . SLACK_WEBHOOK_URL } )
136135 expect ( runCount ) . toBe ( 1 ) // First run
137- const response = await utils . promisify ( request . get ) ( 'http://localhost:3030/healthcheck' )
138- // console.log(response.body)
139- expect ( response . statusCode ) . toBe ( 200 )
140- const healthcheck = JSON . parse ( response . body )
136+ const response = await fetch ( 'http://localhost:3030/healthcheck' )
137+ expect ( response . status ) . toBe ( 200 )
138+ const healthcheck = await response . json ( )
141139 // console.log(healthcheck)
142140 const { error } = await runCommand ( 'node ' + path . join ( __dirname , '..' , 'healthcheck.js' ) )
143141 expect ( error ) . toBeNull ( )
@@ -162,10 +160,9 @@ describe('krawler:cli', () => {
162160 await utils . promisify ( setTimeout ) ( ( 1 + remainingSecondsForNextRun ) * 1000 )
163161 try {
164162 expect ( runCount ) . toBeGreaterThanOrEqual ( 2 ) // 2 runs
165- const response = await utils . promisify ( request . get ) ( 'http://localhost:3030/healthcheck' )
166- // console.log(response.body)
167- expect ( response . statusCode ) . toBe ( 500 )
168- const healthcheck = JSON . parse ( response . body )
163+ const response = await fetch ( 'http://localhost:3030/healthcheck' )
164+ expect ( response . status ) . toBe ( 500 )
165+ const healthcheck = await response . json ( )
169166 // console.log(healthcheck)
170167 const { error } = await runCommand ( 'node ' + path . join ( __dirname , '..' , 'healthcheck.js' ) )
171168 expect ( error ) . toBeTruthy ( )
0 commit comments