|
136 | 136 | ) |
137 | 137 | end |
138 | 138 | end |
| 139 | + |
| 140 | + context 'when there are multiple users in the company' do |
| 141 | + let(:other_user) do |
| 142 | + Userlist::Push::User.new( |
| 143 | + identifier: 'other-user-identifier', |
| 144 | + email: 'bar@example.com' |
| 145 | + ) |
| 146 | + end |
| 147 | + |
| 148 | + let(:other_relationship) do |
| 149 | + Userlist::Push::Relationship.new( |
| 150 | + user: other_user, |
| 151 | + company: company, |
| 152 | + properties: { |
| 153 | + role: 'member' |
| 154 | + } |
| 155 | + ) |
| 156 | + end |
| 157 | + |
| 158 | + before do |
| 159 | + company.relationships = [relationship, other_relationship] |
| 160 | + end |
| 161 | + |
| 162 | + it 'should return the correct payload' do |
| 163 | + expect(payload).to eq( |
| 164 | + identifier: 'user-identifier', |
| 165 | + email: 'foo@example.com', |
| 166 | + signed_up_at: nil, |
| 167 | + relationships: [ |
| 168 | + { |
| 169 | + user: 'user-identifier', |
| 170 | + company: { |
| 171 | + identifier: 'company-identifier', |
| 172 | + name: 'Example, Inc.', |
| 173 | + signed_up_at: nil, |
| 174 | + relationships: [ |
| 175 | + { |
| 176 | + company: 'company-identifier', |
| 177 | + user: { |
| 178 | + identifier: 'other-user-identifier', |
| 179 | + email: 'bar@example.com' |
| 180 | + }, |
| 181 | + properties: { |
| 182 | + role: 'member' |
| 183 | + } |
| 184 | + } |
| 185 | + ] |
| 186 | + }, |
| 187 | + properties: { |
| 188 | + role: 'admin' |
| 189 | + } |
| 190 | + } |
| 191 | + ] |
| 192 | + ) |
| 193 | + end |
| 194 | + end |
139 | 195 | end |
140 | 196 |
|
141 | 197 | context 'when serializing the company' do |
|
199 | 255 | ) |
200 | 256 | end |
201 | 257 | end |
| 258 | + |
| 259 | + context 'when there are multiple users in the company' do |
| 260 | + let(:other_user) do |
| 261 | + Userlist::Push::User.new( |
| 262 | + identifier: 'other-user-identifier', |
| 263 | + email: 'bar@example.com' |
| 264 | + ) |
| 265 | + end |
| 266 | + |
| 267 | + let(:other_relationship) do |
| 268 | + Userlist::Push::Relationship.new( |
| 269 | + user: other_user, |
| 270 | + company: company, |
| 271 | + properties: { |
| 272 | + role: 'member' |
| 273 | + } |
| 274 | + ) |
| 275 | + end |
| 276 | + |
| 277 | + before do |
| 278 | + company.relationships = [relationship, other_relationship] |
| 279 | + end |
| 280 | + |
| 281 | + it 'should return the correct payload' do |
| 282 | + expect(payload).to eq( |
| 283 | + identifier: 'company-identifier', |
| 284 | + name: 'Example, Inc.', |
| 285 | + signed_up_at: nil, |
| 286 | + relationships: [ |
| 287 | + { |
| 288 | + company: 'company-identifier', |
| 289 | + user: { |
| 290 | + identifier: 'user-identifier', |
| 291 | + email: 'foo@example.com', |
| 292 | + signed_up_at: nil |
| 293 | + }, |
| 294 | + properties: { |
| 295 | + role: 'admin' |
| 296 | + } |
| 297 | + }, |
| 298 | + { |
| 299 | + company: 'company-identifier', |
| 300 | + user: { |
| 301 | + identifier: 'other-user-identifier', |
| 302 | + email: 'bar@example.com' |
| 303 | + }, |
| 304 | + properties: { |
| 305 | + role: 'member' |
| 306 | + } |
| 307 | + } |
| 308 | + ] |
| 309 | + ) |
| 310 | + end |
| 311 | + end |
202 | 312 | end |
203 | 313 |
|
204 | 314 | context 'when serializing the relationship' do |
|
241 | 351 | expect(payload).to_not be |
242 | 352 | end |
243 | 353 | end |
| 354 | + |
| 355 | + context 'when there are multiple users in the company' do |
| 356 | + let(:other_user) do |
| 357 | + Userlist::Push::User.new( |
| 358 | + identifier: 'other-user-identifier', |
| 359 | + email: 'bar@example.com' |
| 360 | + ) |
| 361 | + end |
| 362 | + |
| 363 | + let(:other_relationship) do |
| 364 | + Userlist::Push::Relationship.new( |
| 365 | + user: other_user, |
| 366 | + company: company, |
| 367 | + properties: { |
| 368 | + role: 'member' |
| 369 | + } |
| 370 | + ) |
| 371 | + end |
| 372 | + |
| 373 | + before do |
| 374 | + company.relationships = [relationship, other_relationship] |
| 375 | + end |
| 376 | + |
| 377 | + it 'should return the correct payload' do |
| 378 | + expect(payload).to eq( |
| 379 | + user: { |
| 380 | + identifier: 'user-identifier', |
| 381 | + email: 'foo@example.com', |
| 382 | + signed_up_at: nil |
| 383 | + }, |
| 384 | + company: { |
| 385 | + identifier: 'company-identifier', |
| 386 | + name: 'Example, Inc.', |
| 387 | + signed_up_at: nil, |
| 388 | + relationships: [ |
| 389 | + { |
| 390 | + company: 'company-identifier', |
| 391 | + user: { |
| 392 | + identifier: 'other-user-identifier', |
| 393 | + email: 'bar@example.com' |
| 394 | + }, |
| 395 | + properties: { |
| 396 | + role: 'member' |
| 397 | + } |
| 398 | + } |
| 399 | + ] |
| 400 | + }, |
| 401 | + properties: { |
| 402 | + role: 'admin' |
| 403 | + } |
| 404 | + ) |
| 405 | + end |
| 406 | + end |
244 | 407 | end |
245 | 408 |
|
246 | 409 | context 'when serializing the event' do |
|
309 | 472 | expect(payload[:occurred_at]).to be_within(1).of(Time.now) |
310 | 473 | end |
311 | 474 | end |
| 475 | + |
| 476 | + context 'when there are multiple users in the company' do |
| 477 | + let(:other_user) do |
| 478 | + Userlist::Push::User.new( |
| 479 | + identifier: 'other-user-identifier', |
| 480 | + email: 'bar@example.com' |
| 481 | + ) |
| 482 | + end |
| 483 | + |
| 484 | + let(:other_relationship) do |
| 485 | + Userlist::Push::Relationship.new( |
| 486 | + user: other_user, |
| 487 | + company: company, |
| 488 | + properties: { |
| 489 | + role: 'member' |
| 490 | + } |
| 491 | + ) |
| 492 | + end |
| 493 | + |
| 494 | + before do |
| 495 | + company.relationships = [relationship, other_relationship] |
| 496 | + end |
| 497 | + |
| 498 | + it 'should return the correct payload' do |
| 499 | + expect(payload).to eq( |
| 500 | + name: 'example_event', |
| 501 | + occurred_at: event.occurred_at, |
| 502 | + user: { |
| 503 | + identifier: 'user-identifier', |
| 504 | + email: 'foo@example.com', |
| 505 | + signed_up_at: nil, |
| 506 | + relationships: [ |
| 507 | + { |
| 508 | + user: 'user-identifier', |
| 509 | + company: { |
| 510 | + identifier: 'company-identifier', |
| 511 | + name: 'Example, Inc.', |
| 512 | + signed_up_at: nil, |
| 513 | + relationships: [ |
| 514 | + { |
| 515 | + company: 'company-identifier', |
| 516 | + user: { |
| 517 | + identifier: 'other-user-identifier', |
| 518 | + email: 'bar@example.com' |
| 519 | + }, |
| 520 | + properties: { |
| 521 | + role: 'member' |
| 522 | + } |
| 523 | + } |
| 524 | + ] |
| 525 | + }, |
| 526 | + properties: { |
| 527 | + role: 'admin' |
| 528 | + } |
| 529 | + } |
| 530 | + ] |
| 531 | + }, |
| 532 | + company: 'company-identifier', |
| 533 | + properties: { |
| 534 | + null: nil, |
| 535 | + empty: [], |
| 536 | + value: 'foo' |
| 537 | + } |
| 538 | + ) |
| 539 | + end |
| 540 | + end |
312 | 541 | end |
313 | 542 | end |
314 | 543 | end |
0 commit comments