UNPKG

soap-node-decoder

Version:

A simple package to get the content of a SOAP response node.

70 lines (56 loc) 2.03 kB
const decodeSoapNode = require('../decodeSoapNode'); /** * Test data using the soap format soap:Envelope, soap:Body */ const fakeSoapResponse = `<?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope/" soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding"> <soap:Body> <m:GetPriceResponse xmlns:m="https://www.w3schools.com/prices"> <m:Price>1.90</m:Price> </m:GetPriceResponse> </soap:Body> </soap:Envelope>` /** * Test data using the soap format SOAP-ENV:Envelope, SOAP-ENV:Body */ const fakeSoapResponse2 = `<?xml version = "1.0"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV = "http://www.w3.org/2001/12/soap-envelope" SOAP-ENV:encodingStyle = "http://www.w3.org/2001/12/soap-encoding"> <SOAP-ENV:Body xmlns:m = "http://www.xyz.org/quotations"> <m:GetQuotation> <m:QuotationsName>MiscroSoft</m:QuotationsName> </m:GetQuotation> </SOAP-ENV:Body> </SOAP-ENV:Envelope>`; /** * Test for all formats */ test('decodeNode should return null if the given node is null', () => { expect(decodeSoapNode(null, fakeSoapResponse2)).toBe(null); }); test('decodeNode should return null if the given node is undefined', () => { expect(decodeSoapNode(undefined, fakeSoapResponse2)).toBe(null); }); test('decodeNode should return null if the given soap response is null', () => { expect(decodeSoapNode('Price', null)).toBe(null); }); /** * Test data using the soap format SOAP-ENV:Envelope, SOAP-ENV:Body */ test('decodeNode should return the value of the node Price', () => { expect(decodeSoapNode('Price', fakeSoapResponse)).toBe('1.90'); }); test('decodeNode should return null if the node does not exist', () => { expect(decodeSoapNode('GetPrice', fakeSoapResponse)).toBe(null); }); /** * Test data using the soap format SOAP-ENV:Envelope, SOAP-ENV:Body */ test('decodeNode should return the value of the node QuotationsName', () => { expect(decodeSoapNode('QuotationsName', fakeSoapResponse2)).toBe('MiscroSoft'); });