fix(test): more mocks

This commit is contained in:
Barrett Ruth 2025-09-22 23:14:54 -04:00
parent a84b1697bf
commit 4b70a21210
3 changed files with 15 additions and 22 deletions

View file

@ -75,15 +75,11 @@ describe('async integration', function()
end, end,
} }
local cmd_methods = { vim.cmd = function() end
e = function() end, vim.cmd.e = function() end
only = function() end, vim.cmd.only = function() end
startinsert = function() end, vim.cmd.startinsert = function() end
stopinsert = function() end, vim.cmd.stopinsert = function() end
}
vim.cmd = setmetatable(function() end, {
__index = cmd_methods,
})
vim.api.nvim_get_current_buf = function() vim.api.nvim_get_current_buf = function()
return 1 return 1
end end
@ -183,7 +179,7 @@ describe('async integration', function()
it('handles language flags correctly', function() it('handles language flags correctly', function()
local language_passed = nil local language_passed = nil
local mock_async_setup = { local mock_async_setup = {
setup_contest_async = function(contest_id, language) setup_contest_async = function(_, language)
language_passed = language language_passed = language
end, end,
} }

View file

@ -69,15 +69,11 @@ describe('cp.async.setup', function()
end, end,
} }
local cmd_methods = { vim.cmd = function() end
e = function() end, vim.cmd.e = function() end
only = function() end, vim.cmd.only = function() end
startinsert = function() end, vim.cmd.startinsert = function() end
stopinsert = function() end, vim.cmd.stopinsert = function() end
}
vim.cmd = setmetatable(function() end, {
__index = cmd_methods,
})
vim.api.nvim_get_current_buf = function() vim.api.nvim_get_current_buf = function()
return 1 return 1
end end
@ -126,7 +122,7 @@ describe('cp.async.setup', function()
end) end)
it('handles metadata scraping failure gracefully', function() it('handles metadata scraping failure gracefully', function()
mock_scraper.scrape_contest_metadata_async = function(platform, contest_id, callback) mock_scraper.scrape_contest_metadata_async = function(_, _, callback)
callback({ callback({
success = false, success = false,
error = 'network error', error = 'network error',
@ -210,7 +206,7 @@ describe('cp.async.setup', function()
describe('handle_full_setup_async', function() describe('handle_full_setup_async', function()
it('validates problem exists in contest', function() it('validates problem exists in contest', function()
mock_scraper.scrape_contest_metadata_async = function(platform, contest_id, callback) mock_scraper.scrape_contest_metadata_async = function(_, _, callback)
callback({ callback({
success = true, success = true,
problems = { { id = 'a' }, { id = 'b' } }, problems = { { id = 'a' }, { id = 'b' } },
@ -230,7 +226,7 @@ describe('cp.async.setup', function()
end) end)
it('proceeds with valid problem', function() it('proceeds with valid problem', function()
mock_scraper.scrape_contest_metadata_async = function(platform, contest_id, callback) mock_scraper.scrape_contest_metadata_async = function(_, _, callback)
callback({ callback({
success = true, success = true,
problems = { { id = 'a' }, { id = 'b' } }, problems = { { id = 'a' }, { id = 'b' } },

View file

@ -22,6 +22,7 @@ describe('cp command parsing', function()
set_platform = function() set_platform = function()
return true return true
end, end,
navigate_problem = function() end,
} }
package.loaded['cp.setup'] = mock_setup package.loaded['cp.setup'] = mock_setup