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



558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
# File 'lib/fbe/github_graph.rb', line 558

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' => '[email protected]'
      }
    }
  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' => '[email protected]'
      }
    }
  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' => '[email protected]'
      }
    }
  end
end

#pull_request_reviews(_owner, _name) ⇒ Object



633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
# File 'lib/fbe/github_graph.rb', line 633

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



621
622
623
624
625
626
627
628
629
630
631
# File 'lib/fbe/github_graph.rb', line 621

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



488
489
490
# File 'lib/fbe/github_graph.rb', line 488

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



501
502
503
504
505
506
507
508
# File 'lib/fbe/github_graph.rb', line 501

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



532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
# File 'lib/fbe/github_graph.rb', line 532

def total_commits(owner = nil, name = nil, branch = nil, repos: nil)
  raise 'Need owner, name and branch or repos' if owner.nil? && name.nil? && branch.nil? && repos.nil?
  raise 'Owner, name and branch is required' if (owner.nil? || name.nil? || branch.nil?) && repos.nil?
  raise 'Repos list cannot be empty' if owner.nil? && name.nil? && branch.nil? && repos&.empty?
  raise 'Need only owner, name and branch or repos' if (!owner.nil? || !name.nil? || !branch.nil?) && !repos.nil?
  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



662
663
664
665
666
667
# File 'lib/fbe/github_graph.rb', line 662

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



518
519
520
521
522
523
# File 'lib/fbe/github_graph.rb', line 518

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