Skip to content

Commit

Permalink
feat: test for text with and without attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
olzzon committed Jan 7, 2025
1 parent 64771f5 commit ece22e4
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/helper/src/__tests__/parsing/mosSample3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"items": [
{
"ID": "2",
"ObjectID": "cfc641849c417eaa10e4f3c377f181",
"MOSID": "parsing-text.sofie",
"Slug": "bts-finnmark-bil_with_attr(3)",
"Paths": [
{
"Description": "VIDEO",
"Target": "41cfc641849c417eaa10e4f3c377f181",
"Type": "PATH"
}
],
"MosExternalMetaData": [
{
"MosScope": "OBJECT",
"MosSchema": "http://mos-connection/unit-test",
"MosPayload": {
"objType": "VIDEO",
"zone": {
"name": "graphics",
"sequence": "weather-tower",
"variableNoAttr": "1,2,3,4",
"variable": {
"name": "locations",
"text": "1,2,3,4"
}
}
}
}
],
"ObjectSlug": "bts-finnmark-bil_with_attr(3)"
}
]
}
28 changes: 28 additions & 0 deletions packages/helper/src/__tests__/parsing/mosSample3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<mos>
<ncsItem>
<item>
<itemID>2</itemID>
<itemSlug>bts-finnmark-bil_with_attr(3)</itemSlug>
<objID>cfc641849c417eaa10e4f3c377f181</objID>
<objSlug>bts-finnmark-bil_with_attr(3)</objSlug>
<mosID>parsing-text.sofie</mosID>
<mosPlugInID>Sofie.QuantelPlugin</mosPlugInID>
<mosAbstract />
<objPaths>
<objPath techDescription="VIDEO">41cfc641849c417eaa10e4f3c377f181</objPath>
</objPaths>
<itemEdDur />
<mosExternalMetadata>
<mosScope>OBJECT</mosScope>
<mosSchema>http://mos-connection/unit-test</mosSchema>
<mosPayload>
<objType>VIDEO</objType>
<zone name="graphics" sequence="weather-tower">
<variableNoAttr>1,2,3,4</variableNoAttr>
<variable name="locations">1,2,3,4</variable>
</zone>
</mosPayload>
</mosExternalMetadata>
</item>
</ncsItem>
</mos>
24 changes: 24 additions & 0 deletions packages/helper/src/__tests__/parsing/mosXml2Js.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,30 @@ describe('MOS XML to JavaScript object parser', () => {
expect(actualJson).toEqual(jsonDoc.items)
})

it('converting via xml should be lossless', () => {
for (let i = 0; i < jsonDoc.items.length; i++) {
const generatedXml = generateMosPluginItemXml(jsonDoc.items[i])
const actual = parseMosPluginMessageXml(generatedXml)

const actualJson = actual && stringifyMosObject(actual.items[0], true) // Strip out any MosString etc

expect(actualJson).toEqual(jsonDoc.items[i])
}
})
})
describe('Sample3 - test for singlepath with and without attributes', () => {
const sampleXmlStr = readFileSync(join(__dirname, './mosSample3.xml'), 'utf-8')
const sampleJsonStr = readFileSync(join(__dirname, './mosSample3.json'), 'utf-8')

const jsonDoc = JSON.parse(sampleJsonStr)

it('should match the json representation', () => {
const actual = parseMosPluginMessageXml(sampleXmlStr)
const actualJson = actual && stringifyMosObject(actual.items, true) // Strip out any MosString etc

expect(actualJson).toEqual(jsonDoc.items)
})

it('converting via xml should be lossless', () => {
for (let i = 0; i < jsonDoc.items.length; i++) {
const generatedXml = generateMosPluginItemXml(jsonDoc.items[i])
Expand Down

0 comments on commit ece22e4

Please sign in to comment.