@kintone/customize-uploader
Version:
A kintone customize uploader
220 lines • 9.09 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const assert_1 = __importDefault(require("assert"));
const fs = __importStar(require("fs"));
const rimraf_1 = require("rimraf");
const import_1 = require("../import");
const MockKintoneApiClient_1 = __importDefault(require("./MockKintoneApiClient"));
describe("import", () => {
const testDestDir = "testDestDir";
const filesToTestContent = [
`${testDestDir}/desktop/js/bootstrap.min.js`,
`${testDestDir}/desktop/js/a.js`,
`${testDestDir}/desktop/css/bootstrap.min.css`,
`${testDestDir}/desktop/css/bootstrap-reboot.min.css`,
`${testDestDir}/desktop/css/bootstrap-grid.min.css`,
`${testDestDir}/mobile/js/bootstrap.js`,
`${testDestDir}/mobile/js/b.js`,
];
const uploadFileBody = `(function() { console.log("hello"); })();`;
describe("runImport", () => {
let kintoneApiClient;
let manifest;
let status;
let options;
beforeEach(() => {
kintoneApiClient = new MockKintoneApiClient_1.default("kintone", "hogehoge", "oAuthToken", "basicAuthUser", "basicAuthPass", "https://example.com", {
proxy: "",
guestSpaceId: 0,
});
manifest = {
app: "1",
};
status = {
retryCount: 0,
};
options = {
lang: "en",
proxy: "",
guestSpaceId: 0,
destDir: testDestDir,
};
});
afterEach(() => {
(0, rimraf_1.rimrafSync)(`${testDestDir}`);
});
const assertManifestContent = (buffer) => {
const appCustomize = {
app: "1",
scope: "ALL",
desktop: {
js: [
"https://js.cybozu.com/vuejs/v2.5.17/vue.min.js",
"https://js.cybozu.com/lodash/4.17.11/lodash.min.js",
`${testDestDir}/desktop/js/bootstrap.min.js`,
`${testDestDir}/desktop/js/a.js`,
],
css: [
`${testDestDir}/desktop/css/bootstrap.min.css`,
`${testDestDir}/desktop/css/bootstrap-reboot.min.css`,
`${testDestDir}/desktop/css/bootstrap-grid.min.css`,
],
},
mobile: {
js: [
"https://js.cybozu.com/jquery/3.3.1/jquery.min.js",
"https://js.cybozu.com/jqueryui/1.12.1/jquery-ui.min.js",
`${testDestDir}/mobile/js/bootstrap.js`,
`${testDestDir}/mobile/js/b.js`,
],
css: [
`${testDestDir}/mobile/css/bootstrap.min.css`,
`${testDestDir}/mobile/css/bootstrap-reboot.min.css`,
`${testDestDir}/mobile/css/bootstrap-grid.min.css`,
],
},
};
assert_1.default.deepStrictEqual(JSON.parse(buffer.toString()), appCustomize);
};
const assertDownloadFile = (path) => {
assert_1.default.ok(fs.existsSync(path), `test ${path} is exists`);
const content = fs.readFileSync(path);
assert_1.default.strictEqual(uploadFileBody, content.toString());
};
const assertImportUseCaseApiRequest = (mockKintoneApiClient) => {
const expected = [
{
body: {
app: "1",
},
method: "GET",
path: "/k/v1/app/customize.json",
},
{
body: {
fileKey: "20181116095653774F24C632AF46E69BDC8F5EF04C8E24014",
},
method: "GET",
path: "/k/v1/file.json",
},
{
body: {
fileKey: "20181116095653FF8D40EE4B364FD89A2B3A382EDCB259286",
},
method: "GET",
path: "/k/v1/file.json",
},
{
body: {
fileKey: "201811160956531AFF9246D7CB40938A91EAC14A0622C9250",
},
method: "GET",
path: "/k/v1/file.json",
},
{
body: {
fileKey: "201811160956531DCC5DA8C6E0480C8F3BD8A92EEFF584123",
},
method: "GET",
path: "/k/v1/file.json",
},
{
body: {
fileKey: "20181116095653A6A52415705D403A9B1AB36E1448B32E191",
},
method: "GET",
path: "/k/v1/file.json",
},
{
body: {
fileKey: "20181116095653C06A1FE34CFD43D6B21BE7F55D3B6ECB031",
},
method: "GET",
path: "/k/v1/file.json",
},
{
body: {
fileKey: "201811160956535E4F00740689488C9ABE7DCF3E794B34315",
},
method: "GET",
path: "/k/v1/file.json",
},
{
body: {
fileKey: "201811160956531AFF9246D7CB40938A91EAC14A0622C9250",
},
method: "GET",
path: "/k/v1/file.json",
},
{
body: {
fileKey: "201811160956531DCC5DA8C6E0480C8F3BD8A92EEFF584123",
},
method: "GET",
path: "/k/v1/file.json",
},
{
body: {
fileKey: "20181116095653A6A52415705D403A9B1AB36E1448B32E191",
},
method: "GET",
path: "/k/v1/file.json",
},
];
assert_1.default.deepStrictEqual(mockKintoneApiClient.logs, expected);
};
it("should success updating customize-manifest.json and downloading uploaded js/css files", () => {
const getAppCustomizeResponse = JSON.parse(fs
.readFileSync("src/commands/__tests__/fixtures/get-appcustomize-response.json")
.toString());
kintoneApiClient.willBeReturn("/k/v1/file.json", "GET", uploadFileBody);
kintoneApiClient.willBeReturn("/k/v1/app/customize.json", "GET", getAppCustomizeResponse);
const execCommand = (0, import_1.importCustomizeSetting)(kintoneApiClient, manifest, status, options);
return execCommand.then(() => {
assertImportUseCaseApiRequest(kintoneApiClient);
const manifestFile = `${testDestDir}/customize-manifest.json`;
assert_1.default.ok(fs.existsSync(manifestFile), `test ${manifestFile} exists`);
const contents = fs.readFileSync(manifestFile);
assertManifestContent(contents);
filesToTestContent.map(assertDownloadFile);
});
});
});
});
//# sourceMappingURL=import.test.js.map