Skip to content

Commit

Permalink
Capture behaviour of old diff library
Browse files Browse the repository at this point in the history
You can see that the diffs were not perfect! If there was no change, double commas showed,
and if there _was_ a diff, ANSI colour codes were only partially removed, leaving behind
a 0x1B ('ANSI Escape') character.

https://en.wikipedia.org/wiki/ANSI_escape_code#C0_control_codes
  • Loading branch information
rtyley committed Jan 31, 2024
1 parent 1eb384c commit 5b081ad
Show file tree
Hide file tree
Showing 2 changed files with 60 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
57 changes: 57 additions & 0 deletions test/model/commands/UpdateAtomCommandTest.scala
Original file line number Diff line number Diff line change
@@ -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 ))"
)
}
}

0 comments on commit 5b081ad

Please sign in to comment.