Skip to content

Commit

Permalink
sdkTransformer: Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomByte committed Mar 14, 2019
1 parent ca55c37 commit 480b832
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions test/lib/processors/jsdoc/sdkTransformer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const {test} = require("ava");
const sinon = require("sinon");
const mock = require("mock-require");
const sdkTransformer = require("../../../../lib/processors/jsdoc/sdkTransformer");

test.afterEach.always((t) => {
sinon.restore();
});

test.serial("sdkTransformer", async (t) => {
const transformerStub = sinon.stub().resolves("api.json content");
mock("../../../../lib/processors/jsdoc/lib/transform-apijson-for-sdk", transformerStub);
const createResourceStub = sinon.stub(require("@ui5/fs").resourceFactory, "createResource")
.returns("result resource");

const sdkTransformer = mock.reRequire("../../../../lib/processors/jsdoc/sdkTransformer");

const res = await sdkTransformer({
apiJsonPath: "/some/path/api.json",
dotLibraryPath: "/some/path/.library",
targetApiJsonPath: "/some/other/path/api.json",
dependencyApiJsonPaths: [
"/some/path/x/api.json",
"/some/path/y/api.json"
],
fs: "custom fs"
});

t.deepEqual(res.length, 1, "Returned one resource");
t.deepEqual(res[0], "result resource", "Returned one resource");

t.deepEqual(transformerStub.callCount, 1, "generateJsdocConfig called once");
t.deepEqual(transformerStub.getCall(0).args[0], "/some/path/api.json",
"transform-apijson-for-sdk called with correct argument #1");
t.deepEqual(transformerStub.getCall(0).args[1], "/ignore/this/path/resource/will/be/returned",
"transform-apijson-for-sdk called with correct argument #2");
t.deepEqual(transformerStub.getCall(0).args[2], "/some/path/.library",
"transform-apijson-for-sdk called with correct argument #3");
t.deepEqual(transformerStub.getCall(0).args[3], [
"/some/path/x/api.json",
"/some/path/y/api.json"
], "transform-apijson-for-sdk called with correct argument #4");
t.deepEqual(transformerStub.getCall(0).args[4], {
customFs: "custom fs",
returnOutputFile: true
}, "transform-apijson-for-sdk called with correct argument #5");

t.deepEqual(createResourceStub.callCount, 1, "createResource called once");
t.deepEqual(createResourceStub.getCall(0).args[0], {
path: "/some/other/path/api.json",
string: "api.json content"
}, "createResource called with correct arguments");

mock.stop("../../../../lib/processors/jsdoc/lib/transform-apijson-for-sdk");
});

test("sdkTransformer missing parameters", async (t) => {
const error = await t.throws(sdkTransformer());
t.deepEqual(error.message, "[sdkTransformer]: One or more mandatory parameters not provided",
"Correct error message thrown");
});

0 comments on commit 480b832

Please sign in to comment.