Problem: Log messages used inconsistent capitalization, punctuation, and phrasing — some started lowercase, some omitted periods, "Pending" was used instead of "task", and sync backend errors used ad-hoc formatting. Solution: Apply sentence case after backend prefixes, add trailing periods to complete sentences, rename "Pending" to "task", use `'Failed to <verb> <noun>: '` pattern for operation errors, and pluralize "Archived N task(s)" correctly.
114 lines
2.9 KiB
Lua
114 lines
2.9 KiB
Lua
require('spec.helpers')
|
|
|
|
local config = require('pending.config')
|
|
|
|
describe('sync', function()
|
|
local tmpdir
|
|
local pending
|
|
|
|
before_each(function()
|
|
tmpdir = vim.fn.tempname()
|
|
vim.fn.mkdir(tmpdir, 'p')
|
|
vim.g.pending = { data_path = tmpdir .. '/tasks.json' }
|
|
config.reset()
|
|
package.loaded['pending'] = nil
|
|
pending = require('pending')
|
|
end)
|
|
|
|
after_each(function()
|
|
vim.fn.delete(tmpdir, 'rf')
|
|
vim.g.pending = nil
|
|
config.reset()
|
|
package.loaded['pending'] = nil
|
|
end)
|
|
|
|
describe('dispatch', function()
|
|
it('errors on unknown subcommand', function()
|
|
local msg
|
|
local orig = vim.notify
|
|
vim.notify = function(m, level)
|
|
if level == vim.log.levels.ERROR then
|
|
msg = m
|
|
end
|
|
end
|
|
pending.command('notreal')
|
|
vim.notify = orig
|
|
assert.are.equal('[pending.nvim]: Unknown subcommand: notreal', msg)
|
|
end)
|
|
|
|
it('errors on unknown action for valid backend', function()
|
|
local msg
|
|
local orig = vim.notify
|
|
vim.notify = function(m, level)
|
|
if level == vim.log.levels.ERROR then
|
|
msg = m
|
|
end
|
|
end
|
|
pending.command('gcal notreal')
|
|
vim.notify = orig
|
|
assert.are.equal("[pending.nvim]: gcal: No 'notreal' action.", msg)
|
|
end)
|
|
|
|
it('lists actions when action is omitted', function()
|
|
local msg = nil
|
|
local orig = vim.notify
|
|
vim.notify = function(m)
|
|
msg = m
|
|
end
|
|
pending.command('gcal')
|
|
vim.notify = orig
|
|
assert.is_not_nil(msg)
|
|
assert.is_truthy(msg:find('push'))
|
|
end)
|
|
|
|
it('routes explicit push action', function()
|
|
local called = false
|
|
local gcal = require('pending.sync.gcal')
|
|
local orig_push = gcal.push
|
|
gcal.push = function()
|
|
called = true
|
|
end
|
|
pending.command('gcal push')
|
|
gcal.push = orig_push
|
|
assert.is_true(called)
|
|
end)
|
|
|
|
it('routes auth command', function()
|
|
local called = false
|
|
local orig_auth = pending.auth
|
|
pending.auth = function()
|
|
called = true
|
|
end
|
|
pending.command('auth')
|
|
pending.auth = orig_auth
|
|
assert.is_true(called)
|
|
end)
|
|
end)
|
|
|
|
it('works with sync.gcal config', function()
|
|
config.reset()
|
|
vim.g.pending = {
|
|
data_path = tmpdir .. '/tasks.json',
|
|
sync = { gcal = { client_id = 'test-id' } },
|
|
}
|
|
local cfg = config.get()
|
|
assert.are.equal('test-id', cfg.sync.gcal.client_id)
|
|
end)
|
|
|
|
describe('gcal module', function()
|
|
it('has name field', function()
|
|
local gcal = require('pending.sync.gcal')
|
|
assert.are.equal('gcal', gcal.name)
|
|
end)
|
|
|
|
it('has push function', function()
|
|
local gcal = require('pending.sync.gcal')
|
|
assert.are.equal('function', type(gcal.push))
|
|
end)
|
|
|
|
it('has health function', function()
|
|
local gcal = require('pending.sync.gcal')
|
|
assert.are.equal('function', type(gcal.health))
|
|
end)
|
|
end)
|
|
end)
|