|
338 | 338 | end |
339 | 339 | end |
340 | 340 |
|
| 341 | + it 'only sends non-nil values in request body' do |
| 342 | + expect(described_class).to receive(:post_request) do |options| |
| 343 | + body = options[:body] |
| 344 | + expect(body).to eq({ email: '[email protected]', first_name: 'John' }) |
| 345 | + expect(body).not_to have_key(:last_name) |
| 346 | + expect(body).not_to have_key(:email_verified) |
| 347 | + |
| 348 | + double('request') |
| 349 | + end.and_return(double('request')) |
| 350 | + |
| 351 | + expect(described_class).to receive(:execute_request).and_return( |
| 352 | + double('response', body: '{"id": "test_user", "email": "[email protected]"}'), |
| 353 | + ) |
| 354 | + |
| 355 | + described_class.create_user( |
| 356 | + |
| 357 | + first_name: 'John', |
| 358 | + ) |
| 359 | + end |
| 360 | + |
341 | 361 | context 'with an invalid payload' do |
342 | 362 | it 'returns an error' do |
343 | 363 | VCR.use_cassette 'user_management/create_user_invalid' do |
|
382 | 402 | end |
383 | 403 | end |
384 | 404 |
|
| 405 | + it 'only sends non-nil values in request body' do |
| 406 | + # Mock the request to inspect what's being sent |
| 407 | + expect(described_class).to receive(:put_request) do |options| |
| 408 | + # Verify that the body only contains non-nil values |
| 409 | + body = options[:body] |
| 410 | + expect(body).to eq({ email_verified: true }) |
| 411 | + expect(body).not_to have_key(:first_name) |
| 412 | + expect(body).not_to have_key(:last_name) |
| 413 | + expect(body).not_to have_key(:email) |
| 414 | + |
| 415 | + # Return a mock request object |
| 416 | + double('request') |
| 417 | + end.and_return(double('request')) |
| 418 | + |
| 419 | + expect(described_class).to receive(:execute_request).and_return( |
| 420 | + double('response', body: '{"id": "test_user", "email_verified": true}'), |
| 421 | + ) |
| 422 | + |
| 423 | + described_class.update_user( |
| 424 | + id: 'user_01H7TVSKS45SDHN5V9XPSM6H44', |
| 425 | + email_verified: true, |
| 426 | + ) |
| 427 | + end |
| 428 | + |
385 | 429 | context 'with an invalid payload' do |
386 | 430 | it 'returns an error' do |
387 | 431 | VCR.use_cassette 'user_management/update_user/invalid' do |
|
778 | 822 | expect(authentication_response.authentication_challenge.id).to eq('auth_challenge_01H96FETXGTW1QMBSBT2T36PW0') |
779 | 823 | end |
780 | 824 | end |
| 825 | + |
| 826 | + it 'only sends non-nil values in request body' do |
| 827 | + expect(described_class).to receive(:post_request) do |options| |
| 828 | + body = options[:body] |
| 829 | + expect(body).to eq({ type: 'totp', totp_issuer: 'Test App' }) |
| 830 | + expect(body).not_to have_key(:totp_user) |
| 831 | + expect(body).not_to have_key(:totp_secret) |
| 832 | + |
| 833 | + double('request') |
| 834 | + end.and_return(double('request')) |
| 835 | + |
| 836 | + expect(described_class).to receive(:execute_request).and_return( |
| 837 | + double('response', |
| 838 | + body: '{"authentication_factor": {"id": "test"}, "authentication_challenge": {"id": "test"}}',), |
| 839 | + ) |
| 840 | + |
| 841 | + described_class.enroll_auth_factor( |
| 842 | + user_id: 'user_123', |
| 843 | + type: 'totp', |
| 844 | + totp_issuer: 'Test App', |
| 845 | + ) |
| 846 | + end |
781 | 847 | end |
782 | 848 |
|
783 | 849 | context 'with an incorrect user id' do |
|
1444 | 1510 | expect(invitation.email).to eq('[email protected]') |
1445 | 1511 | end |
1446 | 1512 | end |
| 1513 | + |
| 1514 | + it 'only sends non-nil values in request body' do |
| 1515 | + expect(described_class).to receive(:post_request) do |options| |
| 1516 | + body = options[:body] |
| 1517 | + expect(body).to eq({ email: '[email protected]', organization_id: 'org_123' }) |
| 1518 | + expect(body).not_to have_key(:expires_in_days) |
| 1519 | + expect(body).not_to have_key(:inviter_user_id) |
| 1520 | + expect(body).not_to have_key(:role_slug) |
| 1521 | + |
| 1522 | + double('request') |
| 1523 | + end.and_return(double('request')) |
| 1524 | + |
| 1525 | + expect(described_class).to receive(:execute_request).and_return( |
| 1526 | + double('response', body: '{"id": "test_invitation"}'), |
| 1527 | + ) |
| 1528 | + |
| 1529 | + described_class.send_invitation( |
| 1530 | + |
| 1531 | + organization_id: 'org_123', |
| 1532 | + ) |
| 1533 | + end |
1447 | 1534 | end |
1448 | 1535 |
|
1449 | 1536 | context 'with an invalid payload' do |
|
0 commit comments