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



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
# File 'lib/fbe/github_graph.rb', line 343

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

#query(_query) ⇒ Hash

Executes a GraphQL query (mock implementation).

Parameters:

  • _query (String)

    The GraphQL query (ignored)

Returns:

  • (Hash)

    Empty hash



289
290
291
# File 'lib/fbe/github_graph.rb', line 289

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



302
303
304
305
306
307
308
309
# File 'lib/fbe/github_graph.rb', line 302

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

#total_commits(_owner, _name, _branch) ⇒ Integer

Returns mock total commit count.

Parameters:

  • _owner (String)

    Repository owner (ignored)

  • _name (String)

    Repository name (ignored)

  • _branch (String)

    Branch name (ignored)

Returns:

  • (Integer)

    Always returns 1484



332
333
334
# File 'lib/fbe/github_graph.rb', line 332

def total_commits(_owner, _name, _branch)
  1484
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



319
320
321
322
323
324
# File 'lib/fbe/github_graph.rb', line 319

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