<commit_before>/*
 * Copyright 2018 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.selfservicetimetopay.testonly

import com.google.inject.Singleton
import play.api.Logger
import play.api.libs.json.{JsObject, JsValue, Json}
import uk.gov.hmrc.play.config.ServicesConfig
import uk.gov.hmrc.http.HeaderCarrier
import uk.gov.hmrc.selfservicetimetopay.config.WSHttp

import scala.concurrent.{ExecutionContext, Future}
import scala.util.Random


@Singleton
class SaStubConnector extends ServicesConfig {

  def setTaxpayerResponse(tu: TestUser)(implicit hc: HeaderCarrier, ec: ExecutionContext): Future[Unit] = {


    val predefinedResponse: JsValue = Json.obj(
      "status" -> tu.saTaxpayerResponseStatusCode,
      "body" -> tu.saTaxpayer
    )
    val setTaxpayerUrl = s"$baseUrl/sa/individual/${tu.utr.v}/designatory-details/taxpayer"

    WSHttp
      .PATCH(setTaxpayerUrl, predefinedResponse)
      .map{
        r =>
          if(r.status != 200) throw new RuntimeException(s"Could not set up taxpayer in SA-STUB: ${tu.utr}")
          Logger.debug(s"Set up a predefined response in SA-STUB for ${tu.utr}")
      }
  }

  private lazy val baseUrl: String = baseUrl("sa-services")


}<commit_msg>[CC][SSTTP2-405]Fix for create user and sign in<commit_after>/*
 * Copyright 2018 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.selfservicetimetopay.testonly

import com.google.inject.Singleton
import play.api.Logger
import play.api.libs.json.{JsObject, JsValue, Json}
import uk.gov.hmrc.play.config.ServicesConfig
import uk.gov.hmrc.http.HeaderCarrier
import uk.gov.hmrc.selfservicetimetopay.config.WSHttp

import scala.concurrent.{ExecutionContext, Future}
import scala.util.Random


@Singleton
class SaStubConnector extends ServicesConfig {

  def setTaxpayerResponse(tu: TestUser)(implicit hc: HeaderCarrier, ec: ExecutionContext): Future[Unit] = {


    val predefinedResponse: JsValue = Json.obj(
      "status" -> tu.saTaxpayerResponseStatusCode,
      "body" -> tu.saTaxpayer
    )
    val setTaxpayerUrl = s"$baseUrl/sa/individual/${tu.utr.v}/designatory-details/taxpayer"

    WSHttp
      .POST(setTaxpayerUrl, predefinedResponse)
      .map{
        r =>
          if(r.status != 200) throw new RuntimeException(s"Could not set up taxpayer in SA-STUB: ${tu.utr}")
          Logger.debug(s"Set up a predefined response in SA-STUB for ${tu.utr}")
      }
  }

  private lazy val baseUrl: String = baseUrl("sa-services")


}
{'fraction_non_alphanumeric': 0.09833755987602141, 'fraction_numerical': 0.007326007326007326, 'mean_word_length': 3.7972972972972974, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '138953', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1071, 'n_words': 328}