Skip to content

Commit

Permalink
Merge e4d31b7 into 523bbf7
Browse files Browse the repository at this point in the history
  • Loading branch information
johnduffell committed Aug 10, 2018
2 parents 523bbf7 + e4d31b7 commit 8e41073
Show file tree
Hide file tree
Showing 47 changed files with 305 additions and 188 deletions.
25 changes: 22 additions & 3 deletions build.sbt
Expand Up @@ -88,6 +88,16 @@ lazy val salesforce = all(project in file("lib/salesforce"))
libraryDependencies ++= Seq(okhttp3, logging, scalaz, playJson, scalatest)
)

lazy val `update-sf-identityid` = all(project in file("lib/sf/update-sf-identityid"))
.dependsOn(
salesforce % "compile->compile;test->test",
effects % "test->test",
testDep
)
.settings(
libraryDependencies ++= Seq(okhttp3, logging, scalaz, playJson, scalatest)
)

lazy val restHttp = all(project in file("lib/restHttp"))
.settings(
libraryDependencies ++= Seq(okhttp3, logging, scalaz, playJson, scalatest)
Expand Down Expand Up @@ -160,12 +170,21 @@ lazy val root = all(project in file(".")).enablePlugins(RiffRaffArtifact).aggreg
s3ConfigValidator,
`new-product-api`,
`effects-sqs`,
`effects-ses`
`effects-ses`,
`update-sf-identityid`
).dependsOn(zuora, handler, effectsDepIncludingTestFolder, testDep)

lazy val `identity-backfill` = all(project in file("handlers/identity-backfill")) // when using the "project identity-backfill" command it uses the lazy val name
.enablePlugins(RiffRaffArtifact)
.dependsOn(zuora, salesforce, handler, effectsDepIncludingTestFolder, testDep, salesforce % "test->test")
.dependsOn(
zuora,
salesforce,
handler,
effectsDepIncludingTestFolder,
testDep,
salesforce % "test->test",
`update-sf-identityid` % "compile->compile;test->test"
)

lazy val `digital-subscription-expiry` = all(project in file("handlers/digital-subscription-expiry"))
.enablePlugins(RiffRaffArtifact)
Expand All @@ -189,7 +208,7 @@ lazy val `zuora-retention` = all(project in file("handlers/zuora-retention"))

lazy val `sf-contact-merge` = all(project in file("handlers/sf-contact-merge"))
.enablePlugins(RiffRaffArtifact)
.dependsOn(zuora, salesforce, handler, effectsDepIncludingTestFolder, testDep)
.dependsOn(zuora, salesforce, handler, effectsDepIncludingTestFolder, testDep, `update-sf-identityid` % "compile->compile;test->test")

lazy val `cancellation-sf-cases` = all(project in file("handlers/cancellation-sf-cases"))
.enablePlugins(RiffRaffArtifact)
Expand Down
@@ -1,12 +1,13 @@
package com.gu.identity

import com.gu.identity.GetByEmail.RawWireModel.{User, UserResponse}
import com.gu.identityBackfill.Types.{EmailAddress, IdentityId}
import com.gu.identityBackfill.Types.EmailAddress
import com.gu.identityBackfill.salesforce.UpdateSalesforceIdentityId.IdentityId
import com.gu.util.config.ConfigLocation
import okhttp3.{HttpUrl, Request, Response}
import play.api.libs.json.{Json, Reads}
import scalaz.{-\/, \/, \/-}
import scalaz.syntax.std.either._
import scalaz.{-\/, \/, \/-}

