Skip to content

Commit

Permalink
setup TriggerThirdPartyEvent mutation
Browse files Browse the repository at this point in the history
* update Service and ServiceType
* create new adapter files
* convert TriggerCapiEventInput to TriggerThirdPartyInput
* create TriggerThirdPartyEvent.graphql in /mutations
  • Loading branch information
scottkicks committed Jul 13, 2023
1 parent df76cd4 commit 5c7a051
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Kickstarter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,11 @@
6078106F2A04191C0050D4F7 /* FirebaseAnalytics in Frameworks */ = {isa = PBXBuildFile; productRef = 6078106E2A04191C0050D4F7 /* FirebaseAnalytics */; };
608E7A5328ABDBAE00289E92 /* SetYourPasswordViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 608E7A5128ABD5E700289E92 /* SetYourPasswordViewController.swift */; };
608E7A5628ABE6CD00289E92 /* SetYourPasswordViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 608E7A5428ABE27400289E92 /* SetYourPasswordViewModel.swift */; };
6093098D2A6054CB004297AF /* GraphAPI.TriggerThirdPartyEventInput+TriggerThirdPartyEventInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6093098C2A6054CB004297AF /* GraphAPI.TriggerThirdPartyEventInput+TriggerThirdPartyEventInput.swift */; };
6093098F2A6054D8004297AF /* GraphAPI.TriggerThirdPartyEventInput+TriggerThirdPartyEventInputTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6093098E2A6054D8004297AF /* GraphAPI.TriggerThirdPartyEventInput+TriggerThirdPartyEventInputTests.swift */; };
609309912A60555F004297AF /* TriggerThirdPartyEventInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 609309902A60555F004297AF /* TriggerThirdPartyEventInput.swift */; };
609309932A605563004297AF /* TriggerThirdPartyEventInputTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 609309922A605563004297AF /* TriggerThirdPartyEventInputTests.swift */; };
609309952A6055A5004297AF /* TriggerThirdPartyEvent.graphql in Resources */ = {isa = PBXBuildFile; fileRef = 609309942A6055A5004297AF /* TriggerThirdPartyEvent.graphql */; };
60DA50EB28B689A4002E2DF1 /* SetYourPasswordViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60DA50E928B68990002E2DF1 /* SetYourPasswordViewModelTests.swift */; };
60DA50F128B6953A002E2DF1 /* SetYourPasswordViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60DA50EF28B69534002E2DF1 /* SetYourPasswordViewControllerTests.swift */; };
60DA50FE28C38DDB002E2DF1 /* AlamofireImage in Frameworks */ = {isa = PBXBuildFile; productRef = 60DA50FD28C38DDB002E2DF1 /* AlamofireImage */; };
Expand Down Expand Up @@ -2070,6 +2075,11 @@
606F2169299E8C9F00BA5CDF /* TriggerCapiEventInputTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TriggerCapiEventInputTests.swift; sourceTree = "<group>"; };
608E7A5128ABD5E700289E92 /* SetYourPasswordViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetYourPasswordViewController.swift; sourceTree = "<group>"; };
608E7A5428ABE27400289E92 /* SetYourPasswordViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetYourPasswordViewModel.swift; sourceTree = "<group>"; };
6093098C2A6054CB004297AF /* GraphAPI.TriggerThirdPartyEventInput+TriggerThirdPartyEventInput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "GraphAPI.TriggerThirdPartyEventInput+TriggerThirdPartyEventInput.swift"; sourceTree = "<group>"; };
6093098E2A6054D8004297AF /* GraphAPI.TriggerThirdPartyEventInput+TriggerThirdPartyEventInputTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "GraphAPI.TriggerThirdPartyEventInput+TriggerThirdPartyEventInputTests.swift"; sourceTree = "<group>"; };
609309902A60555F004297AF /* TriggerThirdPartyEventInput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TriggerThirdPartyEventInput.swift; sourceTree = "<group>"; };
609309922A605563004297AF /* TriggerThirdPartyEventInputTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TriggerThirdPartyEventInputTests.swift; sourceTree = "<group>"; };
609309942A6055A5004297AF /* TriggerThirdPartyEvent.graphql */ = {isa = PBXFileReference; lastKnownFileType = text; path = TriggerThirdPartyEvent.graphql; sourceTree = "<group>"; };
60DA50E928B68990002E2DF1 /* SetYourPasswordViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetYourPasswordViewModelTests.swift; sourceTree = "<group>"; };
60DA50EF28B69534002E2DF1 /* SetYourPasswordViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetYourPasswordViewControllerTests.swift; sourceTree = "<group>"; };
60DF50962A434E6B002C771F /* DashboardDeprecationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardDeprecationView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5807,6 +5817,7 @@
062868E526B999EF00EC5052 /* DeletePaymentSource.graphql */,
47D7D09526C2EA5200D2BAB5 /* SignInWithApple.graphql */,
606F2165299D456D00BA5CDF /* TriggerCapiEvent.graphql */,
609309942A6055A5004297AF /* TriggerThirdPartyEvent.graphql */,
8AC3E0F4269F48A400168BF8 /* UpdateBacking.graphql */,
06643F3926A5FF1C002C5997 /* UpdateUserAccount.graphql */,
06C38CB826A9D13400591CED /* UpdateUserProfile.graphql */,
Expand Down Expand Up @@ -6027,6 +6038,8 @@
47D7D09B26C2FA5F00D2BAB5 /* GraphAPI.SignInWithAppleInput+SignInWithAppleInputTests.swift */,
606F215D299D414800BA5CDF /* GraphAPI.TriggerCapiEventInput+TriggerCapiEventInput.swift */,
606F215A299D3EF800BA5CDF /* GraphAPI.TriggerCapiEventInput+TriggerCapiEventInputTests.swift */,
6093098C2A6054CB004297AF /* GraphAPI.TriggerThirdPartyEventInput+TriggerThirdPartyEventInput.swift */,
6093098E2A6054D8004297AF /* GraphAPI.TriggerThirdPartyEventInput+TriggerThirdPartyEventInputTests.swift */,
8AC3E10C269F4D4000168BF8 /* GraphAPI.UpdateBackingInput+UpdateBackingInput.swift */,
8AC3E111269F4DAF00168BF8 /* GraphAPI.UpdateBackingInput+UpdateBackingInputTests.swift */,
06643F3B26A61338002C5997 /* GraphAPI.UpdateUserAccountInput+UpdateUserAccountInput.swift */,
Expand Down Expand Up @@ -7119,6 +7132,8 @@
77C0818D245CBA1B004ABE88 /* SignInWithAppleInputTests.swift */,
606F2167299D45F900BA5CDF /* TriggerCapiEventInput.swift */,
606F2169299E8C9F00BA5CDF /* TriggerCapiEventInputTests.swift */,
609309902A60555F004297AF /* TriggerThirdPartyEventInput.swift */,
609309922A605563004297AF /* TriggerThirdPartyEventInputTests.swift */,
4753C76E264DAFD300BB10B6 /* PostCommentInput.swift */,
4753C78E264EE1B100BB10B6 /* PostCommentInputTests.swift */,
);
Expand Down Expand Up @@ -7558,6 +7573,7 @@
06DAAE5626AA3CCB00194E58 /* LocationFragment.graphql in Resources */,
06DAAE5326AA3CC300194E58 /* RewardFragment.graphql in Resources */,
47A662F126AF1FCC001CE7B1 /* WatchProject.graphql in Resources */,
609309952A6055A5004297AF /* TriggerThirdPartyEvent.graphql in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -8849,6 +8865,7 @@
20EB9313266030CB004FA1C8 /* PostCommentEnvelope.swift in Sources */,
D01588BD1EEB2ED7006E7684 /* ProjectStatsEnvelope.RewardDistributionLenses.swift in Sources */,
D01588611EEB2ED7006E7684 /* Config.swift in Sources */,
609309932A605563004297AF /* TriggerThirdPartyEventInputTests.swift in Sources */,
D64DDCE123564D3700DE0EA9 /* PaymentSourceTemplates.swift in Sources */,
D002CAE5218CF951009783F2 /* WatchProjectResponseEnvelope.swift in Sources */,
D0158A1C1EEB30A2006E7684 /* ProjectNotificationTemplates.swift in Sources */,
Expand All @@ -8871,6 +8888,7 @@
8AC3E0962698CF0600168BF8 /* ShippingRule+ShippingRuleFragment.swift in Sources */,
06FE2D7726CDB01E00A4C0F4 /* MockGraphQLClient.swift in Sources */,
D6C9A2541F758C7900981E64 /* GraphCategoryLenses.swift in Sources */,
6093098F2A6054D8004297AF /* GraphAPI.TriggerThirdPartyEventInput+TriggerThirdPartyEventInputTests.swift in Sources */,
D015883B1EEB2ED7006E7684 /* MimeType.swift in Sources */,
D01589931EEB2ED7006E7684 /* User.swift in Sources */,
D0158A271EEB30A2006E7684 /* ShippingRuleTemplates.swift in Sources */,
Expand All @@ -8883,10 +8901,12 @@
8AF34C742342CBC2000B211D /* UpdateBackingInput.swift in Sources */,
4778EE2126A200BE0059EA69 /* UserEnvelope+GraphUserEnvelope.swift in Sources */,
8ADCCCAE264C98A50079D308 /* Comment.swift in Sources */,
609309912A60555F004297AF /* TriggerThirdPartyEventInput.swift in Sources */,
D0158A2E1EEB30A2006E7684 /* User.AvatarTemplates.swift in Sources */,
D01588771EEB2ED7006E7684 /* FriendStatsEnvelope.swift in Sources */,
D015891D1EEB2ED7006E7684 /* ShippingRule.swift in Sources */,
D67B6CD6221F468100B63A6B /* Location+Encode.swift in Sources */,
6093098D2A6054CB004297AF /* GraphAPI.TriggerThirdPartyEventInput+TriggerThirdPartyEventInput.swift in Sources */,
8AC3E105269F4D1C00168BF8 /* GraphAPI.ApplePay+ApplePayParams.swift in Sources */,
D01588331EEB2ED7006E7684 /* Decodable.swift in Sources */,
06232D3E2795EC2C00A81755 /* Element+Helpers.swift in Sources */,
Expand Down
10 changes: 10 additions & 0 deletions KsApi/Service.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ public struct Service: ServiceType {
}
}

