aboutsummaryrefslogtreecommitdiffstats
path: root/tests/mason-registry/api_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tests/mason-registry/api_spec.lua')
-rw-r--r--tests/mason-registry/api_spec.lua37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/mason-registry/api_spec.lua b/tests/mason-registry/api_spec.lua
new file mode 100644
index 00000000..b871520b
--- /dev/null
+++ b/tests/mason-registry/api_spec.lua
@@ -0,0 +1,37 @@
+local stub = require "luassert.stub"
+local Result = require "mason-core.result"
+
+describe("mason-registry API", function()
+ ---@module "mason-registry.api"
+ local api
+ local fetch
+ before_each(function()
+ fetch = stub.new()
+ package.loaded["mason-core.fetch"] = fetch
+ package.loaded["mason-registry.api"] = nil
+ api = require "mason-registry.api"
+ end)
+
+ it("should stringify query parameters", function()
+ fetch.returns(Result.success [[{}]])
+
+ api.get("/api/data", {
+ params = {
+ page = 2,
+ page_limit = 10,
+ sort = "ASC",
+ },
+ })
+
+ assert.spy(fetch).was_called(1)
+ assert.spy(fetch).was_called_with "https://api.mason-registry.dev/api/data?page=2&page_limit=10&sort=ASC"
+ end)
+
+ it("should deserialize JSON", function()
+ fetch.returns(Result.success [[{"field": ["value"]}]])
+
+ local result = api.get("/"):get_or_throw()
+
+ assert.same({ field = { "value" } }, result)
+ end)
+end)