Class: Fbe::Graph::Fake

Inherits:
Object
  • Object
show all
Defined in:
lib/fbe/github_graph.rb

Overview

Fake GitHub GraphQL client for testing.

This class mocks the GraphQL client interface and returns predictable test data without making actual API calls. It’s used when the application is in testing mode.

Examples:

Using the fake client in tests

fake = Fbe::Graph::Fake.new
result = fake.total_commits('owner', 'repo', 'main')
# => 1484 (always returns the same value)

Instance Method Summary collapse

Instance Method Details

#issue_type_event(node_id) ⇒ Hash?

Returns mock issue type event data.

Examples:

fake.issue_type_event('ITAE_examplevq862Ga8lzwAAAAQZanzv')
# => {'type'=>'IssueTypeAddedEvent', ...}

Parameters:

  • node_id (String)

    The event node ID

Returns:

  • (Hash, nil)

    Event data for known IDs, nil otherwise



640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
# File 'lib/fbe/github_graph.rb', line 640

def issue_type_event(node_id)
  case node_id
  when 'ITAE_examplevq862Ga8lzwAAAAQZanzv'
    {
      'type' => 'IssueTypeAddedEvent',
      'created_at' => Time.parse('2025-05-11 18:17:16 UTC'),
      'issue_type' => {
        'id' => 'IT_exampleQls4BmRE0',
        'name' => 'Bug',
        'description' => 'An unexpected problem or behavior'
      },
      'prev_issue_type' => nil,
      'actor' => {
        'login' => 'yegor256',
        'type' => 'User',
        'id' => 526_301,
        'name' => 'Yegor',
        'email' => 'example@gmail.com'
      }
    }
  when 'ITCE_examplevq862Ga8lzwAAAAQZbq9S'
    {
      'type' => 'IssueTypeChangedEvent',
      'created_at' => Time.parse('2025-05-11 20:23:13 UTC'),
      'issue_type' => {
        'id' => 'IT_kwDODJdQls4BmREz',
        'name' => 'Task',
        'description' => 'A specific piece of work'
      },
      'prev_issue_type' => {
        'id' => 'IT_kwDODJdQls4BmRE0',
        'name' => 'Bug',
        'description' => 'An unexpected problem or behavior'
      },
      'actor' => {
        'login' => 'yegor256',
        'type' => 'User',
        'id' => 526_301,
        'name' => 'Yegor',
        'email' => 'example@gmail.com'
      }
    }
  when 'ITRE_examplevq862Ga8lzwAAAAQcqceV'
    {
      'type' => 'IssueTypeRemovedEvent',
      'created_at' => Time.parse('2025-05-11 22:09:42 UTC'),
      'issue_type' => {
        'id' => 'IT_kwDODJdQls4BmRE1',
        'name' => 'Feature',
        'description' => 'A request, idea, or new functionality'
      },
      'prev_issue_type' => nil,
      'actor' => {
        'login' => 'yegor256',
        'type' => 'User',
        'id' => 526_301,
        'name' => 'Yegor',
        'email' => 'example@gmail.com'
      }
    }
  end
end

#pull_request_reviews(_owner, _name) ⇒ Object



715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
# File 'lib/fbe/github_graph.rb', line 715

def pull_request_reviews(_owner, _name, **)
  [
    {
      'id' => 'PR_kwDOL6J6Ss6iprCx',
      'number' => 2,
      'reviews' => [
        { 'id' => 'PRR_kwDOL6J6Ss647NCl', 'submitted_at' => Time.parse('2025-10-02 12:58:42 UTC') },
        { 'id' => 'PRR_kwDOL6J6Ss647NC8', 'submitted_at' => Time.parse('2025-10-02 15:58:42 UTC') }
      ],
      'reviews_has_next_page' => false,
      'reviews_next_cursor' => 'yc29yOnYyO1'
    },
    {
      'id' => 'PR_kwDOL6J6Ss6rhJ7T',
      'number' => 5,
      'reviews' => [{ 'id' => 'PRR_kwDOL6J6Ss64_mnn', 'submitted_at' => Time.parse('2025-10-03 15:58:42 UTC') }],
      'reviews_has_next_page' => false,
      'reviews_next_cursor' => 'yc29yOnYyO2'
    },
    {
      'id' => 'PR_kwDOL6J6Ss6r13fG',
      'number' => 21,
      'reviews' => [{ 'id' => 'PRR_kwDOL6J6Ss65AbIA', 'submitted_at' => Time.parse('2025-10-04 15:58:42 UTC') }],
      'reviews_has_next_page' => false,
      'reviews_next_cursor' => 'yc29yOnYyO3'
    }
  ]
end

