UNPKG

@kintone/dts-gen

Version:

Types for kintone js api and Types generating tools

103 lines 3.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const axios_utils_1 = require("./axios-utils"); const axios_1 = require("axios"); describe("FormsClientImpl#constructor", () => { const baseUrl = "https://kintone.com"; const authToken = Buffer.from("username:password").toString("base64"); const assertConstructorWithArgs = (input, expectedInput) => { axios_utils_1.VisibleForTesting.newAxiosInstanceInternal = jest.fn(); axios_utils_1.AxiosUtils.newAxiosInstance(input); expect(axios_utils_1.VisibleForTesting.newAxiosInstanceInternal).toBeCalledWith(expectedInput); }; test("with plain settings", () => { const input = { baseUrl, username: "username", password: "password", proxy: null, basicAuthPassword: null, basicAuthUsername: null, }; const headers = new axios_1.AxiosHeaders({ "X-Cybozu-Authorization": authToken, }); const expectedCalledWith = { headers, baseURL: baseUrl, proxy: undefined, }; assertConstructorWithArgs(input, expectedCalledWith); }); test("with proxy option", () => { const input = { baseUrl, username: "username", password: "password", proxy: "http://admin:password@localhost:1234", basicAuthPassword: null, basicAuthUsername: null, }; const headers = new axios_1.AxiosHeaders({ "X-Cybozu-Authorization": authToken, }); const expectedCalledWith = { headers, baseURL: baseUrl, proxy: { host: "localhost", port: 1234, protocol: "http:", auth: { username: "admin", password: "password", }, }, }; assertConstructorWithArgs(input, expectedCalledWith); }); test("with proxy option and empty proxy authorization", () => { const input = { baseUrl, username: "username", password: "password", proxy: "https://localhost:1234", basicAuthPassword: null, basicAuthUsername: null, }; const headers = new axios_1.AxiosHeaders({ "X-Cybozu-Authorization": authToken, }); const expectedCalledWith = { headers, baseURL: baseUrl, proxy: { protocol: "https:", host: "localhost", port: 1234, }, }; assertConstructorWithArgs(input, expectedCalledWith); }); test("with basic auth", () => { const input = { baseUrl, username: "username", password: "password", proxy: null, basicAuthPassword: "basicUsername", basicAuthUsername: "basicPassword", }; const headers = new axios_1.AxiosHeaders({ "X-Cybozu-Authorization": authToken, Authorization: "Basic YmFzaWNQYXNzd29yZDpiYXNpY1VzZXJuYW1l", }); const expectedCalledWith = { headers, baseURL: baseUrl, proxy: undefined, }; assertConstructorWithArgs(input, expectedCalledWith); }); }); //# sourceMappingURL=axios-utils.test.js.map