|
9 | 9 | let(:hc) { FakeHttpClient.new } |
10 | 10 | let(:user) { { key: "userkey", name: "Red" } } |
11 | 11 | let(:filtered_user) { { key: "userkey", privateAttrs: [ "name" ] } } |
| 12 | + let(:numeric_user) { { key: 1, secondary: 2, ip: 3, country: 4, email: 5, firstName: 6, lastName: 7, |
| 13 | + avatar: 8, name: 9, anonymous: false, custom: { age: 99 } } } |
| 14 | + let(:stringified_numeric_user) { { key: '1', secondary: '2', ip: '3', country: '4', email: '5', firstName: '6', |
| 15 | + lastName: '7', avatar: '8', name: '9', anonymous: false, custom: { age: 99 } } } |
12 | 16 |
|
13 | 17 | after(:each) do |
14 | 18 | if !@ep.nil? |
|
40 | 44 | }) |
41 | 45 | end |
42 | 46 |
|
| 47 | + it "stringifies built-in user attributes in identify event" do |
| 48 | + @ep = subject.new("sdk_key", default_config, hc) |
| 49 | + flag = { key: "flagkey", version: 11 } |
| 50 | + e = { kind: "identify", key: numeric_user[:key], user: numeric_user } |
| 51 | + @ep.add_event(e) |
| 52 | + |
| 53 | + output = flush_and_get_events |
| 54 | + expect(output).to contain_exactly( |
| 55 | + kind: "identify", |
| 56 | + key: numeric_user[:key].to_s, |
| 57 | + creationDate: e[:creationDate], |
| 58 | + user: stringified_numeric_user |
| 59 | + ) |
| 60 | + end |
| 61 | + |
43 | 62 | it "queues individual feature event with index event" do |
44 | 63 | @ep = subject.new("sdk_key", default_config, hc) |
45 | 64 | flag = { key: "flagkey", version: 11 } |
|
75 | 94 | ) |
76 | 95 | end |
77 | 96 |
|
| 97 | + it "stringifies built-in user attributes in index event" do |
| 98 | + @ep = subject.new("sdk_key", default_config, hc) |
| 99 | + flag = { key: "flagkey", version: 11 } |
| 100 | + fe = { |
| 101 | + kind: "feature", key: "flagkey", version: 11, user: numeric_user, |
| 102 | + variation: 1, value: "value", trackEvents: true |
| 103 | + } |
| 104 | + @ep.add_event(fe) |
| 105 | + |
| 106 | + output = flush_and_get_events |
| 107 | + expect(output).to contain_exactly( |
| 108 | + eq(index_event(fe, stringified_numeric_user)), |
| 109 | + eq(feature_event(fe, flag, false, nil)), |
| 110 | + include(:kind => "summary") |
| 111 | + ) |
| 112 | + end |
| 113 | + |
78 | 114 | it "can include inline user in feature event" do |
79 | 115 | config = LaunchDarkly::Config.new(inline_users_in_events: true) |
80 | 116 | @ep = subject.new("sdk_key", config, hc) |
|
92 | 128 | ) |
93 | 129 | end |
94 | 130 |
|
| 131 | + it "stringifies built-in user attributes in feature event" do |
| 132 | + config = LaunchDarkly::Config.new(inline_users_in_events: true) |
| 133 | + @ep = subject.new("sdk_key", config, hc) |
| 134 | + flag = { key: "flagkey", version: 11 } |
| 135 | + fe = { |
| 136 | + kind: "feature", key: "flagkey", version: 11, user: numeric_user, |
| 137 | + variation: 1, value: "value", trackEvents: true |
| 138 | + } |
| 139 | + @ep.add_event(fe) |
| 140 | + |
| 141 | + output = flush_and_get_events |
| 142 | + expect(output).to contain_exactly( |
| 143 | + eq(feature_event(fe, flag, false, stringified_numeric_user)), |
| 144 | + include(:kind => "summary") |
| 145 | + ) |
| 146 | + end |
| 147 | + |
95 | 148 | it "filters user in feature event" do |
96 | 149 | config = LaunchDarkly::Config.new(all_attributes_private: true, inline_users_in_events: true) |
97 | 150 | @ep = subject.new("sdk_key", config, hc) |
|
323 | 376 | ) |
324 | 377 | end |
325 | 378 |
|
| 379 | + it "stringifies built-in user attributes in custom event" do |
| 380 | + config = LaunchDarkly::Config.new(inline_users_in_events: true) |
| 381 | + @ep = subject.new("sdk_key", config, hc) |
| 382 | + e = { kind: "custom", key: "eventkey", user: numeric_user } |
| 383 | + @ep.add_event(e) |
| 384 | + |
| 385 | + output = flush_and_get_events |
| 386 | + expect(output).to contain_exactly( |
| 387 | + eq(custom_event(e, stringified_numeric_user)) |
| 388 | + ) |
| 389 | + end |
| 390 | + |
326 | 391 | it "does a final flush when shutting down" do |
327 | 392 | @ep = subject.new("sdk_key", default_config, hc) |
328 | 393 | e = { kind: "identify", key: user[:key], user: user } |
|
0 commit comments