Skip to content

Commit

Permalink
wip: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Sep 26, 2024
1 parent cc250f0 commit c1a332d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ describe('groupPartsInMosRundownAndChanges', () => {
s1p2: NrcsIngestPartChangeDetails.Inserted,
},
partOrderChanged: true,
payloadChanged: false,
},
},
segmentOrderChanged: false,
Expand Down Expand Up @@ -284,6 +285,7 @@ describe('groupPartsInMosRundownAndChanges', () => {
s1p3: NrcsIngestPartChangeDetails.Deleted,
},
partOrderChanged: true,
payloadChanged: false,
},
},
segmentOrderChanged: false,
Expand Down Expand Up @@ -357,12 +359,14 @@ describe('groupPartsInMosRundownAndChanges', () => {
s1p2: NrcsIngestPartChangeDetails.Updated,
},
partOrderChanged: false,
payloadChanged: false,
},
rundown0_s2p1: {
partChanges: {
s2p2: NrcsIngestPartChangeDetails.Updated,
},
partOrderChanged: false,
payloadChanged: false,
},
},
segmentOrderChanged: false,
Expand All @@ -378,6 +382,39 @@ describe('groupPartsInMosRundownAndChanges', () => {
segmentChanges: {}, // Note: this is ignored for inserts/deletes
}

const previousIngestRundown = clone(nrcsIngestRundown)
previousIngestRundown.segments[0].name = 'SEGMENT0;PART1'
previousIngestRundown.segments[0].parts[0].name = 'SEGMENT0;PART1'
previousIngestRundown.segments[1].name = 'SEGMENT0;PART2'
previousIngestRundown.segments[1].parts[0].name = 'SEGMENT0;PART2'

const result = groupMosPartsInRundownAndChanges(nrcsIngestRundown, previousIngestRundown, ingestChanges)

expect(result).toEqual({
nrcsIngestRundown: combinedIngestRundown,
ingestChanges: {
source: IngestChangeType.Ingest,
changedSegmentExternalIds: {},
segmentChanges: {
rundown0_s1p1: {
partChanges: {},
partOrderChanged: false,
payloadChanged: true,
},
},
segmentOrderChanged: false,
},
} satisfies Complete<GroupPartsInMosRundownAndChangesResult>)
})

it('segment id changed', () => {
const { nrcsIngestRundown, combinedIngestRundown } = createBasicMosIngestRundown()

const ingestChanges: NrcsIngestChangeDetails = {
source: IngestChangeType.Ingest,
segmentChanges: {}, // Note: this is ignored for inserts/deletes
}

const previousIngestRundown = clone(nrcsIngestRundown)
previousIngestRundown.segments[0].externalId = 'segment-s1p1-old'
previousIngestRundown.segments[0].parts[0].externalId = 's1p1-old'
Expand All @@ -403,7 +440,7 @@ describe('groupPartsInMosRundownAndChanges', () => {
} satisfies Complete<GroupPartsInMosRundownAndChangesResult>)
})

it('segment renamed and moved', () => {
it('segment id changed and moved', () => {
const { nrcsIngestRundown, combinedIngestRundown } = createBasicMosIngestRundown()

const ingestChanges: NrcsIngestChangeDetails = {
Expand Down Expand Up @@ -507,13 +544,15 @@ describe('groupPartsInMosRundownAndChanges', () => {
s1p2: NrcsIngestPartChangeDetails.Inserted,
},
partOrderChanged: true,
payloadChanged: false,
},
rundown0_s1p2: NrcsIngestSegmentChangeDetailsEnum.Deleted,
rundown0_s2p1: {
partChanges: {
s2p2: NrcsIngestPartChangeDetails.Inserted,
},
partOrderChanged: true,
payloadChanged: false,
},
rundown0_s2p2: NrcsIngestSegmentChangeDetailsEnum.Deleted,
},
Expand Down Expand Up @@ -606,13 +645,15 @@ describe('groupPartsInMosRundownAndChanges', () => {
s1p2: NrcsIngestPartChangeDetails.Deleted,
},
partOrderChanged: true,
payloadChanged: false,
},
rundown0_s1p2: NrcsIngestSegmentChangeDetailsEnum.InsertedOrUpdated,
rundown0_s2p1: {
partChanges: {
s2p2: NrcsIngestPartChangeDetails.Deleted,
},
partOrderChanged: true,
payloadChanged: false,
},
rundown0_s2p2: NrcsIngestSegmentChangeDetailsEnum.InsertedOrUpdated,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,15 @@ function calculateSegmentChanges(
}
}

const payloadChanged =
oldIngestSegment.name !== segment.name || !_.isEqual(oldIngestSegment.payload, segment.payload)

const partOrderChanged = hasPartOrderChanged(segment.parts, oldIngestSegment.parts)
if (partOrderChanged || Object.keys(segmentPartChanges).length > 0) {
if (partOrderChanged || payloadChanged || Object.keys(segmentPartChanges).length > 0) {
segmentChanges[segment.externalId] = {
partChanges: segmentPartChanges,
partOrderChanged,
payloadChanged,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -862,21 +862,25 @@ describe('Test recieved mos ingest payloads', () => {
await expectRundownToMatchSnapshot(rundown._id, true, true)
})

test.skip('mosRoStorySwap: Swap with self', async () => {
test('mosRoStorySwap: Swap with self', async () => {
await resetOrphanedRundown()

const rundown = (await context.mockCollections.Rundowns.findOne()) as DBRundown
expect(rundown).toBeTruthy()

const story0 = mosTypes.mosString128.create('ro1;s1;p1')

await expect(
handleMosSwapStoriesWrapped(context, {
rundownExternalId: rundown.externalId,
story0,
story1: story0,
})
).rejects.toThrow(
`Cannot swap part ${mosTypes.mosString128.stringify(story0)} with itself in rundown ${rundown.externalId}`
)
// Swap should happen without error
await handleMosSwapStoriesWrapped(context, {
rundownExternalId: rundown.externalId,
story0,
story1: story0,
})

// should match the default
const { segments, parts } = await getRundownData({ _id: rundown._id })
const partMap = mockRO.segmentIdMap()
expect(getPartIdMap(segments, parts)).toEqual(partMap)
})

test('mosRoStorySwap: Story not found', async () => {
Expand Down Expand Up @@ -1211,7 +1215,7 @@ describe('Test recieved mos ingest payloads', () => {
const newSegment = newSegments.find((s) => s.name === newName)
if (newSegment) {
const oldSegmentId = oldSegment._id
expect(oldSegmentId).not.toEqual(newSegment._id) // If the id doesn't change, then the whole test is invalid
expect(oldSegmentId).toEqual(newSegment._id) // If the id doesn't change, then the whole test is invalid
oldSegment.name = newSegment.name
oldSegment._id = newSegment._id
oldSegment.externalId = newSegment.externalId
Expand Down
2 changes: 1 addition & 1 deletion packages/job-worker/src/ingest/mosDevice/mosStoryJobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export function handleMosInsertStories(
for (const segment of newIngestSegments) {
segmentChanges[segment.externalId] = NrcsIngestSegmentChangeDetailsEnum.InsertedOrUpdated
}
if (data.replace && insertBeforeSegmentExternalId) {
if (data.replace && insertBeforeSegmentExternalId && !segmentChanges[insertBeforeSegmentExternalId]) {
segmentChanges[insertBeforeSegmentExternalId] = NrcsIngestSegmentChangeDetailsEnum.Deleted
}

Expand Down

0 comments on commit c1a332d

Please sign in to comment.