|
580 | 580 | result = subject.send(:add_user_to_team, user: "blackmanx", team:) |
581 | 581 | expect(result).to eq(false) |
582 | 582 | end |
| 583 | + |
| 584 | + context "ignore_not_found is false" do |
| 585 | + it "raises when user is not found" do |
| 586 | + expect(subject).to receive(:validate_team_id_and_slug!).with(1001, "russian-blues").and_return(true) |
| 587 | + expect(subject).to receive(:org_members).and_return(Set.new(%w[blackmanx])) |
| 588 | + |
| 589 | + add_membership_response = { |
| 590 | + "url" => "https://github.fake/api/v3/teams/1001/memberships/blackmanx", |
| 591 | + "role" => "member", |
| 592 | + "state" => "active" |
| 593 | + } |
| 594 | + |
| 595 | + stub_request(:put, "https://github.fake/api/v3/teams/1001/memberships/blackmanx") |
| 596 | + .to_return( |
| 597 | + status: 404, |
| 598 | + headers: { |
| 599 | + "Content-Type" => "application/json" |
| 600 | + }, |
| 601 | + body: JSON.generate({ |
| 602 | + "message" => "Not Found", |
| 603 | + "documentation_url" => "https://docs.github.com/rest" |
| 604 | + }) |
| 605 | + ) |
| 606 | + |
| 607 | + expect { subject.send(:add_user_to_team, user: "blackmanx", team:) }.to raise_error(Octokit::NotFound) |
| 608 | + end |
| 609 | + end |
| 610 | + |
| 611 | + context "ignore_not_found is true" do |
| 612 | + let(:subject) do |
| 613 | + described_class.new( |
| 614 | + addr: "https://github.fake/api/v3", |
| 615 | + org: "kittensinc", |
| 616 | + token: "GoPackGo", |
| 617 | + ou: "ou=kittensinc,ou=GitHub,dc=github,dc=fake", |
| 618 | + ignore_not_found: true |
| 619 | + ) |
| 620 | + end |
| 621 | + |
| 622 | + it "ignores 404s" do |
| 623 | + expect(subject).to receive(:validate_team_id_and_slug!).with(1001, "russian-blues").and_return(true) |
| 624 | + expect(subject).to receive(:org_members).and_return(Set.new(%w[blackmanx])) |
| 625 | + |
| 626 | + add_membership_response = { |
| 627 | + "url" => "https://github.fake/api/v3/teams/1001/memberships/blackmanx", |
| 628 | + "role" => "member", |
| 629 | + "state" => "active" |
| 630 | + } |
| 631 | + |
| 632 | + stub_request(:put, "https://github.fake/api/v3/teams/1001/memberships/blackmanx") |
| 633 | + .to_return( |
| 634 | + status: 404, |
| 635 | + headers: { |
| 636 | + "Content-type" => "application/json" |
| 637 | + }, |
| 638 | + body: JSON.generate({ |
| 639 | + "message" => "Not Found", |
| 640 | + "documentation_url" => "https://docs.github.com/rest" |
| 641 | + }) |
| 642 | + ) |
| 643 | + |
| 644 | + result = subject.send(:add_user_to_team, user: "blackmanx", team:) |
| 645 | + expect(result).to eq(false) |
| 646 | + end |
| 647 | + end |
583 | 648 | end |
584 | 649 |
|
585 | 650 | describe "#remove_user_from_team" do |
|
0 commit comments