Skip to content

Instantly share code, notes, and snippets.

@JosephShering
Created November 1, 2017 23:56
Show Gist options
  • Save JosephShering/04a7499288d82593172f52339eb1938a to your computer and use it in GitHub Desktop.
Save JosephShering/04a7499288d82593172f52339eb1938a to your computer and use it in GitHub Desktop.
const {
fetchResults,
createRequestBody,
submitLocations,
checkStatus,
parseXml,
getRequestID,
timeoutCheckStatus,
getStatus,
unzipResult
} = require('./../here')
const assert = require('assert')
const testJobs = [
{ id: '123flhweofih324', company: 'Hivelocity Hosting', cityState: 'Tampa FL' },
{ id: '123flhweofiqwww', company: 'Mad Mobile', cityState: 'Tampa FL' },
{ id: '123flhweofiqww2', company: 'Complete Technology Solutions', cityState: 'Spring Hill FL' },
];
describe('#createRequestBody()', () => {
it('should return a string of comma separated jobs', () => {
const testValue = `recId,searchText,country\n123flhweofih324,Hivelocity Hosting Tampa FL,USA`
const val = createRequestBody(testJobs)
assert.equal(testValue, val)
})
})
describe('#submitLocations', () => {
it('should submit the csv to the correct endpoint', (done) => {
const body = createRequestBody(testJobs)
submitLocations(body)
.then(parseXml)
.then(getRequestID)
.then(requestId => {
console.log(requestId)
assert(typeof requestId, 'String')
done()
})
.catch(err => {
assert.fail(err, '')
done()
})
})
})
describe('#checkStatus', () => {
it('should submit the csv and wait check it intervally until it\'s done', (done) => {
const body = createRequestBody(testJobs)
fetchResults('bqclfHTQguFlq5QS7dYGQq2yrrRrjE7v')
.then(unzipResult)
.then(result => {
console.log(result)
done()
})
.catch(err => {
assert.fail(err, '')
done()
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment