Last active
January 24, 2020 11:41
-
-
Save circa10a/82029f4c24c904c19cc37cb332939e14 to your computer and use it in GitHub Desktop.
medium mocha and chai test example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const { expect } = require('chai'); | |
const soapRequest = require('../index'); | |
const url = 'https://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php'; | |
const urlFail = 'https://graphical.weather.gov:80/xml/SOAP_server/ndfdXMLserver.php'; | |
const headers = { | |
'user-agent': 'easy-soap-request-test', | |
'Content-Type': 'text/xml;charset=UTF-8', | |
SOAPAction: 'https://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl#LatLonListZipCode', | |
}; | |
const xml = fs.readFileSync('test/zip-code-envelope.xml', 'utf-8'); | |
const xmlFail = fs.readFileSync('test/zip-code-envelope-fail.xml', 'utf-8'); | |
describe('Test Longitude/Latitude SOAP Request', () => { | |
const coordinates = '32.9612,-96.8372'; | |
it(`Zip Code 75001 should return ${coordinates}`, async () => { | |
const { response } = await soapRequest({ url, headers, xml }); | |
const { body, statusCode } = response; | |
expect(body).to.include(coordinates); | |
expect(statusCode).to.be.equal(200); | |
}); | |
it('Should catch Promise Rejection', async () => { | |
try { | |
const { response } = await soapRequest({ url, headers, xmlFail }); | |
const { statusCode } = response; | |
expect(statusCode).to.not.be.equal(200); | |
} catch (e) { | |
// Test promise rejection for coverage | |
} | |
}); | |
it('Should catch connection error Promise Rejection', async () => { | |
try { | |
const { response } = await soapRequest({ | |
url: urlFail, | |
headers, | |
xml: xmlFail, | |
timeout: 1000, | |
}); | |
const { statusCode } = response; | |
expect(statusCode).to.not.be.equal(200); | |
} catch (e) { | |
// Test promise rejection for coverage | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment