From bf087883b05082a07ec2abe22e904b227b21f0d3 Mon Sep 17 00:00:00 2001 From: William Boman Date: Tue, 14 Mar 2023 04:48:03 +0100 Subject: feat: add registry.refresh() method (#1096) --- tests/mason/api/command_spec.lua | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'tests') diff --git a/tests/mason/api/command_spec.lua b/tests/mason/api/command_spec.lua index aee08f6f..7b77bae3 100644 --- a/tests/mason/api/command_spec.lua +++ b/tests/mason/api/command_spec.lua @@ -1,6 +1,7 @@ local log = require "mason-core.log" local match = require "luassert.match" local spy = require "luassert.spy" +local stub = require "luassert.stub" local Pkg = require "mason-core.package" local a = require "mason-core.async" @@ -88,3 +89,43 @@ describe(":MasonLog", function() end) end) end) + +describe(":MasonUpdate", function() + it( + "should update registries", + async_test(function() + stub(registry, "update", function(cb) + cb(true, { {} }) + end) + spy.on(vim, "notify") + api.MasonUpdate() + assert.spy(vim.notify).was_called(1) + assert.spy(vim.notify).was_called_with("Updating registries…", vim.log.levels.INFO, { + title = "mason.nvim", + }) + a.scheduler() + assert.spy(vim.notify).was_called_with("Successfully updated 1 registry.", vim.log.levels.INFO, { + title = "mason.nvim", + }) + end) + ) + + it( + "should notify errors", + async_test(function() + stub(registry, "update", function(cb) + cb(false, "Some error.") + end) + spy.on(vim, "notify") + api.MasonUpdate() + assert.spy(vim.notify).was_called(1) + assert.spy(vim.notify).was_called_with("Updating registries…", vim.log.levels.INFO, { + title = "mason.nvim", + }) + a.scheduler() + assert.spy(vim.notify).was_called_with("Failed to update registries: Some error.", vim.log.levels.ERROR, { + title = "mason.nvim", + }) + end) + ) +end) -- cgit v1.2.3-70-g09d2