#pull_requests_with_reviews(_owner, _name, _since) ⇒ Object



703
704
705
706
707
708
709
710
711
712
713
# File 'lib/fbe/github_graph.rb', line 703

def pull_requests_with_reviews(_owner, _name, _since, **)
  {
    'pulls_with_reviews' => [
      { 'id' => 'PR_kwDOL6J6Ss6iprCx', 'number' => 2 },
      { 'id' => 'PR_kwDOL6J6Ss6rhJ7T', 'number' => 5 },
      { 'id' => 'PR_kwDOL6J6Ss6r13fG', 'number' => 21 }
    ],
    'has_next_page' => false,
    'next_cursor' => 'Y3Vyc29yOnYyOpHOdh_xUw=='
  }
end

#query(_query) ⇒ Hash

Executes a GraphQL query (mock implementation).

Parameters:

  • _query (String)

    The GraphQL query (ignored)

Returns:

  • (Hash)

    Empty hash



572
573
574
# File 'lib/fbe/github_graph.rb', line 572

def query(_query)
  {}
end

#resolved_conversations(owner, name, _number) ⇒ Array<Hash>

Returns mock resolved conversation threads.

Examples:

fake.resolved_conversations('zerocracy', 'baza', 42)
# => [conversation data for zerocracy_baza]

Parameters:

  • owner (String)

    Repository owner

  • name (String)

    Repository name

  • _number (Integer)

    Pull request number (ignored)

Returns:

  • (Array<Hash>)

    Array of conversation threads



585
586
587
588
# File 'lib/fbe/github_graph.rb', line 585

def resolved_conversations(owner, name, _number)
  data = { zerocracy_baza: [conversation('PRRT_kwDOK2_4A85BHZAR')] }
  data[:"#{owner}_#{name}"] || []
end

#total_commits(owner = nil, name = nil, branch = nil, repos: nil) ⇒ Integer, Array<Hash>

Returns mock total commit count.

Parameters:

  • owner (String) (defaults to: nil)

    Repository owner

  • name (String) (defaults to: nil)

    Repository name

  • branch (String) (defaults to: nil)

    Branch name

  • repos (Array<Array<String, String, String>>) (defaults to: nil)

    List of owner, name, branch

Returns:

  • (Integer, Array<Hash>)

    Returns 1484 for single repo or array of hashes

Raises:



612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
# File 'lib/fbe/github_graph.rb', line 612

def total_commits(owner = nil, name = nil, branch = nil, repos: nil) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
  raise(Fbe::Error, 'Need owner, name and branch or repos') if owner.nil? && name.nil? && branch.nil? && repos.nil?
  raise(Fbe::Error, 'Owner, name and branch is required') if (owner.nil? || name.nil? || branch.nil?) && repos.nil?
  raise(Fbe::Error, 'Repos list cannot be empty') if owner.nil? && name.nil? && branch.nil? && repos&.empty?
  if (!owner.nil? || !name.nil? || !branch.nil?) && !repos.nil?
    raise(Fbe::Error, 'Need only owner, name and branch or repos')
  end
  if owner && name && branch
    1484
  else
    repos.each_with_index.map do |(owner, name, branch), _i|
      {
        'owner' => owner,
        'name' => name,
        'branch' => branch,
        'total_commits' => 1484
      }
    end
  end
end

#total_commits_pushed(_owner, _name, _since) ⇒ Object



744
745
746
747
748
749
# File 'lib/fbe/github_graph.rb', line 744

def total_commits_pushed(_owner, _name, _since)
  {
    'commits' => 29,
    'hoc' => 1857
  }
end

#total_issues_and_pulls(_owner, _name) ⇒ Hash

Returns mock issue and pull request counts.

Examples:

fake.total_issues_and_pulls('owner', 'repo')
# => {"issues"=>23, "pulls"=>19}

Parameters:

  • _owner (String)

    Repository owner (ignored)

  • _name (String)

    Repository name (ignored)

Returns:

  • (Hash)

    Hash with ‘issues’ and ‘pulls’ counts



598
599
600
601
602
603
# File 'lib/fbe/github_graph.rb', line 598

def total_issues_and_pulls(_owner, _name)
  {
    'issues' => 23,
    'pulls' => 19
  }
end

#total_issues_created(_owner, _name, _since) ⇒ Object



751
752
753
754
755
756
# File 'lib/fbe/github_graph.rb', line 751

def total_issues_created(_owner, _name, _since)
  {
    'issues' => 17,
    'pulls' => 8
  }
end

#total_releases_published(_owner, _name, _since) ⇒ Object



758
759
760
# File 'lib/fbe/github_graph.rb', line 758

def total_releases_published(_owner, _name, _since)
  { 'releases' => 7 }
end