object GetByEmail {

Expand Down
Expand Up @@ -6,19 +6,22 @@ import com.amazonaws.services.lambda.runtime.Context
import com.gu.effects.{GetFromS3, RawEffects}
import com.gu.identity.{GetByEmail, IdentityConfig}
import com.gu.identityBackfill.TypeConvert._
import com.gu.identityBackfill.Types.{EmailAddress, IdentityId}
import com.gu.identityBackfill.Types.EmailAddress
import com.gu.identityBackfill.salesforce.ContactSyncCheck.RecordTypeId
import com.gu.identityBackfill.salesforce.UpdateSalesforceIdentityId.IdentityId
import com.gu.identityBackfill.salesforce._
import com.gu.identityBackfill.zuora.{AddIdentityIdToAccount, CountZuoraAccountsForIdentityId, GetZuoraAccountsForEmail, GetZuoraSubTypeForAccount}
import com.gu.salesforce.auth.SalesforceAuthenticate
import com.gu.salesforce.TypesForSFEffectsData.SFContactId
import com.gu.salesforce.auth.SalesforceAuthenticate.SFAuthConfig
import com.gu.salesforce.auth.{SalesforceAuthenticate, SalesforceRestRequestMaker}
import com.gu.util.apigateway.ApiGatewayHandler.{LambdaIO, Operation}
import com.gu.util.apigateway.ResponseModels.ApiResponse
import com.gu.util.apigateway.{ApiGatewayHandler, ApiGatewayResponse}
import com.gu.util.config.LoadConfigModule.StringFromS3
import com.gu.util.config.{LoadConfigModule, Stage}
import com.gu.util.reader.Types._
import com.gu.util.resthttp.RestRequestMaker.Requests
import com.gu.util.resthttp.HttpOp
import com.gu.util.resthttp.RestRequestMaker.{PatchRequest, Requests}
import com.gu.util.resthttp.Types.ClientFailableOp
import com.gu.util.zuora.{ZuoraQuery, ZuoraRestConfig, ZuoraRestRequestMaker}
import okhttp3.{Request, Response}
Expand Down Expand Up @@ -50,7 +53,10 @@ object Handler {
val zuoraQuerier = ZuoraQuery(zuoraRequests)
val getByEmail: EmailAddress => GetByEmail.ApiError \/ IdentityId = GetByEmail(response, identityConfig)
val countZuoraAccounts: IdentityId => ClientFailableOp[Int] = CountZuoraAccountsForIdentityId(zuoraQuerier)
lazy val sfRequests: ApiGatewayOp[Requests] = SalesforceAuthenticate(response, sfConfig)

lazy val sfAuth = SalesforceAuthenticate.doAuth(response, sfConfig)
lazy val sfRequests = sfAuth.map(s => SalesforceRestRequestMaker(s, response))
lazy val sfPatch = sfAuth.map(s => HttpOp(response).setupRequest(SalesforceRestRequestMaker.patch(s)))

Operation(
steps = IdentityBackfillSteps(
Expand All @@ -62,12 +68,12 @@ object Handler {
syncableSFToIdentity(sfRequests, stage)
),
AddIdentityIdToAccount(zuoraRequests),
updateSalesforceIdentityId(sfRequests)
updateSalesforceIdentityId(sfPatch)
),
healthcheck = () => Healthcheck(
getByEmail,
countZuoraAccounts,
sfRequests
sfAuth
)
)
}
Expand All @@ -92,22 +98,22 @@ object Handler {
mappings.get(stage).toApiGatewayContinueProcessing(ApiGatewayResponse.internalServerError(s"missing standard record type for stage $stage"))
}

def syncableSFToIdentity(sfRequests: ApiGatewayOp[Requests], stage: Stage)(sFContactId: Types.SFContactId): ApiGatewayOp[Unit] =
def syncableSFToIdentity(sfRequests: ApiGatewayOp[Requests], stage: Stage)(sFContactId: SFContactId): ApiGatewayOp[Unit] =
for {
sfRequests <- sfRequests
standardRecordType <- standardRecordTypeForStage(stage)
syncable <- SyncableSFToIdentity(standardRecordType)(sfRequests)(sFContactId)
} yield syncable

def updateSalesforceIdentityId(
sfRequests: ApiGatewayOp[Requests]
sfRequests: ApiGatewayOp[HttpOp[PatchRequest]]
)(
sFContactId: Types.SFContactId,
sFContactId: SFContactId,
identityId: IdentityId
): ApiGatewayOp[Unit] =
for {
sfRequests <- sfRequests
_ <- UpdateSalesforceIdentityId(sfRequests)(sFContactId, identityId).toApiGatewayOp("zuora issue")
_ <- UpdateSalesforceIdentityId.set(sfRequests).runRequestMultiArg(sFContactId, identityId).toApiGatewayOp("zuora issue")
} yield ()

}
Expand Down
Expand Up @@ -2,15 +2,17 @@ package com.gu.identityBackfill

import com.gu.identityBackfill.IdentityBackfillSteps.WireModel.IdentityBackfillRequest
import com.gu.identityBackfill.PreReqCheck.PreReqResult
import com.gu.identityBackfill.TypeConvert._
import com.gu.identityBackfill.Types._
import com.gu.identityBackfill.salesforce.UpdateSalesforceIdentityId.IdentityId
import com.gu.salesforce.TypesForSFEffectsData.SFContactId
import com.gu.util.Logging
import com.gu.util.apigateway.ResponseModels.ApiResponse
import com.gu.util.apigateway.{ApiGatewayRequest, ApiGatewayResponse}
import com.gu.util.reader.Types.ApiGatewayOp._
import com.gu.util.reader.Types._
import com.gu.util.resthttp.Types.ClientFailableOp
import play.api.libs.json.{Json, Reads}
import ApiGatewayOp._
import TypeConvert._

