|
127 | 127 | end |
128 | 128 | end |
129 | 129 | end |
| 130 | + |
| 131 | + describe "bucket_user" do |
| 132 | + it "gets expected bucket values for specific keys" do |
| 133 | + user = { key: "userKeyA" } |
| 134 | + bucket = bucket_user(user, "hashKey", "key", "saltyA") |
| 135 | + expect(bucket).to be_within(0.0000001).of(0.42157587); |
| 136 | + |
| 137 | + user = { key: "userKeyB" } |
| 138 | + bucket = bucket_user(user, "hashKey", "key", "saltyA") |
| 139 | + expect(bucket).to be_within(0.0000001).of(0.6708485); |
| 140 | + |
| 141 | + user = { key: "userKeyC" } |
| 142 | + bucket = bucket_user(user, "hashKey", "key", "saltyA") |
| 143 | + expect(bucket).to be_within(0.0000001).of(0.10343106); |
| 144 | + end |
| 145 | + |
| 146 | + it "can bucket by int value (equivalent to string)" do |
| 147 | + user = { |
| 148 | + key: "userkey", |
| 149 | + custom: { |
| 150 | + stringAttr: "33333", |
| 151 | + intAttr: 33333 |
| 152 | + } |
| 153 | + } |
| 154 | + stringResult = bucket_user(user, "hashKey", "stringAttr", "saltyA") |
| 155 | + intResult = bucket_user(user, "hashKey", "intAttr", "saltyA") |
| 156 | + |
| 157 | + expect(intResult).to be_within(0.0000001).of(0.54771423) |
| 158 | + expect(intResult).to eq(stringResult) |
| 159 | + end |
| 160 | + |
| 161 | + it "cannot bucket by float value" do |
| 162 | + user = { |
| 163 | + key: "userkey", |
| 164 | + custom: { |
| 165 | + floatAttr: 33.5 |
| 166 | + } |
| 167 | + } |
| 168 | + result = bucket_user(user, "hashKey", "floatAttr", "saltyA") |
| 169 | + expect(result).to eq(0.0) |
| 170 | + end |
| 171 | + |
| 172 | + |
| 173 | + it "cannot bucket by bool value" do |
| 174 | + user = { |
| 175 | + key: "userkey", |
| 176 | + custom: { |
| 177 | + boolAttr: true |
| 178 | + } |
| 179 | + } |
| 180 | + result = bucket_user(user, "hashKey", "boolAttr", "saltyA") |
| 181 | + expect(result).to eq(0.0) |
| 182 | + end |
| 183 | + end |
130 | 184 | end |
0 commit comments