Skip to content

Commit

Permalink
feat: Updated test/plugin_spec.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] authored Oct 25, 2023
1 parent f51691a commit 22ee6ad
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions test/plugin_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
describe('Hurl.nvim plugin', function()
it('should be able to load', function()
local hurl = require('hurl')
local utils = require('hurl.utils')
assert.truthy(hurl)

assert.are.same('popup', _HURL_CFG.mode)
Expand All @@ -21,39 +22,52 @@ describe('Hurl.nvim plugin', function()
local utils = require('hurl.utils')

it('should correctly log info', function()
-- TODO: add a test to check log_info function
utils.log_info('Test info message')
assert.spy(log.info).was.called_with('Test info message')
end)

it('should correctly log error', function()
-- TODO: add a test to check log_error function
utils.log_error('Test error message')
assert.spy(log.error).was.called_with('Test error message')
end)

it('should correctly get visual selection', function()
-- TODO: add a test to check get_visual_selection function
vim.fn.setpos("'<", { 0, 1, 1, 0 })
vim.fn.setpos("'>", { 0, 1, 1, 0 })
local selection = utils.get_visual_selection()
assert.are.same({ 'GET http://example.com' }, selection)
end)

it('should correctly create tmp file', function()
-- TODO: add a test to check create_tmp_file function
local tmp_file = utils.create_tmp_file('Test content')
assert.truthy(tmp_file)
os.remove(tmp_file)
end)

it('should correctly create custom command', function()
-- TODO: add a test to check create_cmd function
utils.create_cmd('TestCommand', function() print('Test command') end, { desc = 'Test description' })
assert.truthy(vim.fn.exists(':TestCommand'))
end)

it('should correctly format the body of the request', function()
-- TODO: add a test to check format function
local formatted_body = utils.format('{"test": "value"}', 'json')
assert.are.same({ '{', ' "test": "value"', '}' }, formatted_body)
end)

it('should correctly render header table', function()
-- TODO: add a test to check render_header_table function
local headers = { ['Content-Type'] = 'application/json', ['Accept'] = 'application/json' }
local rendered_headers = utils.render_header_table(headers)
assert.are.same({ 'Content-Type | application/json', 'Accept | application/json' }, rendered_headers.headers)
end)

it('should correctly check if the response is json', function()
-- TODO: add a test to check is_json_response function
local is_json = utils.is_json_response('application/json')
assert.is_true(is_json)
end)

it('should correctly check if the response is html', function()
-- TODO: add a test to check is_html_response function
local is_html = utils.is_html_response('text/html')
assert.is_true(is_html)
end)
end)
end)

0 comments on commit 22ee6ad

Please sign in to comment.