Skip to content

Commit d5cfec5

Browse files
committed
fix: ExternalMetadata.MosPayload wasn't passed through when containing string. Changed MosPayload to be AnyXMLValue instead of AnyXMLObject.
1 parent 44168ad commit d5cfec5

File tree

5 files changed

+185
-3
lines changed

5 files changed

+185
-3
lines changed

packages/connector/src/__mocks__/testData.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,33 @@ const xmlData = {
153153
01 ett navn 1: 2:
154154
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>`,
155155
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>`,
156+
roStorySendStringMosPayload: `<roStorySend>
157+
<roID>2012R2ENPS8VM;P_ENPSNEWS\\W;696297DF-1568-4B36-B43B3B79514B40D4</roID>
158+
<storyID>2012R2ENPS8VM;P_ENPSNEWS\\W\\R_696297DF-1568-4B36-B43B3B79514B40D4;1DAF0044-CA12-47BA-9F6CEFF33B3874FB</storyID>
159+
<storySlug>KRITIKK ETTER BRANN KONGSBERG;SAK</storySlug>
160+
<storyNum></storyNum>
161+
<storyBody>
162+
<storyItem>
163+
<itemID>2</itemID>
164+
<objID>N11580_1412594672</objID>
165+
<mosID>METADATA.NRK.MOS</mosID>
166+
<mosAbstract>METADATA</mosAbstract>
167+
<objSlug>M: </objSlug>
168+
<mosExternalMetadata>
169+
<mosScope>PLAYLIST</mosScope>
170+
<mosSchema>https://MOSA4.com/mos/supported_schemas/MOSAXML2.08</mosSchema>
171+
<mosPayload>THIS IS A STRING</mosPayload>
172+
</mosExternalMetadata>
173+
<itemSlug>SAK BUSKERUD;SAK-14</itemSlug>
174+
</storyItem>
175+
<p>a text</p>
176+
</storyBody>
177+
<mosExternalMetadata>
178+
<mosScope>PLAYLIST</mosScope>
179+
<mosSchema>https://2012R2ENPS8VM:10505/schema/enps.dtd</mosSchema>
180+
<mosPayload>THIS IS ANOTHER STRING</mosPayload>
181+
</mosExternalMetadata>
182+
</roStorySend>`,
156183
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>`,
157184
mosObjCreate: `
158185
<mosObjCreate>
@@ -1919,6 +1946,48 @@ const xmlApiData = {
19191946
}),
19201947
],
19211948
}),
1949+
roStorySendStringMosPayload: literal<IMOSROFullStory>({
1950+
ID: mosTypes.mosString128.create(
1951+
'2012R2ENPS8VM;P_ENPSNEWS\\W\\R_696297DF-1568-4B36-B43B3B79514B40D4;1DAF0044-CA12-47BA-9F6CEFF33B3874FB'
1952+
),
1953+
RunningOrderId: mosTypes.mosString128.create('2012R2ENPS8VM;P_ENPSNEWS\\W;696297DF-1568-4B36-B43B3B79514B40D4'),
1954+
Slug: mosTypes.mosString128.create('KRITIKK ETTER BRANN KONGSBERG;SAK'),
1955+
Body: [
1956+
literal<IMOSROFullStoryBodyItem>({
1957+
itemType: 'storyItem',
1958+
Type: 'storyItem',
1959+
Content: literal<IMOSItem>({
1960+
ID: mosTypes.mosString128.create('2'),
1961+
Slug: mosTypes.mosString128.create('SAK BUSKERUD;SAK-14'),
1962+
ObjectID: mosTypes.mosString128.create('N11580_1412594672'),
1963+
MOSID: 'METADATA.NRK.MOS',
1964+
mosAbstract: 'METADATA',
1965+
ObjectSlug: mosTypes.mosString128.create('M:'),
1966+
MosExternalMetaData: [
1967+
literal<IMOSExternalMetaData>({
1968+
MosScope: IMOSScope.PLAYLIST,
1969+
MosSchema: 'https://MOSA4.com/mos/supported_schemas/MOSAXML2.08',
1970+
MosPayload: 'THIS IS A STRING',
1971+
}),
1972+
],
1973+
}),
1974+
}),
1975+
literal<IMOSROFullStoryBodyItem>({
1976+
itemType: 'other',
1977+
Type: 'p',
1978+
Content: {
1979+
text: 'a text',
1980+
},
1981+
}),
1982+
],
1983+
MosExternalMetaData: [
1984+
literal<IMOSExternalMetaData>({
1985+
MosScope: IMOSScope.PLAYLIST,
1986+
MosSchema: 'https://2012R2ENPS8VM:10505/schema/enps.dtd',
1987+
MosPayload: 'THIS IS ANOTHER STRING',
1988+
}),
1989+
],
1990+
}),
19221991
roListAll: [
19231992
literal<IMOSRunningOrderBase>({
19241993
ID: mosTypes.mosString128.create('5PM'),

packages/connector/src/__tests__/Profile4.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,34 @@ describe('Profile 4', () => {
156156
})
157157
await checkReplyToServer(serverSocketMockLower, messageId, '<roAck>')
158158
})
159+
test('onRunningOrderStory, string MosPayload', async () => {
160+
// Fake incoming message on socket:
161+
162+
const messageId = await fakeIncomingMessage(serverSocketMockLower, xmlData.roStorySendStringMosPayload)
163+
expect(onROStory).toHaveBeenCalledTimes(1)
164+
165+
const o = { ...xmlApiData.roStorySendStringMosPayload }
166+
// @ts-expect-error optional property
167+
delete o.Body
168+
expect(onROStory.mock.calls[0][0]).toMatchObject(o)
169+
170+
expect(fixSnapshot(onROStory.mock.calls)).toMatchSnapshot()
171+
xmlApiData.roStorySendStringMosPayload.Body.forEach((testItem, key) => {
172+
let item: any
173+
try {
174+
item = onROStory.mock.calls[0][0].Body[key]
175+
if (!testItem.Content) delete testItem.Content
176+
177+
expect(item).toMatchObject(testItem)
178+
} catch (e) {
179+
console.error(key)
180+
console.error('item', item)
181+
console.error('testItem', testItem)
182+
throw e
183+
}
184+
})
185+
await checkReplyToServer(serverSocketMockLower, messageId, '<roAck>')
186+
})
159187
test('onRequestAllRunningOrders', async () => {
160188
const onRoReqAll = jest.fn(async (): Promise<IMOSRunningOrder[]> => {
161189
return [

packages/connector/src/__tests__/__snapshots__/Profile4.spec.ts.snap

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,89 @@ exports[`Profile 4 onRunningOrderStory 1`] = `
627627
]
628628
`;
629629

630+
exports[`Profile 4 onRunningOrderStory, string MosPayload 1`] = `
631+
[
632+
[
633+
{
634+
"Body": [
635+
{
636+
"Content": {
637+
"ID": {
638+
"_mosString128": "2",
639+
},
640+
"MOSID": "METADATA.NRK.MOS",
641+
"MosExternalMetaData": [
642+
{
643+
"MosPayload": "THIS IS A STRING",
644+
"MosSchema": "https://MOSA4.com/mos/supported_schemas/MOSAXML2.08",
645+
"MosScope": "PLAYLIST",
646+
},
647+
],
648+
"ObjectID": {
649+
"_mosString128": "N11580_1412594672",
650+
},
651+
"ObjectSlug": {
652+
"_mosString128": "M:",
653+
},
654+
"Slug": {
655+
"_mosString128": "SAK BUSKERUD;SAK-14",
656+
},
657+
"mosAbstract": "METADATA",
658+
},
659+
"Type": "storyItem",
660+
"itemType": "storyItem",
661+
},
662+
{
663+
"Content": {
664+
"$name": "p",
665+
"$type": "text",
666+
"text": "a text",
667+
},
668+
"Type": "p",
669+
"itemType": "other",
670+
},
671+
],
672+
"ID": {
673+
"_mosString128": "2012R2ENPS8VM;P_ENPSNEWS\\W\\R_696297DF-1568-4B36-B43B3B79514B40D4;1DAF0044-CA12-47BA-9F6CEFF33B3874FB",
674+
},
675+
"MosExternalMetaData": [
676+
{
677+
"MosPayload": "THIS IS ANOTHER STRING",
678+
"MosSchema": "https://2012R2ENPS8VM:10505/schema/enps.dtd",
679+
"MosScope": "PLAYLIST",
680+
},
681+
],
682+
"RunningOrderId": {
683+
"_mosString128": "2012R2ENPS8VM;P_ENPSNEWS\\W;696297DF-1568-4B36-B43B3B79514B40D4",
684+
},
685+
"Slug": {
686+
"_mosString128": "KRITIKK ETTER BRANN KONGSBERG;SAK",
687+
},
688+
},
689+
],
690+
]
691+
`;
692+
693+
exports[`Profile 4 onRunningOrderStory, string MosPayload: <mos>
694+
<ncsID>their.mos.id</ncsID>
695+
<mosID>our.mos.id</mosID>
696+
<messageID>1635</messageID>
697+
<roAck>
698+
<roID>runningOrderId</roID>
699+
<roStatus>OK</roStatus>
700+
</roAck>
701+
</mos> 1`] = `
702+
"<mos>
703+
<ncsID>their.mos.id</ncsID>
704+
<mosID>our.mos.id</mosID>
705+
<messageID>1635</messageID>
706+
<roAck>
707+
<roID>runningOrderId</roID>
708+
<roStatus>OK</roStatus>
709+
</roAck>
710+
</mos>"
711+
`;
712+
630713
exports[`Profile 4 onRunningOrderStory: <mos>
631714
<ncsID>their.mos.id</ncsID>
632715
<mosID>our.mos.id</mosID>

packages/helper/src/mosModel/profile1/xmlConversion.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ export namespace XMLMosExternalMetaData {
361361
'mosScope'
362362
),
363363
MosSchema: mosTypes.string.createRequired(xmlMetadata.mosSchema, 'mosSchema'),
364-
MosPayload: fixXMLMosPayload(ensureXMLObject(xmlMetadata.mosPayload, strict)),
364+
MosPayload: fixXMLMosPayload(xmlMetadata.mosPayload),
365365
})
366366
}
367367
omitUndefined(metadata)
@@ -384,6 +384,8 @@ export namespace XMLMosExternalMetaData {
384384
}
385385
}
386386
}
387+
388+
/** Replace any empty objects with "" */
387389
function fixXMLMosPayload(value: AnyXMLValueSingular): AnyXMLValueSingular
388390
function fixXMLMosPayload(value: AnyXMLObject): AnyXMLObject
389391
function fixXMLMosPayload(value: AnyXMLValue): AnyXMLValue

packages/model/src/mosTypes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as MosString128 from './mosTypes/mosString128'
22
import * as MosDuration from './mosTypes/mosDuration'
33
import * as MosTime from './mosTypes/mosTime'
4-
import { AnyXMLObject } from './xmlParse'
4+
import { AnyXMLValue } from './xmlParse'
55

66
export { IMOSString128 } from './mosTypes/mosString128'
77
export { IMOSDuration } from './mosTypes/mosDuration'
@@ -92,7 +92,7 @@ function getMosType<Serialized, Value, CreateValue>(
9292
export interface IMOSExternalMetaData {
9393
MosScope?: IMOSScope
9494
MosSchema: string
95-
MosPayload: AnyXMLObject
95+
MosPayload: AnyXMLValue
9696
}
9797
export enum IMOSScope {
9898
OBJECT = 'OBJECT',

0 commit comments

Comments
 (0)