Skip to content

Commit 425b841

Browse files
Merge pull request #1525 from guardian/vb/add-topic-title
Add optional title field to Topic case class on /device/register endpoint
2 parents 0fcd292 + 9564326 commit 425b841

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

common/src/main/scala/models/Topic.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import play.api.libs.json._
55
import cats.syntax.all._
66

77

8-
case class Topic(`type`: TopicType, name: String) {
8+
case class Topic(`type`: TopicType, name: String, title: Option[String] = None) {
99
override def toString: String = fullName
1010
def toFirebaseString: String = toString.replaceAll("/", "%")
1111
lazy val id: String = md5Hex(toString)

registration/test/registration/controllers/MainControllerSpec.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ class MainControllerSpec extends PlaySpecification with JsonMatchers with Mockit
4949
val Some(register) = route(app, FakeRequest(POST, "/legacy/device/register").withJsonBody(Json.parse(legacyAndroidRegistrationJson)))
5050
status(register) must equalTo(BAD_REQUEST)
5151
}
52+
53+
////// NEW ENDPOINT ///////
54+
55+
"new /device/register endpoint returns expected response" in new RegistrationsContext {
56+
val Some(result) = route(app, FakeRequest(POST, "/device/register").withJsonBody(Json.parse(newRegistrationJson)))
57+
println(Json.prettyPrint(Json.parse(contentAsString(result))))
58+
59+
status(result) must equalTo(OK)
60+
contentAsString(result) must /("provider" -> "Guardian")
61+
contentAsString(result) must /("deviceId" -> "TEST-TOKEN-ID")
62+
contentAsString(result) must /("platform" -> "ios")
63+
contentAsString(result) must (/("topics") andHave size(4))
64+
}
5265
}
5366

5467
trait RegistrationsContext extends RegistrationsBase with withMockedWSClient {

registration/test/registration/controllers/RegistrationsFixtures.scala

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ import cats.syntax.all._
77
import com.gu.DevIdentity
88
import db.{DatabaseConfig, JdbcConfig, RegistrationService}
99
import doobie.util.transactor.Transactor
10-
import error.NotificationsError
1110
import models.Provider.Unknown
1211
import models.TopicTypes.{Breaking, FootballMatch}
1312
import models._
1413
import play.api.ApplicationLoader.Context
1514
import play.api.{BuiltInComponents, Logger, Configuration => PlayConfig}
1615
import play.api.libs.ws.WSClient
17-
import providers.ProviderError
1816
import registration.RegistrationApplicationComponents
1917
import registration.services.NotificationRegistrar.RegistrarResponse
2018
import registration.services.topic.{TopicValidator, TopicValidatorError}
@@ -165,6 +163,37 @@ trait RegistrationsJson {
165163
|}
166164
""".stripMargin
167165

166+
val newRegistrationJson =
167+
"""
168+
|{
169+
| "deviceToken": "TEST-TOKEN-ID",
170+
| "platform": "ios",
171+
| "buildTier": "debug",
172+
| "appVersion": "1.0.0",
173+
| "topics": [
174+
| {
175+
| "name": "4501006",
176+
| "title": "Burnley vs Leeds (2025-10-18)",
177+
| "type": "football-match"
178+
| },
179+
| {
180+
| "name": "profile/jane-doe",
181+
| "title": "Jane Doe",
182+
| "type": "tag-contributor"
183+
| },
184+
| {
185+
| "name": "uk-sport",
186+
| "title": "UK sport notifications",
187+
| "type": "breaking"
188+
| },
189+
| {
190+
| "name": "uk",
191+
| "type": "breaking"
192+
| }
193+
| ]
194+
|}
195+
""".stripMargin
196+
168197
val registrationJson =
169198
"""
170199
|{

0 commit comments

Comments
 (0)