nrkno / sofie-mos-connection

Sofie MOS Connection: A Part of the Sofie TV Studio Automation System
https://github.com/nrkno/Sofie-TV-automation/
MIT License
22 stars 14 forks source link

Bug on xml2js function #73

Closed JuanPabloLoCoco closed 1 year ago

JuanPabloLoCoco commented 1 year ago
<mos>
    <mosID>${mosId}</mosID>
    <ncsID>${ncsId}</ncsID>
    <messageID>3</messageID>
    <roElementAction operation="INSERT">
      <roID>${roId}</roID>
      <element_target>
        <storyID>1</storyID>
      </element_target>
      <element_source>
        <story>
          <whatever>2</whatever>
        </story>
      </element_source>
    </roElementAction>
  </mos>

If I want to process this mesage, in the MosDevice.ts on sourceStories i will get:

[
      {
        ID: { _mosString128: 'undefined' },
        Slug: { _mosString128: 'undefined' },
        Items: []
      }
    ]

This is because data.roElementAction.element_source is equal to { text: 2, story: 2}. And this occurs because in the function xml2js exists a logic for compressing the tags when a node has a unique long branch.

In this example the child of <story> is <whatevet> because it doesn't matter what is the name of the nodes between the root node and its child's.

nytamin commented 1 year ago

Thanks for this bug report! Would you mind opening a pull request where you add a (failing) unit test that shows the issue? That way we'd be able to find the issue more easily.

A good place to add a units test would be here: https://github.com/nrkno/sofie-mos-connection/blob/master/packages/connector/src/__tests__/Profile2.spec.ts#L454

Add one by copying an existing one, then run the tests with yarn test (you might have to install (yarn and build yarn build first).