@kintone/dts-gen
Version:
Types for kintone js api and Types generating tools
79 lines • 2.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const forms_client_impl_1 = require("./forms-client-impl");
const axios_utils_1 = require("./axios-utils");
describe("VisibleForTesting.constructUrl", () => {
const testCases = [
{
preview: false,
guestSpaceId: "1",
expected: "/k/guest/1/v1/app/form/fields.json",
},
{
preview: false,
guestSpaceId: null,
expected: "/k/v1/app/form/fields.json",
},
{
preview: true,
guestSpaceId: "1",
expected: "/k/guest/1/v1/preview/app/form/fields.json",
},
{
preview: true,
guestSpaceId: null,
expected: "/k/v1/preview/app/form/fields.json",
},
];
test.each(testCases)("constructUrl with %p", ({ preview, guestSpaceId, expected }) => {
const input = {
appId: "123",
preview,
guestSpaceId,
};
expect(forms_client_impl_1.VisibleForTesting.constructUrl(input)).toEqual(expected);
});
});
describe("FormsClientImpl#fetchFormProperties", () => {
test("#fertchFormProperties calls AxoisInstance#request", () => {
const mockConstructUrl = jest.fn();
mockConstructUrl.mockReturnValue("/k/v1/app/form/fields.json");
forms_client_impl_1.VisibleForTesting.constructUrl = mockConstructUrl;
const mockRequest = jest.fn();
mockRequest.mockReturnValue(Promise.resolve({
data: {
properties: {},
},
}));
const mockNewAxiosInstance = jest.fn();
mockNewAxiosInstance.mockReturnValue({
request: mockRequest,
});
axios_utils_1.AxiosUtils.newAxiosInstance = mockNewAxiosInstance;
const input = {
baseUrl: "https://kintone.com",
username: "username",
password: "password",
apiToken: null,
oAuthToken: null,
proxy: null,
basicAuthPassword: null,
basicAuthUsername: null,
};
const fetchInput = {
appId: "1",
preview: false,
guestSpaceId: null,
};
new forms_client_impl_1.FormsClientImpl(input).fetchFormProperties(fetchInput);
const expectedRequestConfig = {
method: "GET",
url: "/k/v1/app/form/fields.json",
params: {
app: "1",
},
};
expect(mockRequest).toBeCalledWith(expectedRequestConfig);
});
});
//# sourceMappingURL=forms-client-impl.test.js.map