public func triggerThirdPartyEventInput(input: TriggerThirdPartyEventInput)
-> SignalProducer<EmptyResponseEnvelope, ErrorEnvelope> {
return GraphQL.shared.client
.perform(mutation: GraphAPI
.TriggerThirdPartyEventMutation(input: GraphAPI.TriggerThirdPartyEventInput.from(input)))
.flatMap { _ in
SignalProducer(value: EmptyResponseEnvelope())
}
}

public func cancelBacking(input: CancelBackingInput)
-> SignalProducer<EmptyResponseEnvelope, ErrorEnvelope> {
return GraphQL.shared.client
Expand Down
4 changes: 4 additions & 0 deletions KsApi/ServiceType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public protocol ServiceType {
func triggerCapiEventInput(input: TriggerCapiEventInput)
-> SignalProducer<EmptyResponseEnvelope, ErrorEnvelope>

/// Sends facebook ad data and/or google analytics data relevant to the user
func triggerThirdPartyEventInput(input: TriggerThirdPartyEventInput)
-> SignalProducer<EmptyResponseEnvelope, ErrorEnvelope>

/// Cancels a backing
func cancelBacking(input: CancelBackingInput)
-> SignalProducer<EmptyResponseEnvelope, ErrorEnvelope>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
extension GraphAPI.TriggerThirdPartyEvent {
static func from(_ input: TriggerThirdPartyEventInput) -> GraphAPI.TriggerThirdPartyEvent {
return GraphAPI.TriggerThirdPartyEvent(
deviceId: input.deviceId,
eventName: input.eventName,
projectId: input.projectId,
pledgeAmount: input.pledgeAmount,
shipping: input.shipping,
transactionId: input.transactionId,
userId: input.userId,
appData: GraphAPI.AppDataInput?,
clientMutation: input.clientMutation
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@testable import KsApi
import XCTest

class GraphAPI_TriggerThirdPartyEventInput_TriggerThirdPartyEventInputTests: XCTestCase {
func testTriggerThirdEventPartyInputCreation_WithValidData_Success() {
let input =
TriggerThirdPartyEventInput(
deviceId: "deviceId",
eventName: "eventName",
projectId: "projectId",
pledgeAmount: 1.0,
shipping: 2.0,
transactionId: "transactionId",
userId: "userId",
appData: GraphAPI.AppDataInput(
advertiserTrackingEnabled: true,
applicationTrackingEnabled: true,
extinfo: ["appData"]
),
clientMutation: ""
)

let graphInput = GraphAPI.TriggerThirdPartyEvent.from(input)

XCTAssertEqual(graphInput.deviceId, input.deviceId)
XCTAssertEqual(graphInput.eventName, input.eventName)
XCTAssertEqual(graphInput.projectId, input.projectId)
XCTAssertEqual(graphInput.pledgeAmount, input.pledgeAmount)
XCTAssertEqual(graphInput.shipping, input.shipping)
XCTAssertEqual(graphInput.transactionId, input.transactionId)
XCTAssertEqual(graphInput.userId, input.userId)
XCTAssertNotNil(graphInput.appData)
XCTAssertEqual(graphInput.clientMutation, input.clientMutation)
}
}
5 changes: 5 additions & 0 deletions KsApi/mutations/TriggerThirdPartyEvent.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mutation triggerThirdPartyEvent($input: TriggerThirdPartyEventInput!) {
triggerThirdPartyEvent(input: $input) {
success
}
}
49 changes: 49 additions & 0 deletions KsApi/mutations/inputs/TriggerThirdPartyEventInput.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Foundation

public struct TriggerThirdPartyEventInput: GraphMutationInput {
let deviceId: String
let eventName: String
let projectId: String
let pledgeAmount: Float?
let shipping: Float?
let transactionId: String?
let userId: String?
let appData: GraphAPI.AppDataInput?
let clientMutation: String

public init(
deviceId: String,
eventName: String,
projectId: String,
pledgeAmount: Float?,
shipping: Float?,
transactionId: String?,
userId: String?,
appData: GraphAPI.AppDataInput?,
clientMutation: String
) {
self.deviceId = deviceId
self.eventName = eventName
self.projectId = projectId
self.pledgeAmount = pledgeAmount
self.shipping = shipping
self.transactionId = transactionId
self.userId = userId
self.appData = appData
self.clientMutation = clientMutation
}

public func toInputDictionary() -> [String: Any] {
return [
"deviceId": self.deviceId,
"eventName": self.eventName,
"projectId": self.projectId,
"pledgeAmount": self.pledgeAmount,
"shipping": self.shipping,
"transactionId": self.transactionId,
"userId": self.userId,
"appData": self.appData,
"clientMutation": self.clientMutation
]
}
}
35 changes: 35 additions & 0 deletions KsApi/mutations/inputs/TriggerThirdPartyEventInputTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@testable import KsApi
import XCTest

final class TriggerThirdPartyEventInputTests: XCTestCase {
func testTriggerThirdPartyEventInputTestsDictionary_WithValue_Success() {
let triggerThirdPartyEventInput =
TriggerThirdPartyEventInput(
deviceId: "deviceId",
eventName: "eventName",
projectId: "projectId",
pledgeAmount: 1.0,
shipping: 2.0,
transactionId: "transactionId",
userId: "userId",
appData: GraphAPI.AppDataInput(
advertiserTrackingEnabled: true,
applicationTrackingEnabled: true,
extinfo: ["appData"]
),
clientMutation: ""
)

let input = triggerThirdPartyEventInput.toInputDictionary()

XCTAssertEqual(input["deviceId"] as? String, "deviceId")
XCTAssertEqual(input["eventName"] as? String, "eventName")
XCTAssertEqual(input["projectId"] as? String, "projectId")
XCTAssertEqual(input["pledgeAmount"] as? Float, 1.0)
XCTAssertEqual(input["shipping"] as? Float, 2.0)
XCTAssertEqual(input["transactionId"] as? String, "transactionId")
XCTAssertEqual(input["userId"] as? String, "userId")
XCTAssertNotNil(input["appData"])
XCTAssertEqual(input["clientMutation"] as? String, "")
}
}

0 comments on commit 5c7a051

Please sign in to comment.