-
Notifications
You must be signed in to change notification settings - Fork 5
/
StepsTest.scala
96 lines (74 loc) · 3.36 KB
/
StepsTest.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.gu.identityBackfill
import com.gu.identityBackfill.StepsData._
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
import com.gu.util.reader.Types.ApiGatewayOp.{ContinueProcessing, ReturnWithResponse}
import com.gu.util.resthttp.Types.ClientSuccess
import org.scalatest.{FlatSpec, Matchers}
class StepsTest extends FlatSpec with Matchers {
class StepsWithMocks {
var zuoraUpdate: Option[(AccountId, IdentityId)] = None // !!
var salesforceUpdate: Option[(SFContactId, IdentityId)] = None // !!
var emailToCheck: Option[EmailAddress] = None // !!
def getSteps(succeed: Boolean = true): ApiGatewayRequest => ApiResponse = {
val preReqCheck: EmailAddress => ApiGatewayOp[PreReqCheck.PreReqResult] = { email =>
emailToCheck = Some(email)
if (succeed)
ContinueProcessing(PreReqCheck.PreReqResult(AccountId("acc"), SFContactId("sf"), IdentityId("asdf")))
else
ReturnWithResponse(ApiGatewayResponse.notFound("dummy"))
}
IdentityBackfillSteps(
preReqCheck,
updateZuoraIdentityId = (accountId, identityId) => {
zuoraUpdate = Some((accountId, identityId))
ClientSuccess(())
},
updateSalesforceIdentityId = (sFContactId, identityId) => {
salesforceUpdate = Some((sFContactId, identityId))
ContinueProcessing(())
}
)
}
}
it should "go through a happy case in real mode" in {
val stepsWithMocks = new StepsWithMocks
import stepsWithMocks._
val result =
getSteps()(ApiGatewayRequest(None, Some(identityBackfillRequest(false)), None))
val expectedResult = ApiGatewayResponse.successfulExecution
result should be(expectedResult)
zuoraUpdate should be(Some((AccountId("acc"), IdentityId("asdf"))))
salesforceUpdate should be(Some((SFContactId("sf"), IdentityId("asdf"))))
emailToCheck should be(Some(EmailAddress("email@address")))
}
it should "go through a happy case in dry run mode without calling update" in {
val stepsWithMocks = new StepsWithMocks
import stepsWithMocks._
val result =
getSteps()(ApiGatewayRequest(None, Some(identityBackfillRequest(true)), None))
val expectedResult = ApiGatewayResponse.noActionRequired("DRY RUN requested! skipping to the end")
result should be(expectedResult)
zuoraUpdate should be(None)
salesforceUpdate should be(None)
emailToCheck should be(Some(EmailAddress("email@address")))
}
it should "go through a already got identity (according to the zuora query bu identity id) case without calling update even not in dry run mode" in {
val stepsWithMocks = new StepsWithMocks
import stepsWithMocks._
val result =
getSteps(false)(ApiGatewayRequest(None, Some(identityBackfillRequest(false)), None))
val expectedResult = ApiGatewayResponse.notFound("dummy")
result should be(expectedResult)
zuoraUpdate should be(None)
salesforceUpdate should be(None)
}
}
object StepsData {
def identityBackfillRequest(dryRun: Boolean): String =
s"""{"emailAddress": "email@address", "dryRun": $dryRun}""""
}