diff --git a/app/model/commands/UpdateAtomCommand.scala b/app/model/commands/UpdateAtomCommand.scala index d80fdd8bb..6e9e60754 100644 --- a/app/model/commands/UpdateAtomCommand.scala +++ b/app/model/commands/UpdateAtomCommand.scala @@ -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 @@ -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 diff --git a/test/model/commands/UpdateAtomCommandTest.scala b/test/model/commands/UpdateAtomCommandTest.scala new file mode 100644 index 000000000..8f010d7bb --- /dev/null +++ b/test/model/commands/UpdateAtomCommandTest.scala @@ -0,0 +1,57 @@ +package model.commands + +import com.gu.media.model.{Category, ContentChangeDetails, MediaAtom} +import model.commands.UpdateAtomCommand.createDiffString +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("Example 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, + expiryDate = None, + legallySensitive = None, + sensitive = None, + optimisedForWeb = None, + composerCommentsEnabled = None, + suppressRelatedContent = None + ) + + test("Diff output when nothing changes") { + createDiffString(mediaAtomFixture, mediaAtomFixture) must be("Updated atom fields (category = News$,, channelId = None,, description = Some( \"Example description\" ),, duration = Some( 1 ),, legallySensitive = None,, license = None,, source = Some( \"source\" ),, title = \"title\",, youtubeCategoryId = None,, youtubeTitle = \"title\")") + } + + test("Diff output when description changes") { + createDiffString(mediaAtomFixture, mediaAtomFixture.copy(description = Some("New description"))) must be( + "Updated atom fields (MediaAtom( ..., description = Some( \u001B\"Example description\"\u001B -> \u001B\"New description\"\u001B ) ))" + ) + } + + test("Diff output when description is removed") { + createDiffString(mediaAtomFixture, mediaAtomFixture.copy(description = None)) must be( + "Updated atom fields (MediaAtom( ..., description = \u001BSome( \"Example description\" )\u001B -> \u001BNone\u001B ))" + ) + } +}