-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* MIB-153: backend connector * MIB-142_V3: unused import * MIB-142_V3: only reset when persistence succeed * MIB-153: remove chance of throwing in mib generator * MIB-153: little cleaning up * MIB-153: add declarationId retrieved from backend * MIB-153: cleaning up * MIB-153: renaming * MIB-153: unused import * MIB-153: rename * MIB-153: inline 2 vals * MIB-153: inline one more val * [MIBM-153][PH] fix deprecation warning * [MIBM-153][PH] rename makePayment method Co-authored-by: Paul Hodgson <[email protected]>
- Loading branch information
1 parent
f067c39
commit c74c4ac
Showing
18 changed files
with
311 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
app/uk/gov/hmrc/merchandiseinbaggagefrontend/connectors/MibConnector.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2020 HM Revenue & Customs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package uk.gov.hmrc.merchandiseinbaggagefrontend.connectors | ||
|
||
import javax.inject.{Inject, Named, Singleton} | ||
import uk.gov.hmrc.http.{HeaderCarrier, HttpClient} | ||
import uk.gov.hmrc.merchandiseinbaggagefrontend.config.MibConfiguration | ||
import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.{Declaration, DeclarationId} | ||
import uk.gov.hmrc.http.HttpReads.Implicits.readFromJson | ||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
@Singleton | ||
class MibConnector @Inject()(httpClient: HttpClient, @Named("mibBackendBaseUrl") base: String) extends MibConfiguration { | ||
|
||
def persistDeclaration(declaration: Declaration)(implicit hc: HeaderCarrier, ec: ExecutionContext): Future[DeclarationId] = | ||
httpClient.POST[Declaration, DeclarationId](s"$base$declarationsUrl", declaration) | ||
|
||
def findDeclaration(declarationId: DeclarationId)(implicit hc: HeaderCarrier, ec: ExecutionContext): Future[Declaration] = | ||
httpClient.GET[Declaration](s"$base$declarationsUrl/${declarationId.value}") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
app/uk/gov/hmrc/merchandiseinbaggagefrontend/model/core/DeclarationId.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright 2020 HM Revenue & Customs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package uk.gov.hmrc.merchandiseinbaggagefrontend.model.core | ||
|
||
import play.api.libs.json._ | ||
import uk.gov.hmrc.merchandiseinbaggagefrontend.utils.ValueClassFormat | ||
|
||
case class DeclarationId(value: String) | ||
object DeclarationId { | ||
implicit val format: Format[DeclarationId] = ValueClassFormat.format(value => DeclarationId.apply(value))(_.value) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
test/uk/gov/hmrc/merchandiseinbaggagefrontend/connectors/MibConnectorSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2020 HM Revenue & Customs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package uk.gov.hmrc.merchandiseinbaggagefrontend.connectors | ||
|
||
import uk.gov.hmrc.http.HeaderCarrier | ||
import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.DeclarationId | ||
import uk.gov.hmrc.merchandiseinbaggagefrontend.stubs.MibBackendStub._ | ||
import uk.gov.hmrc.merchandiseinbaggagefrontend.{BaseSpecWithApplication, CoreTestData, WireMockSupport} | ||
|
||
import scala.concurrent.ExecutionContext.Implicits.global | ||
|
||
class MibConnectorSpec extends BaseSpecWithApplication with CoreTestData with WireMockSupport { | ||
|
||
val client = app.injector.instanceOf[MibConnector] | ||
implicit val hc = HeaderCarrier() | ||
|
||
"send a declaration to backend to be persisted" in { | ||
givenDeclarationIsPersistedInBackend(wireMockServer, declaration) | ||
|
||
client.persistDeclaration(declaration).futureValue mustBe stubbedDeclarationId | ||
} | ||
|
||
"find a persisted declaration from backend by declarationId" in { | ||
val id = DeclarationId("1234") | ||
|
||
givenPersistedDeclarationIsFound(wireMockServer, declaration, id) | ||
|
||
client.findDeclaration(id).futureValue mustBe declaration | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.