Skip to content

Commit

Permalink
Capture behaviour of existing diff library
Browse files Browse the repository at this point in the history
  • Loading branch information
rtyley committed Jan 30, 2024
1 parent 1e9b727 commit 261f1d9
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/model/commands/UpdateAtomCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.gu.media.util.MediaAtomImplicits
import com.gu.pandomainauth.model.{User => PandaUser}
import data.DataStores
import model.commands.CommandExceptions._
import model.commands.UpdateAtomCommand.createDiffString
import org.joda.time.DateTime
import util.AWSConfig

Expand Down Expand Up @@ -120,7 +121,9 @@ case class UpdateAtomCommand(id: String, atom: MediaAtom, override val stores: D
val message = AtomAssignedProjectMessage.build(newAtom)
plutoActions.sendToPluto(message)
}
}

object UpdateAtomCommand {
private val interestingFields = List("title", "category", "description", "duration", "source", "youtubeCategoryId", "license", "commentsEnabled", "channelId", "legallySensitive")

// We don't use HTTP patch so diffing has to be done manually
Expand Down
55 changes: 55 additions & 0 deletions test/model/commands/UpdateAtomCommandTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package model.commands

import com.gu.media.model.{Category, ContentChangeDetails, MediaAtom}
import org.scalatest.{FunSuite, MustMatchers}

class UpdateAtomCommandTest extends FunSuite with MustMatchers {
val mediaAtomFixture: MediaAtom = MediaAtom(
id = "123",
labels = List.empty,
assets = List.empty,
activeVersion = Some(1),
title = "title",
category = Category.News,
description = Some("description"),
duration = Some(1),
source = Some("source"),
posterImage = None,
trailText = None,
youtubeTitle = "title",
youtubeDescription = None,
trailImage = None,
tags = List.empty,
byline = List.empty,
commissioningDesks = List.empty,
contentChangeDetails = ContentChangeDetails(None, None, None, 1L, None, None, None),
privacyStatus = None,
channelId = None,
youtubeCategoryId = None,
youtubeOverrideImage = None,
keywords = List.empty,
license = None,
plutoData = None,
blockAds = false,
expiryDate = None,
legallySensitive = None,
sensitive = None,
optimisedForWeb = None,
composerCommentsEnabled = None,
suppressRelatedContent = None
)

test("Diff output when nothing changes") {
val str = UpdateAtomCommand.createDiffString(mediaAtomFixture, mediaAtomFixture)
println(str)
str must be(
"""Updated atom fields (category = News$,, channelId = None,, description = Some( "description" ),, duration = Some( 1 ),, legallySensitive = None,, license = None,, source = Some( "source" ),, title = "title",, youtubeCategoryId = None,, youtubeTitle = "title")"""
)
}

test("Diff output when description changes") {
UpdateAtomCommand.createDiffString(mediaAtomFixture, mediaAtomFixture.copy(description = Some("New description"))) must be(
"Updated atom fields (MediaAtom( ..., description = Some( \u001B\"description\"\u001B -> \u001B\"New description\"\u001B ) ))"
)
}
}

0 comments on commit 261f1d9

Please sign in to comment.