<commit_before>package uk.ac.wellcome.messaging.sns

import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures}
import org.scalatest.{FunSpec, Matchers}
import uk.ac.wellcome.json.JsonUtil._
import uk.ac.wellcome.json.utils.JsonAssertions
import uk.ac.wellcome.messaging.test.fixtures.SNS
import uk.ac.wellcome.messaging.test.fixtures.SNS.Topic

class SNSWriterTest
    extends FunSpec
    with ScalaFutures
    with Matchers
    with SNS
    with IntegrationPatience
    with JsonAssertions {

  it("sends a message to SNS and returns a PublishAttempt") {
    withLocalSnsTopic { topic =>
      withSNSWriter(topic) { snsWriter =>
        val message = "sns-writer-test-message"
        val subject = "sns-writer-test-subject"
        val futurePublishAttempt = snsWriter.writeMessage(
          message = message,
          subject = subject
        )

        whenReady(futurePublishAttempt) { publishAttempt =>
          val messages = listMessagesReceivedFromSNS(topic)
          messages should have size 1
          messages.head.message shouldBe message
          messages.head.subject shouldBe subject
          publishAttempt.id should be(Right(messages.head.message))
        }
      }
    }
  }

  case class Shape(sides: Int, colour: String)

  it("encodes a case class as JSON before sending it to SNS") {
    withLocalSnsTopic { topic =>
      withSNSWriter(topic) { snsWriter =>
        val message = Shape(sides = 5, colour = "red")

        val futurePublishAttempt = snsWriter.writeMessage(
          message = message,
          subject = "shape sorter subject"
        )

        whenReady(futurePublishAttempt) { publishAttempt =>
          val messages = listMessagesReceivedFromSNS(topic)
          messages should have size 1
          messages.head.message shouldBe message

          assertJsonStringsAreEqual(
            messages.head.message,
            toJson(message).get
          )
        }
      }
    }
  }

  it("returns a failed Future if it fails to publish the message") {
    withSNSWriter(Topic("does-not-exist")) { snsWriter =>
      val futurePublishAttempt =
        snsWriter.writeMessage(message = "someMessage", subject = "subject")

      whenReady(futurePublishAttempt.failed) { exception =>
        exception.getMessage should not be empty
      }
    }
  }
}
<commit_msg>Fix the SNS writer test<commit_after>package uk.ac.wellcome.messaging.sns

import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures}
import org.scalatest.{FunSpec, Matchers}
import uk.ac.wellcome.json.JsonUtil._
import uk.ac.wellcome.json.utils.JsonAssertions
import uk.ac.wellcome.messaging.test.fixtures.SNS
import uk.ac.wellcome.messaging.test.fixtures.SNS.Topic

class SNSWriterTest
    extends FunSpec
    with ScalaFutures
    with Matchers
    with SNS
    with IntegrationPatience
    with JsonAssertions {

  it("sends a message to SNS and returns a PublishAttempt") {
    withLocalSnsTopic { topic =>
      withSNSWriter(topic) { snsWriter =>
        val message = "sns-writer-test-message"
        val subject = "sns-writer-test-subject"
        val futurePublishAttempt = snsWriter.writeMessage(
          message = message,
          subject = subject
        )

        whenReady(futurePublishAttempt) { publishAttempt =>
          val messages = listMessagesReceivedFromSNS(topic)
          messages should have size 1
          messages.head.message shouldBe message
          messages.head.subject shouldBe subject
          publishAttempt.id should be(Right(messages.head.message))
        }
      }
    }
  }

  case class Shape(sides: Int, colour: String)

  it("encodes a case class as JSON before sending it to SNS") {
    withLocalSnsTopic { topic =>
      withSNSWriter(topic) { snsWriter =>
        val message = Shape(sides = 5, colour = "red")

        val futurePublishAttempt = snsWriter.writeMessage(
          message = message,
          subject = "shape sorter subject"
        )

        whenReady(futurePublishAttempt) { publishAttempt =>
          val messages = listMessagesReceivedFromSNS(topic)
          messages should have size 1

          assertJsonStringsAreEqual(
            messages.head.message,
            toJson(message).get
          )
        }
      }
    }
  }

  it("returns a failed Future if it fails to publish the message") {
    withSNSWriter(Topic("does-not-exist")) { snsWriter =>
      val futurePublishAttempt =
        snsWriter.writeMessage(message = "someMessage", subject = "subject")

      whenReady(futurePublishAttempt.failed) { exception =>
        exception.getMessage should not be empty
      }
    }
  }
}

{'fraction_non_alphanumeric': 0.08252322315834953, 'fraction_numerical': 0.0012961762799740765, 'mean_word_length': 2.622848200312989, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3320182', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1303, 'n_words': 307}