diff --git a/packages/helper/src/__tests__/parsing/mosSample3.json b/packages/helper/src/__tests__/parsing/mosSample3.json new file mode 100644 index 00000000..abd96ada --- /dev/null +++ b/packages/helper/src/__tests__/parsing/mosSample3.json @@ -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)" + } + ] +} \ No newline at end of file diff --git a/packages/helper/src/__tests__/parsing/mosSample3.xml b/packages/helper/src/__tests__/parsing/mosSample3.xml new file mode 100644 index 00000000..fe19b076 --- /dev/null +++ b/packages/helper/src/__tests__/parsing/mosSample3.xml @@ -0,0 +1,28 @@ + + + + 2 + bts-finnmark-bil_with_attr(3) + cfc641849c417eaa10e4f3c377f181 + bts-finnmark-bil_with_attr(3) + parsing-text.sofie + Sofie.QuantelPlugin + + + 41cfc641849c417eaa10e4f3c377f181 + + + + OBJECT + http://mos-connection/unit-test + + VIDEO + + 1,2,3,4 + 1,2,3,4 + + + + + + \ No newline at end of file diff --git a/packages/helper/src/__tests__/parsing/mosXml2Js.spec.ts b/packages/helper/src/__tests__/parsing/mosXml2Js.spec.ts index 8e8808b9..c871568c 100644 --- a/packages/helper/src/__tests__/parsing/mosXml2Js.spec.ts +++ b/packages/helper/src/__tests__/parsing/mosXml2Js.spec.ts @@ -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])