|
| 1 | +package test |
| 2 | + |
| 3 | +import play.api.test._ |
| 4 | +import play.api.test.Helpers._ |
| 5 | +import org.scalatest.Matchers |
| 6 | +import org.scalatest.FlatSpec |
| 7 | +import common.UsesElasticSearch |
| 8 | + |
| 9 | +class ArchiveControllerTest extends FlatSpec with Matchers with UsesElasticSearch { |
| 10 | + |
| 11 | + |
| 12 | + "Archive Controller" should "return a HTTP 303 when it finds a match in DynamoDB" in Fake { |
| 13 | + val url = "www.theguardian.com/media/emailservices/article/0,,1694396,.html" |
| 14 | + val result = controllers.ArchiveController.lookup(url)(TestRequest()) |
| 15 | + header("Location", result) should be(Some("http://www.theguardian.com/media/2006/jan/25/1")) |
| 16 | + status(result) should be(303) |
| 17 | + } |
| 18 | + |
| 19 | + it should "return a HTTP 200 when it finds a resource in S3" in Fake { |
| 20 | + val url = "travel.theguardian.com/askatraveller/0,,345059,00.html" |
| 21 | + val result = controllers.ArchiveController.lookup(url)(TestRequest()) |
| 22 | + status(result) should be(200) |
| 23 | + contentType(result) should be("text/html") |
| 24 | + } |
| 25 | + |
| 26 | + it should "return a HTTP 404 when it can not find a resource" in Fake { |
| 27 | + val url = "www.theguardian.com/i/am/not/here" |
| 28 | + val result = controllers.ArchiveController.lookup(url)(TestRequest()) |
| 29 | + status(result) should be(404) |
| 30 | + } |
| 31 | + |
| 32 | + it should "fetch the HTML of a valid archived URL" in Fake { |
| 33 | + val result = controllers.ArchiveController.isArchived("travel.theguardian.com/askatraveller/0,,345059,00.html") |
| 34 | + result.get should include ("<title>Ask a traveller | guardian.co.uk Travel</title>") |
| 35 | + } |
| 36 | + |
| 37 | + it should "return None for a invalid archive URL" in Fake { |
| 38 | + val result = controllers.ArchiveController.isArchived("not/here") |
| 39 | + result should be(None) |
| 40 | + } |
| 41 | + |
| 42 | + it should "fetch the destination of a valid redirected URL" in Fake { |
| 43 | + val result = controllers.ArchiveController.isRedirect("www.theguardian.com/media/emailservices/article/0,,1694396,.html") |
| 44 | + result should be (Some("http://www.theguardian.com/media/2006/jan/25/1")) |
| 45 | + } |
| 46 | + |
| 47 | + it should "return Noen for a path that has not been redirected" in Fake { |
| 48 | + val result = controllers.ArchiveController.isRedirect("not/here") |
| 49 | + result should be(None) |
| 50 | + } |
| 51 | + |
| 52 | +} |
0 commit comments