|
11 | 11 | event = AmplitudeAPI::Event.new(user_id: 123, event_type: 'clicked on sign up')
|
12 | 12 | body = {api_key: AmplitudeAPI.api_key, event: JSON.generate([event.to_hash])}
|
13 | 13 |
|
14 |
| - expect(Typhoeus).to receive(:post).with(AmplitudeAPI::URI_STRING, body: body) |
| 14 | + expect(Typhoeus).to receive(:post).with(AmplitudeAPI::TRACK_URI_STRING, body: body) |
15 | 15 |
|
16 | 16 | AmplitudeAPI.track(event)
|
17 | 17 | end
|
|
23 | 23 | event2 = AmplitudeAPI::Event.new(user_id: 456, event_type: 'liked a widget')
|
24 | 24 | body = {api_key: AmplitudeAPI.api_key, event: JSON.generate([event.to_hash, event2.to_hash])}
|
25 | 25 |
|
26 |
| - expect(Typhoeus).to receive(:post).with(AmplitudeAPI::URI_STRING, body: body) |
| 26 | + expect(Typhoeus).to receive(:post).with(AmplitudeAPI::TRACK_URI_STRING, body: body) |
27 | 27 |
|
28 | 28 | AmplitudeAPI.track([event, event2])
|
29 | 29 | end
|
30 | 30 | end
|
31 | 31 | end
|
32 | 32 |
|
| 33 | + describe ".identify" do |
| 34 | + context "with a single identification" do |
| 35 | + it "sends the identification to Amplitude" do |
| 36 | + identification = AmplitudeAPI::Identification.new(user_id: 123, user_properties: {first_name: 'John', last_name: 'Doe'}) |
| 37 | + body = {api_key: AmplitudeAPI.api_key, identification: JSON.generate([identification.to_hash])} |
| 38 | + |
| 39 | + expect(Typhoeus).to receive(:post).with(AmplitudeAPI::IDENTIFY_URI_STRING, body: body) |
| 40 | + |
| 41 | + AmplitudeAPI.identify(identification) |
| 42 | + end |
| 43 | + end |
| 44 | + |
| 45 | + context "with multiple identifications" do |
| 46 | + it "sends all identifications in a single request" do |
| 47 | + identification = AmplitudeAPI::Identification.new(user_id: 123, user_properties: {first_name: 'Julian', last_name: 'Ponce'}) |
| 48 | + identification2 = AmplitudeAPI::Identification.new(user_id: 456, user_properties: {first_name: 'John', last_name: 'Doe'}) |
| 49 | + body = {api_key: AmplitudeAPI.api_key, identification: JSON.generate([identification.to_hash, identification2.to_hash])} |
| 50 | + |
| 51 | + expect(Typhoeus).to receive(:post).with(AmplitudeAPI::IDENTIFY_URI_STRING, body: body) |
| 52 | + |
| 53 | + AmplitudeAPI.identify([identification, identification2]) |
| 54 | + end |
| 55 | + end |
| 56 | + end |
| 57 | + |
33 | 58 | describe ".initializer " do
|
34 | 59 | it "initializes event without parameter" do
|
35 | 60 | event = AmplitudeAPI::Event.new()
|
|
77 | 102 | end
|
78 | 103 | end
|
79 | 104 |
|
| 105 | + describe ".send_identify" do |
| 106 | + it "sends an identify to AmplitudeAPI" do |
| 107 | + identification = AmplitudeAPI::Identification.new(user_id: @user, user_properties: {first_name: 'John', last_name: 'Doe'}) |
| 108 | + expect(AmplitudeAPI).to receive(:identify).with(identification) |
| 109 | + |
| 110 | + AmplitudeAPI.send_identify(@user, {first_name: 'John', last_name: 'Doe'}) |
| 111 | + end |
| 112 | + |
| 113 | + context "the user is nil" do |
| 114 | + it "sends an identify with the no account user" do |
| 115 | + identification = AmplitudeAPI::Identification.new(user_id: nil, user_properties: {first_name: 'John', last_name: 'Doe'}) |
| 116 | + expect(AmplitudeAPI).to receive(:identify).with(identification) |
| 117 | + |
| 118 | + AmplitudeAPI.send_identify(nil, {first_name: 'John', last_name: 'Doe'}) |
| 119 | + end |
| 120 | + end |
| 121 | + |
| 122 | + context "the user is a user_id" do |
| 123 | + it "sends an identify to AmplitudeAPI" do |
| 124 | + identification = AmplitudeAPI::Identification.new(user_id: 123, user_properties: {first_name: 'John', last_name: 'Doe'}) |
| 125 | + expect(AmplitudeAPI).to receive(:identify).with(identification) |
| 126 | + |
| 127 | + AmplitudeAPI.send_identify(@user.id, {first_name: 'John', last_name: 'Doe'}) |
| 128 | + end |
| 129 | + end |
| 130 | + end |
| 131 | + |
80 | 132 | describe "#body" do
|
81 | 133 | it "should add an api key" do
|
82 | 134 | event = AmplitudeAPI::Event.new(user_id: @user, event_type: "test_event", event_properties: {test_property: 1})
|
83 |
| - body = AmplitudeAPI.body(event) |
| 135 | + body = AmplitudeAPI.track_body(event) |
84 | 136 | expect(body[:api_key]).to eq('stub api key')
|
85 | 137 | end
|
86 | 138 |
|
87 | 139 | it "should create an event" do
|
88 | 140 | event = AmplitudeAPI::Event.new(user_id: 23, event_type: "test_event", event_properties: {foo: "bar"})
|
89 |
| - body = AmplitudeAPI.body(event) |
| 141 | + body = AmplitudeAPI.track_body(event) |
90 | 142 |
|
91 | 143 | expected = JSON.generate([{event_type: "test_event", user_id: 23, event_properties: {foo: "bar"}}])
|
92 | 144 | expect(body[:event]).to eq(expected)
|
|
0 commit comments