6-mils
Version:
A JS library for sending, receiving, and parsing cXML messages.
144 lines (129 loc) • 6.99 kB
JavaScript
/* eslint-env mocha */
/**
* Code under test.
* @type {any}
*/
const T = require('./index.js')
describe('the "format-xml" module', function () {
it('must export a function', function () {
const expected = 'function'
const actual = typeof T
expect(actual).to.equal(expected)
})
describe('the exported function', function () {
it('must return an empty string if the input is undefined', function () {
const expected = ''
const actual = T()
expect(actual).to.equal(expected)
})
it('must return an empty string if the input is `null`', function () {
const expected = ''
const actual = T(null)
expect(actual).to.equal(expected)
})
it('must return an empty string if the input is blank', function () {
const expected = ''
const actual = T('')
expect(actual).to.equal(expected)
})
it('must properly format a valid cXML document with matching opening and closing tags', function () {
const expected = `
<cXML xml:lang="en-US" payloadID="933694607739" timestamp="2002-08-15T08:46:00-07:00">
<Response>
<Status code="200" text="success"></Status>
<PunchOutSetupResponse>
<StartPage>
<URL>http://xml.workchairs.com/retrieve?reqUrl=20626;Initial=TRUE</URL>
</StartPage>
</PunchOutSetupResponse>
</Response>
</cXML>`
const actual = T('<cXML xml:lang="en-US" payloadID="933694607739" timestamp="2002-08-15T08:46:00-07:00"><Response><Status code="200" text="success"></Status><PunchOutSetupResponse><StartPage><URL>http://xml.workchairs.com/retrieve?reqUrl=20626;Initial=TRUE</URL></StartPage></PunchOutSetupResponse></Response></cXML>')
expect(actual).to.equal(expected)
})
it('must properly format a valid cXML document with collapsed empty tags', function () {
const expected = `
<cXML xml:lang="en-US" payloadID="933694607739" timestamp="2002-08-15T08:46:00-07:00">
<Response>
<Status code="200" text="success"/>
<PunchOutSetupResponse>
<StartPage>
<URL>http://xml.workchairs.com/retrieve?reqUrl=20626;Initial=TRUE</URL>
</StartPage>
</PunchOutSetupResponse>
</Response>
</cXML>`
const actual = T('<cXML xml:lang="en-US" payloadID="933694607739" timestamp="2002-08-15T08:46:00-07:00"><Response><Status code="200" text="success"/><PunchOutSetupResponse><StartPage><URL>http://xml.workchairs.com/retrieve?reqUrl=20626;Initial=TRUE</URL></StartPage></PunchOutSetupResponse></Response></cXML>')
expect(actual).to.equal(expected)
})
it('must properly format a valid cXML document with many tags', function () {
const expected = `
<cXML payloadID="933695160894" timestamp="2002-08-15T08:47:00-07:00" xml:lang="en-US">
<Header>
<From>
<Credential domain="DUNS">
<Identity>83528721</Identity>
</Credential>
</From>
<To>
<Credential domain="DUNS">
<Identity>65652314</Identity>
</Credential>
</To>
<Sender>
<Credential domain="workchairs.com">
<Identity>website 1</Identity>
</Credential>
<UserAgent>Workchairs cXML Application</UserAgent>
</Sender>
</Header>
<Message>
<PunchOutOrderMessage>
<BuyerCookie>1CX3L4843PPZO</BuyerCookie>
<PunchOutOrderMessageHeader operationAllowed="edit">
<Total>
<Money currency="USD">763.20</Money>
</Total>
</PunchOutOrderMessageHeader>
<ItemIn quantity="1">
<ItemID>
<SupplierPartID>5555</SupplierPartID>
<SupplierPartAuxiliaryID>E000028901</SupplierPartAuxiliaryID>
</ItemID>
<ItemDetail>
<UnitPrice>
<Money currency="USD">254.40</Money>
</UnitPrice>
<Description xml:lang="en">
<ShortName>Excelsior Desk Chair</ShortName>Leather Reclining Desk Chair with Padded Arms</Description>
<UnitOfMeasure>EA</UnitOfMeasure>
<Classification domain="UNSPSC">5136030000</Classification>
<LeadTime>12</LeadTime>
</ItemDetail>
</ItemIn>
<ItemIn quantity="2">
<ItemID>
<SupplierPartID>5555</SupplierPartID>
<SupplierPartAuxiliaryID>E000028901</SupplierPartAuxiliaryID>
</ItemID>
<ItemDetail>
<UnitPrice>
<Money currency="USD">254.40</Money>
</UnitPrice>
<Description xml:lang="en">Leather Reclining Desk Chair with Padded Arms</Description>
<UnitOfMeasure>EA</UnitOfMeasure>
<Classification domain="UNSPSC">5136030000</Classification>
<LeadTime>12</LeadTime>
</ItemDetail>
</ItemIn>
</PunchOutOrderMessage>
</Message>
</cXML>`
const actual = T('<cXML payloadID="933695160894" timestamp="2002-08-15T08:47:00-07:00" xml:lang="en-US"><Header><From><Credential domain="DUNS"><Identity>83528721</Identity></Credential></From><To><Credential domain="DUNS"><Identity>65652314</Identity></Credential></To><Sender><Credential domain="workchairs.com"><Identity>website 1</Identity></Credential><UserAgent>Workchairs cXML Application</UserAgent></Sender></Header><Message><PunchOutOrderMessage><BuyerCookie>1CX3L4843PPZO</BuyerCookie><PunchOutOrderMessageHeader operationAllowed="edit"><Total><Money currency="USD">763.20</Money></Total></PunchOutOrderMessageHeader><ItemIn quantity="1"><ItemID><SupplierPartID>5555</SupplierPartID><SupplierPartAuxiliaryID>E000028901</SupplierPartAuxiliaryID></ItemID><ItemDetail><UnitPrice><Money currency="USD">254.40</Money></UnitPrice><Description xml:lang="en"><ShortName>Excelsior Desk Chair</ShortName>Leather Reclining Desk Chair with Padded Arms</Description><UnitOfMeasure>EA</UnitOfMeasure><Classification domain="UNSPSC">5136030000</Classification><LeadTime>12</LeadTime></ItemDetail></ItemIn><ItemIn quantity="2"><ItemID><SupplierPartID>5555</SupplierPartID><SupplierPartAuxiliaryID>E000028901</SupplierPartAuxiliaryID></ItemID><ItemDetail><UnitPrice><Money currency="USD">254.40</Money></UnitPrice><Description xml:lang="en">Leather Reclining Desk Chair with Padded Arms</Description><UnitOfMeasure>EA</UnitOfMeasure><Classification domain="UNSPSC">5136030000</Classification><LeadTime>12</LeadTime></ItemDetail></ItemIn></PunchOutOrderMessage></Message></cXML>')
expect(actual).to.equal(expected)
})
})
})