aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-10-08 15:34:20 +0200
committerGitHub <noreply@github.com>2022-10-08 15:34:20 +0200
commit72efedba614355b48109206ecf2cd3e2ce62731d (patch)
tree347a95b2d88ef77256c09939e98a3d9fa6b715f5 /tests
parentfeat(registry): add pylama linter (#523) (diff)
downloadmason-72efedba614355b48109206ecf2cd3e2ce62731d.tar
mason-72efedba614355b48109206ecf2cd3e2ce62731d.tar.gz
mason-72efedba614355b48109206ecf2cd3e2ce62731d.tar.bz2
mason-72efedba614355b48109206ecf2cd3e2ce62731d.tar.lz
mason-72efedba614355b48109206ecf2cd3e2ce62731d.tar.xz
mason-72efedba614355b48109206ecf2cd3e2ce62731d.tar.zst
mason-72efedba614355b48109206ecf2cd3e2ce62731d.zip
feat(registry): add api module (#524)
Diffstat (limited to 'tests')
-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)