@kintone/customize-uploader
Version:
A kintone customize uploader
116 lines • 4.28 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const KintoneApiClient_1 = __importDefault(require("../../KintoneApiClient"));
const ApiPath = {
File: "/k/v1/file.json",
Customize: "/k/v1/app/customize.json",
};
const ApiPreviewPath = {
Customize: "/k/v1/preview/app/customize.json",
Deploy: "/k/v1/preview/app/deploy.json",
};
class MockKintoneApiClient extends KintoneApiClient_1.default {
constructor(...args) {
super(...args);
this.logs = [];
this.willBeReturnResponse = {};
const appDeployResp = {
apps: [{ status: "SUCCESS" }],
};
this.willBeReturn(ApiPreviewPath.Deploy, "GET", appDeployResp)
.willBeReturn(ApiPreviewPath.Deploy, "POST", appDeployResp)
.willBeReturn(ApiPreviewPath.Customize, "PUT", {});
}
willBeReturn(path, method, willBeReturn) {
let byPath = this.willBeReturnResponse[path];
if (!byPath) {
byPath = {};
}
byPath[method] = willBeReturn;
this.willBeReturnResponse[path] = byPath;
return this;
}
getAppCustomize(appId) {
return __awaiter(this, void 0, void 0, function* () {
return this.getByPathResponse({
path: ApiPath.Customize,
method: "GET",
body: {
app: appId,
},
});
});
}
deploySetting(appId) {
return __awaiter(this, void 0, void 0, function* () {
return this.getByPathResponse({
path: ApiPreviewPath.Deploy,
method: "POST",
body: { apps: [{ app: appId }] },
});
});
}
downloadFile(fileKey) {
return __awaiter(this, void 0, void 0, function* () {
return this.getByPathResponse({
path: ApiPath.File,
method: "GET",
body: { fileKey },
});
});
}
waitFinishingDeploy(appId, callback) {
return __awaiter(this, void 0, void 0, function* () {
callback();
return this.getByPathResponse({
path: ApiPreviewPath.Deploy,
method: "GET",
body: { apps: [appId] },
});
});
}
uploadFile(filePath) {
return __awaiter(this, void 0, void 0, function* () {
return this.getByPathResponse({
path: ApiPath.File,
method: "POST",
});
});
}
updateCustomizeSetting(params) {
return __awaiter(this, void 0, void 0, function* () {
return this.getByPathResponse({
path: ApiPreviewPath.Customize,
method: "PUT",
body: params,
});
});
}
getByPathResponse(params) {
this.logs.push(params);
const method = params.method;
if (method === "POST" && params.path === ApiPath.File) {
return { fileKey: `key--${params.path}` };
}
const byPath = this.willBeReturnResponse[params.path];
if (!byPath || !byPath[params.method]) {
console.info(`not mocked request: [${params.method}] ${params.path} returns {}`);
return {};
}
return byPath[params.method];
}
}
exports.default = MockKintoneApiClient;
//# sourceMappingURL=MockKintoneApiClient.js.map