object IdentityBackfillSteps extends Logging {

Expand Down
Expand Up @@ -11,10 +11,12 @@ import com.gu.util.reader.Types._
import com.gu.util.resthttp.Types.ClientFailableOp
import scalaz.\/
import TypeConvert._
import com.gu.identityBackfill.salesforce.UpdateSalesforceIdentityId.IdentityId
import com.gu.salesforce.TypesForSFEffectsData.SFContactId

object PreReqCheck {

case class PreReqResult(zuoraAccountId: Types.AccountId, sFContactId: Types.SFContactId, requiredIdentityId: Types.IdentityId)
case class PreReqResult(zuoraAccountId: Types.AccountId, sFContactId: SFContactId, requiredIdentityId: IdentityId)

def apply(
getByEmail: EmailAddress => \/[GetByEmail.ApiError, IdentityId],
Expand Down
@@ -1,10 +1,11 @@
package com.gu.identityBackfill

import com.gu.identityBackfill.salesforce.UpdateSalesforceIdentityId.IdentityId
import com.gu.salesforce.TypesForSFEffectsData.SFContactId

object Types {

case class EmailAddress(value: String)
case class IdentityId(value: String)
case class SFContactId(value: String)
case class AccountId(value: String)

case class ZuoraAccountIdentitySFContact(
Expand Down
Expand Up @@ -2,8 +2,8 @@ package com.gu.identityBackfill.salesforce

import com.gu.i18n.CountryGroup
import com.gu.identityBackfill.TypeConvert._
import com.gu.identityBackfill.Types.SFContactId
import com.gu.identityBackfill.salesforce.ContactSyncCheck.RecordTypeId
import com.gu.salesforce.TypesForSFEffectsData.SFContactId
import com.gu.util.apigateway.ApiGatewayResponse
import com.gu.util.reader.Types.ApiGatewayOp._
import com.gu.util.resthttp.RestRequestMaker
Expand Down

This file was deleted.

@@ -1,7 +1,7 @@
package com.gu.identityBackfill.zuora

import com.gu.identityBackfill.Types
import com.gu.identityBackfill.Types.{AccountId, IdentityId}
import com.gu.identityBackfill.Types.AccountId
import com.gu.identityBackfill.salesforce.UpdateSalesforceIdentityId.IdentityId
import com.gu.util.resthttp.RestRequestMaker.Requests
import com.gu.util.resthttp.Types.ClientFailableOp
import play.api.libs.json.{JsSuccess, Json, Reads}
Expand All @@ -11,7 +11,7 @@ object AddIdentityIdToAccount {
case class WireRequest(IdentityId__c: String)
implicit val writes = Json.writes[WireRequest]

def reqFromIdentityId(id: Types.IdentityId): WireRequest = {
def reqFromIdentityId(id: IdentityId): WireRequest = {
WireRequest(id.value)
}

Expand Down
@@ -1,6 +1,6 @@
package com.gu.identityBackfill.zuora

import com.gu.identityBackfill.Types.IdentityId
import com.gu.identityBackfill.salesforce.UpdateSalesforceIdentityId.IdentityId
import com.gu.util.resthttp.Types.ClientFailableOp
import com.gu.util.zuora.SafeQueryBuilder.Implicits._
import com.gu.util.zuora.ZuoraQuery.ZuoraQuerier
Expand Down
@@ -1,6 +1,8 @@
package com.gu.identityBackfill.zuora

import com.gu.identityBackfill.Types._
import com.gu.identityBackfill.salesforce.UpdateSalesforceIdentityId.IdentityId
import com.gu.salesforce.TypesForSFEffectsData.SFContactId
import com.gu.util.resthttp.Types.ClientFailableOp
import com.gu.util.zuora.SafeQueryBuilder.Implicits._
import com.gu.util.zuora.ZuoraQuery.ZuoraQuerier
Expand Down
@@ -1,7 +1,8 @@
package com.gu.identity

import com.gu.effects.{GetFromS3, RawEffects}
import com.gu.identityBackfill.Types.{EmailAddress, IdentityId}
import com.gu.identityBackfill.Types.EmailAddress
import com.gu.identityBackfill.salesforce.UpdateSalesforceIdentityId.IdentityId
import com.gu.test.EffectsTest
import com.gu.util.config.{LoadConfigModule, Stage}
import org.scalatest.{FlatSpec, Matchers}
Expand Down
Expand Up @@ -4,7 +4,8 @@ import com.gu.effects.TestingRawEffects
import com.gu.effects.TestingRawEffects.HTTPResponse
import com.gu.identity.GetByEmail.{NotFound, NotValidated}
import com.gu.identity.GetByEmailTest.{NotFoundTestData, NotValidatedTestData, TestData}
import com.gu.identityBackfill.Types.{EmailAddress, IdentityId}
import com.gu.identityBackfill.Types.EmailAddress
import com.gu.identityBackfill.salesforce.UpdateSalesforceIdentityId.IdentityId
import org.scalatest.{FlatSpec, Matchers}
import scalaz.{-\/, \/, \/-}

Expand Down
Expand Up @@ -3,13 +3,14 @@ package com.gu.identityBackfill
import com.gu.identity.GetByEmail
import com.gu.identity.GetByEmail.{NotFound, NotValidated}
import com.gu.identityBackfill.PreReqCheck.PreReqResult
import com.gu.identityBackfill.Types.{IdentityId, _}
import com.gu.identityBackfill.Types._
import com.gu.identityBackfill.salesforce.UpdateSalesforceIdentityId.IdentityId
import com.gu.identityBackfill.zuora.GetZuoraSubTypeForAccount.ReaderType
import com.gu.salesforce.TypesForSFEffectsData.SFContactId
import com.gu.util.apigateway.ApiGatewayResponse
import com.gu.util.reader.Types.ApiGatewayOp
import org.scalatest.{FlatSpec, Matchers}
import ApiGatewayOp.{ContinueProcessing, ReturnWithResponse}
import com.gu.util.reader.Types.ApiGatewayOp.{ContinueProcessing, ReturnWithResponse}
import com.gu.util.resthttp.Types.ClientSuccess
import org.scalatest.{FlatSpec, Matchers}

class PreReqCheckTest extends FlatSpec with Matchers {

Expand Down
@@ -1,7 +1,9 @@
package com.gu.identityBackfill

import com.gu.identityBackfill.StepsData._
import com.gu.identityBackfill.Types.{IdentityId, _}
import com.gu.identityBackfill.Types._
import com.gu.identityBackfill.salesforce.UpdateSalesforceIdentityId.IdentityId
import com.gu.salesforce.TypesForSFEffectsData.SFContactId
import com.gu.util.apigateway.ResponseModels.ApiResponse
import com.gu.util.apigateway.{ApiGatewayRequest, ApiGatewayResponse}
import com.gu.util.reader.Types.ApiGatewayOp
Expand Down
@@ -1,23 +1,21 @@
package com.gu.identityBackfill.salesforce.getContact

import com.gu.effects.{GetFromS3, RawEffects}
import com.gu.identityBackfill.Types.SFContactId
import com.gu.identityBackfill.TypeConvert._
import com.gu.identityBackfill.salesforce.GetSFContactSyncCheckFields.ContactSyncCheckFields
import com.gu.identityBackfill.salesforce.{DevSFEffects, GetSFContactSyncCheckFields}
import com.gu.salesforce.dev.SFEffectsData
import com.gu.test.EffectsTest
import org.scalatest.{FlatSpec, Matchers}
import scalaz.\/-
import com.gu.identityBackfill.TypeConvert._

class GetSFContactSyncCheckFieldsEffectsTest extends FlatSpec with Matchers {

it should "get auth SF correctly" taggedAs EffectsTest in {

val testContact = SFContactId("0036E00000NLzPkQAL")

val actual = for {
auth <- DevSFEffects(GetFromS3.fetchString, RawEffects.response)
result <- GetSFContactSyncCheckFields(auth)(testContact).toApiGatewayOp("failed")
result <- GetSFContactSyncCheckFields(auth)(SFEffectsData.testContactHasName).toApiGatewayOp("failed")
} yield result

actual.toDisjunction should be(\/-(ContactSyncCheckFields(None, "One", "Day", None)))
Expand Down
Expand Up @@ -2,9 +2,9 @@ package com.gu.identityBackfill.salesforce.getContact

import com.gu.effects.TestingRawEffects
import com.gu.effects.TestingRawEffects.HTTPResponse
import com.gu.identityBackfill.Types.SFContactId
import com.gu.identityBackfill.salesforce.GetSFContactSyncCheckFields
import com.gu.identityBackfill.salesforce.GetSFContactSyncCheckFields.ContactSyncCheckFields
import com.gu.salesforce.TypesForSFEffectsData.SFContactId
import com.gu.salesforce.auth.SalesforceAuthenticate.SalesforceAuth
import com.gu.salesforce.auth.SalesforceRestRequestMaker
import com.gu.util.resthttp.Types.ClientSuccess
Expand Down

This file was deleted.

0 comments on commit 8e41073

Please sign in to comment.