import { getAuthHeaderOptions, addQueryParams } from "./http";

describe("HTTP Helper", () => {
  it("Authorization header", () => {
    const result = getAuthHeaderOptions("TEST_TOKEN");

    expect(result).toBeTruthy();
    expect(result.Authorization).toBeTruthy();
    expect(result.Authorization).toEqual("Bearer TEST_TOKEN");
  });

  describe("addQueryParams", () => {
    it("String and number params", () => {
      const params = {
        a: "a",
        b: "b",
        c: 1,
        d: 3.14,
      }
      const result = addQueryParams("http://example.com", params);
  
      expect(result).toEqual("http://example.com/?a=a&b=b&c=1&d=3.14");
    });

    it("Null params", () => {
      const params =  null;
      const result = addQueryParams("http://example.com", params);
  
      expect(result).toEqual("http://example.com");
    });

    it("Undefined params", () => {
      const result = addQueryParams("http://example.com");
      expect(result).toEqual("http://example.com");
    });

    it("Empty params", () => {
      const result = addQueryParams("http://example.com", {});
      expect(result).toEqual("http://example.com/");
    });
  })
});
