From 72efedba614355b48109206ecf2cd3e2ce62731d Mon Sep 17 00:00:00 2001 From: William Boman Date: Sat, 8 Oct 2022 15:34:20 +0200 Subject: feat(registry): add api module (#524) --- tests/mason-registry/api_spec.lua | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/mason-registry/api_spec.lua (limited to 'tests') 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) -- cgit v1.2.3-70-g09d2