Skip to content

Commit

Permalink
Track account creation (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
allthesignals authored Sep 27, 2024
1 parent 6a21eef commit 35ab18f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 10 additions & 2 deletions app/app/controllers/webhooks/pinwheel/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def create
PinwheelAccount
.create_with(cbv_flow: @cbv_flow, supported_jobs: supported_jobs)
.find_or_create_by(pinwheel_account_id: params["payload"]["account_id"])
track_account_created_event(@cbv_flow, params["payload"]["platform_name"])
end

if PinwheelAccount::EVENTS_MAP.keys.include?(params["event"])
Expand All @@ -26,7 +27,7 @@ def create
end

if pinwheel_account.has_fully_synced?
track_event(@cbv_flow, pinwheel_account)
track_account_synced_event(@cbv_flow, pinwheel_account)

PaystubsChannel.broadcast_to(@cbv_flow, {
event: "cbv.payroll_data_available",
Expand All @@ -52,7 +53,7 @@ def authorize_webhook
end
end

def track_event(cbv_flow, pinwheel_account)
def track_account_synced_event(cbv_flow, pinwheel_account)
NewRelicEventTracker.track("PinwheelAccountSyncFinished", {
cbv_flow_id: cbv_flow.id,
identity_success: pinwheel_account.job_succeeded?("identity"),
Expand All @@ -69,6 +70,13 @@ def track_event(cbv_flow, pinwheel_account)
Rails.logger.error "Unable to track NewRelic event (PinwheelAccountSyncFinished): #{ex}"
end

def track_account_created_event(cbv_flow, platform_name)
NewRelicEventTracker.track("PinwheelAccountCreated", {
cbv_flow_id: cbv_flow.id,
platform_name: platform_name
})
end

def set_cbv_flow
@cbv_flow = CbvFlow.find_by_pinwheel_end_user_id(params["payload"]["end_user_id"])
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,18 @@
{
"platform_id" => "00000000-0000-0000-0000-000000011111",
"end_user_id" => cbv_flow.pinwheel_end_user_id,
"account_id" => account_id
"account_id" => account_id,
"platform_name" => "acme"
}
end

it "creates a PinwheelAccount object" do
expect(NewRelicEventTracker).to receive(:track)
.with("PinwheelAccountCreated", {
cbv_flow_id: cbv_flow.id,
platform_name: "acme"
})

expect do
post :create, params: valid_params
end.to change(PinwheelAccount, :count).by(1)
Expand Down

0 comments on commit 35ab18f

Please sign in to comment.