Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #439 from fridaland/fix-gifted-segment-calls
Browse files Browse the repository at this point in the history
Fix bad conditional transition event check for 'gifted' segment calls
  • Loading branch information
johndbritton committed Nov 18, 2019
2 parents 905b4a7 + 458c894 commit 53c6f91
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions app/services/user_state_transition_segment_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def call(user, transition)
when :incomplete then incomplete(user)
when :ineligible then ineligible(user)
when :won then won(user, transition)
when :gift_sticker then gift_sticker(user)
when :gifted then gifted(user)
end
end

Expand Down Expand Up @@ -62,7 +62,9 @@ def won(user, transition)
end
end

def gift_sticker(user)
# TODO: change this to gifted(user, transition) and check transition.to to
# add case for 'gifted_shirt'
def gifted(user)
segment(user).identify(state: 'gifted_sticker')
segment(user).track('user_gifted_sticker')
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@
describe '#gift' do
before do
allow(UserStateTransitionSegmentService)
.to receive(:gift_sticker).and_return(true)
.to receive(:gifted).and_return(true)
end

context 'the user is in the incompleted state' do
Expand Down
3 changes: 3 additions & 0 deletions spec/services/gift_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

context 'there is 1 sticker coupon' do
before do
allow(UserStateTransitionSegmentService).to receive(:call)
FactoryBot.create(:sticker_coupon)
GiftService.call
end
Expand All @@ -44,6 +45,7 @@

context 'there are 2 sticker coupons' do
before do
allow(UserStateTransitionSegmentService).to receive(:call)
FactoryBot.create(:sticker_coupon)
FactoryBot.create(:sticker_coupon)
GiftService.call
Expand All @@ -64,6 +66,7 @@

context 'there are 3 sticker coupons' do
before do
allow(UserStateTransitionSegmentService).to receive(:call)
FactoryBot.create(:sticker_coupon)
FactoryBot.create(:sticker_coupon)
FactoryBot.create(:sticker_coupon)
Expand Down
4 changes: 2 additions & 2 deletions spec/services/user_state_transition_segment_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@
end
end

context 'the event is gift_sticker and the user is incompleted' do
context 'the event is gifted and the user is incompleted' do
let(:user) { FactoryBot.create(:user, :incompleted) }

before do
allow(transition).to receive(:event).and_return(:gift_sticker)
allow(transition).to receive(:event).and_return(:gifted)
end

it 'calls SegmentService#identify with proper arguments' do
Expand Down

0 comments on commit 53c6f91

Please sign in to comment.