From c1a332df779dd94992393995847e4a6c68a67b9b Mon Sep 17 00:00:00 2001 From: Julian Waller Date: Thu, 26 Sep 2024 17:19:41 +0100 Subject: [PATCH] wip: fix test --- .../groupPartsInMosRundownAndChanges.spec.ts | 43 ++++++++++++++++++- .../ingest/groupPartsInRundownAndChanges.ts | 6 ++- .../mosDevice/__tests__/mosIngest.test.ts | 26 ++++++----- .../src/ingest/mosDevice/mosStoryJobs.ts | 2 +- 4 files changed, 63 insertions(+), 14 deletions(-) diff --git a/packages/job-worker/src/blueprints/ingest/__tests__/groupPartsInMosRundownAndChanges.spec.ts b/packages/job-worker/src/blueprints/ingest/__tests__/groupPartsInMosRundownAndChanges.spec.ts index 526d3031c3..01aed7cf04 100644 --- a/packages/job-worker/src/blueprints/ingest/__tests__/groupPartsInMosRundownAndChanges.spec.ts +++ b/packages/job-worker/src/blueprints/ingest/__tests__/groupPartsInMosRundownAndChanges.spec.ts @@ -214,6 +214,7 @@ describe('groupPartsInMosRundownAndChanges', () => { s1p2: NrcsIngestPartChangeDetails.Inserted, }, partOrderChanged: true, + payloadChanged: false, }, }, segmentOrderChanged: false, @@ -284,6 +285,7 @@ describe('groupPartsInMosRundownAndChanges', () => { s1p3: NrcsIngestPartChangeDetails.Deleted, }, partOrderChanged: true, + payloadChanged: false, }, }, segmentOrderChanged: false, @@ -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, @@ -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) + }) + + 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' @@ -403,7 +440,7 @@ describe('groupPartsInMosRundownAndChanges', () => { } satisfies Complete) }) - it('segment renamed and moved', () => { + it('segment id changed and moved', () => { const { nrcsIngestRundown, combinedIngestRundown } = createBasicMosIngestRundown() const ingestChanges: NrcsIngestChangeDetails = { @@ -507,6 +544,7 @@ describe('groupPartsInMosRundownAndChanges', () => { s1p2: NrcsIngestPartChangeDetails.Inserted, }, partOrderChanged: true, + payloadChanged: false, }, rundown0_s1p2: NrcsIngestSegmentChangeDetailsEnum.Deleted, rundown0_s2p1: { @@ -514,6 +552,7 @@ describe('groupPartsInMosRundownAndChanges', () => { s2p2: NrcsIngestPartChangeDetails.Inserted, }, partOrderChanged: true, + payloadChanged: false, }, rundown0_s2p2: NrcsIngestSegmentChangeDetailsEnum.Deleted, }, @@ -606,6 +645,7 @@ describe('groupPartsInMosRundownAndChanges', () => { s1p2: NrcsIngestPartChangeDetails.Deleted, }, partOrderChanged: true, + payloadChanged: false, }, rundown0_s1p2: NrcsIngestSegmentChangeDetailsEnum.InsertedOrUpdated, rundown0_s2p1: { @@ -613,6 +653,7 @@ describe('groupPartsInMosRundownAndChanges', () => { s2p2: NrcsIngestPartChangeDetails.Deleted, }, partOrderChanged: true, + payloadChanged: false, }, rundown0_s2p2: NrcsIngestSegmentChangeDetailsEnum.InsertedOrUpdated, }, diff --git a/packages/job-worker/src/blueprints/ingest/groupPartsInRundownAndChanges.ts b/packages/job-worker/src/blueprints/ingest/groupPartsInRundownAndChanges.ts index f7781bbb46..09304c3f76 100644 --- a/packages/job-worker/src/blueprints/ingest/groupPartsInRundownAndChanges.ts +++ b/packages/job-worker/src/blueprints/ingest/groupPartsInRundownAndChanges.ts @@ -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, } } } diff --git a/packages/job-worker/src/ingest/mosDevice/__tests__/mosIngest.test.ts b/packages/job-worker/src/ingest/mosDevice/__tests__/mosIngest.test.ts index 7afa3157bc..c96a18890d 100644 --- a/packages/job-worker/src/ingest/mosDevice/__tests__/mosIngest.test.ts +++ b/packages/job-worker/src/ingest/mosDevice/__tests__/mosIngest.test.ts @@ -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 () => { @@ -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 diff --git a/packages/job-worker/src/ingest/mosDevice/mosStoryJobs.ts b/packages/job-worker/src/ingest/mosDevice/mosStoryJobs.ts index 5f79f130d6..d63e2a382a 100644 --- a/packages/job-worker/src/ingest/mosDevice/mosStoryJobs.ts +++ b/packages/job-worker/src/ingest/mosDevice/mosStoryJobs.ts @@ -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 }