Skip to content

Commit

Permalink
fix: ExternalMetadata.MosPayload wasn't passed through when containin…
Browse files Browse the repository at this point in the history
…g string. Changed MosPayload to be AnyXMLValue instead of AnyXMLObject.
  • Loading branch information
nytamin committed Jan 22, 2025
1 parent 44168ad commit d5cfec5
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 3 deletions.
69 changes: 69 additions & 0 deletions packages/connector/src/__mocks__/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,33 @@ const xmlData = {
01 ett navn 1: 2:
24 foto/red 1:Foto og redigering: 2: SAK BUSKERUD;SAK-20</MOSSlugs> <Owner>LINUXENPS</Owner> <pubApproved>0</pubApproved> <SourceMediaTime>0</SourceMediaTime> <SourceTextTime>0</SourceTextTime> <StoryProducer>DKTE</StoryProducer> <TextTime>0</TextTime> <mosartType>FULL</mosartType> <ENPSItemType>3</ENPSItemType> </mosPayload> </mosExternalMetadata> </roStorySend>`,
roStorySendSingle: `<roStorySend><roID>roID0</roID><storyID>story0</storyID><storySlug>My Story</storySlug><storyNum/><storyBody><storyItem><itemID>item0</itemID><itemSlug/><objID>object0</objID><mosID>mos0</mosID><itemTrigger>CHAINED</itemTrigger></storyItem></storyBody></roStorySend>`,
roStorySendStringMosPayload: `<roStorySend>
<roID>2012R2ENPS8VM;P_ENPSNEWS\\W;696297DF-1568-4B36-B43B3B79514B40D4</roID>
<storyID>2012R2ENPS8VM;P_ENPSNEWS\\W\\R_696297DF-1568-4B36-B43B3B79514B40D4;1DAF0044-CA12-47BA-9F6CEFF33B3874FB</storyID>
<storySlug>KRITIKK ETTER BRANN KONGSBERG;SAK</storySlug>
<storyNum></storyNum>
<storyBody>
<storyItem>
<itemID>2</itemID>
<objID>N11580_1412594672</objID>
<mosID>METADATA.NRK.MOS</mosID>
<mosAbstract>METADATA</mosAbstract>
<objSlug>M: </objSlug>
<mosExternalMetadata>
<mosScope>PLAYLIST</mosScope>
<mosSchema>https://MOSA4.com/mos/supported_schemas/MOSAXML2.08</mosSchema>
<mosPayload>THIS IS A STRING</mosPayload>
</mosExternalMetadata>
<itemSlug>SAK BUSKERUD;SAK-14</itemSlug>
</storyItem>
<p>a text</p>
</storyBody>
<mosExternalMetadata>
<mosScope>PLAYLIST</mosScope>
<mosSchema>https://2012R2ENPS8VM:10505/schema/enps.dtd</mosSchema>
<mosPayload>THIS IS ANOTHER STRING</mosPayload>
</mosExternalMetadata>
</roStorySend>`,
roListAll: `<roListAll> <ro> <roID>5PM</roID> <roSlug>5PM Rundown</roSlug> <roChannel></roChannel> <roEdStart>2009-07-11T17:00:00</roEdStart> <roEdDur>00:30:00</roEdDur> <roTrigger>MANUAL</roTrigger> <mosExternalMetadata> <mosScope>PLAYLIST</mosScope> <mosSchema>https://ncsA4.com/mos/supported_schemas/NCSAXML2.08</mosSchema> <mosPayload> <Owner>SHOLMES</Owner> <mediaTime>0</mediaTime> <TextTime>278</TextTime> <ModBy>LJOHNSTON</ModBy> <Approved>0</Approved> <Creator>SHOLMES</Creator> </mosPayload> </mosExternalMetadata> </ro> <ro> <roID>6PM</roID> <roSlug>6PM Rundown</roSlug> <roChannel></roChannel> <roEdStart>2009-07-09T18:00:00</roEdStart> <roEdDur>00:30:00</roEdDur> <roTrigger>MANUAL</roTrigger> <mosExternalMetadata> <mosScope>PLAYLIST</mosScope> <mosSchema>https://ncsA4.com/mos/supported_schemas/NCSAXML2.08</mosSchema> <mosPayload> <Owner>SHOLMES</Owner> <mediaTime>0</mediaTime> <TextTime>350</TextTime> <ModBy>BSMITH</ModBy> <Approved>1</Approved> <Creator>SHOLMES</Creator> </mosPayload> </mosExternalMetadata> </ro> </roListAll>`,
mosObjCreate: `
<mosObjCreate>
Expand Down Expand Up @@ -1919,6 +1946,48 @@ const xmlApiData = {
}),
],
}),
roStorySendStringMosPayload: literal<IMOSROFullStory>({
ID: mosTypes.mosString128.create(
'2012R2ENPS8VM;P_ENPSNEWS\\W\\R_696297DF-1568-4B36-B43B3B79514B40D4;1DAF0044-CA12-47BA-9F6CEFF33B3874FB'
),
RunningOrderId: mosTypes.mosString128.create('2012R2ENPS8VM;P_ENPSNEWS\\W;696297DF-1568-4B36-B43B3B79514B40D4'),
Slug: mosTypes.mosString128.create('KRITIKK ETTER BRANN KONGSBERG;SAK'),
Body: [
literal<IMOSROFullStoryBodyItem>({
itemType: 'storyItem',
Type: 'storyItem',
Content: literal<IMOSItem>({
ID: mosTypes.mosString128.create('2'),
Slug: mosTypes.mosString128.create('SAK BUSKERUD;SAK-14'),
ObjectID: mosTypes.mosString128.create('N11580_1412594672'),
MOSID: 'METADATA.NRK.MOS',
mosAbstract: 'METADATA',
ObjectSlug: mosTypes.mosString128.create('M:'),
MosExternalMetaData: [
literal<IMOSExternalMetaData>({
MosScope: IMOSScope.PLAYLIST,
MosSchema: 'https://MOSA4.com/mos/supported_schemas/MOSAXML2.08',
MosPayload: 'THIS IS A STRING',
}),
],
}),
}),
literal<IMOSROFullStoryBodyItem>({
itemType: 'other',
Type: 'p',
Content: {
text: 'a text',
},
}),
],
MosExternalMetaData: [
literal<IMOSExternalMetaData>({
MosScope: IMOSScope.PLAYLIST,
MosSchema: 'https://2012R2ENPS8VM:10505/schema/enps.dtd',
MosPayload: 'THIS IS ANOTHER STRING',
}),
],
}),
roListAll: [
literal<IMOSRunningOrderBase>({
ID: mosTypes.mosString128.create('5PM'),
Expand Down
28 changes: 28 additions & 0 deletions packages/connector/src/__tests__/Profile4.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,34 @@ describe('Profile 4', () => {
})
await checkReplyToServer(serverSocketMockLower, messageId, '<roAck>')
})
test('onRunningOrderStory, string MosPayload', async () => {
// Fake incoming message on socket:

const messageId = await fakeIncomingMessage(serverSocketMockLower, xmlData.roStorySendStringMosPayload)
expect(onROStory).toHaveBeenCalledTimes(1)

const o = { ...xmlApiData.roStorySendStringMosPayload }
// @ts-expect-error optional property
delete o.Body
expect(onROStory.mock.calls[0][0]).toMatchObject(o)

expect(fixSnapshot(onROStory.mock.calls)).toMatchSnapshot()
xmlApiData.roStorySendStringMosPayload.Body.forEach((testItem, key) => {
let item: any
try {
item = onROStory.mock.calls[0][0].Body[key]
if (!testItem.Content) delete testItem.Content

expect(item).toMatchObject(testItem)
} catch (e) {
console.error(key)
console.error('item', item)
console.error('testItem', testItem)
throw e
}
})
await checkReplyToServer(serverSocketMockLower, messageId, '<roAck>')
})
test('onRequestAllRunningOrders', async () => {
const onRoReqAll = jest.fn(async (): Promise<IMOSRunningOrder[]> => {
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,89 @@ exports[`Profile 4 onRunningOrderStory 1`] = `
]
`;

exports[`Profile 4 onRunningOrderStory, string MosPayload 1`] = `
[
[
{
"Body": [
{
"Content": {
"ID": {
"_mosString128": "2",
},
"MOSID": "METADATA.NRK.MOS",
"MosExternalMetaData": [
{
"MosPayload": "THIS IS A STRING",
"MosSchema": "https://MOSA4.com/mos/supported_schemas/MOSAXML2.08",
"MosScope": "PLAYLIST",
},
],
"ObjectID": {
"_mosString128": "N11580_1412594672",
},
"ObjectSlug": {
"_mosString128": "M:",
},
"Slug": {
"_mosString128": "SAK BUSKERUD;SAK-14",
},
"mosAbstract": "METADATA",
},
"Type": "storyItem",
"itemType": "storyItem",
},
{
"Content": {
"$name": "p",
"$type": "text",
"text": "a text",
},
"Type": "p",
"itemType": "other",
},
],
"ID": {
"_mosString128": "2012R2ENPS8VM;P_ENPSNEWS\\W\\R_696297DF-1568-4B36-B43B3B79514B40D4;1DAF0044-CA12-47BA-9F6CEFF33B3874FB",
},
"MosExternalMetaData": [
{
"MosPayload": "THIS IS ANOTHER STRING",
"MosSchema": "https://2012R2ENPS8VM:10505/schema/enps.dtd",
"MosScope": "PLAYLIST",
},
],
"RunningOrderId": {
"_mosString128": "2012R2ENPS8VM;P_ENPSNEWS\\W;696297DF-1568-4B36-B43B3B79514B40D4",
},
"Slug": {
"_mosString128": "KRITIKK ETTER BRANN KONGSBERG;SAK",
},
},
],
]
`;

exports[`Profile 4 onRunningOrderStory, string MosPayload: <mos>
<ncsID>their.mos.id</ncsID>
<mosID>our.mos.id</mosID>
<messageID>1635</messageID>
<roAck>
<roID>runningOrderId</roID>
<roStatus>OK</roStatus>
</roAck>
</mos> 1`] = `
"<mos>
<ncsID>their.mos.id</ncsID>
<mosID>our.mos.id</mosID>
<messageID>1635</messageID>
<roAck>
<roID>runningOrderId</roID>
<roStatus>OK</roStatus>
</roAck>
</mos>"
`;

exports[`Profile 4 onRunningOrderStory: <mos>
<ncsID>their.mos.id</ncsID>
<mosID>our.mos.id</mosID>
Expand Down
4 changes: 3 additions & 1 deletion packages/helper/src/mosModel/profile1/xmlConversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ export namespace XMLMosExternalMetaData {
'mosScope'
),
MosSchema: mosTypes.string.createRequired(xmlMetadata.mosSchema, 'mosSchema'),
MosPayload: fixXMLMosPayload(ensureXMLObject(xmlMetadata.mosPayload, strict)),
MosPayload: fixXMLMosPayload(xmlMetadata.mosPayload),
})
}
omitUndefined(metadata)
Expand All @@ -384,6 +384,8 @@ export namespace XMLMosExternalMetaData {
}
}
}

/** Replace any empty objects with "" */
function fixXMLMosPayload(value: AnyXMLValueSingular): AnyXMLValueSingular
function fixXMLMosPayload(value: AnyXMLObject): AnyXMLObject
function fixXMLMosPayload(value: AnyXMLValue): AnyXMLValue
Expand Down
4 changes: 2 additions & 2 deletions packages/model/src/mosTypes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as MosString128 from './mosTypes/mosString128'
import * as MosDuration from './mosTypes/mosDuration'
import * as MosTime from './mosTypes/mosTime'
import { AnyXMLObject } from './xmlParse'
import { AnyXMLValue } from './xmlParse'

export { IMOSString128 } from './mosTypes/mosString128'
export { IMOSDuration } from './mosTypes/mosDuration'
Expand Down Expand Up @@ -92,7 +92,7 @@ function getMosType<Serialized, Value, CreateValue>(
export interface IMOSExternalMetaData {
MosScope?: IMOSScope
MosSchema: string
MosPayload: AnyXMLObject
MosPayload: AnyXMLValue
}
export enum IMOSScope {
OBJECT = 'OBJECT',
Expand Down

0 comments on commit d5cfec5

Please sign in to comment.