Skip to content

Commit

Permalink
test(test-cmd-api-server): jestify plugin-import-with-npm-install-ver…
Browse files Browse the repository at this point in the history
…sion

Signed-off-by: Peter Somogyvari <[email protected]>
  • Loading branch information
petermetz committed Sep 30, 2024
1 parent fb3286c commit 499f703
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 56 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2200,8 +2200,7 @@ jobs:
JEST_TEST_RUNNER_DISABLED: false
JEST_TEST_COVERAGE_PATH: ./code-coverage-ts/ct-cmd-api-server
JEST_TEST_CODE_COVERAGE_ENABLED: true
TAPE_TEST_PATTERN: ./packages/cactus-test-cmd-api-server/src/test/typescript/integration/plugin-import-with-npm-install-version-selection.test.ts
TAPE_TEST_RUNNER_DISABLED: false
TAPE_TEST_RUNNER_DISABLED: true
runs-on: ubuntu-22.04
steps:
- name: Use Node.js ${{ env.NODEJS_VERSION }}
Expand Down
1 change: 0 additions & 1 deletion .taprc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ files:
- ./packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/get-status-endpoint.test.ts
- ./packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/openapi/openapi-validation.test.ts
- ./packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/refund-endpoint.test.ts
- ./packages/cactus-test-cmd-api-server/src/test/typescript/integration/plugin-import-with-npm-install-version-selection.test.ts
- ./packages/cactus-plugin-ledger-connector-corda/src/test/typescript/integration/openapi/openapi-validation.test.ts
- ./packages/cactus-plugin-ledger-connector-corda/src/test/typescript/integration/flow-database-access-v4.8.test.ts
- ./packages/cactus-test-plugin-consortium-manual/src/test/typescript/integration/plugin-consortium-manual/openapi/openapi-validation.test.ts
Expand Down
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ module.exports = {
`./packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/get-status-endpoint.test.ts`,
`./packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/openapi/openapi-validation.test.ts`,
`./packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/refund-endpoint.test.ts`,
`./packages/cactus-test-cmd-api-server/src/test/typescript/integration/plugin-import-with-npm-install-version-selection.test.ts`,
`./packages/cactus-plugin-ledger-connector-corda/src/test/typescript/integration/openapi/openapi-validation.test.ts`,
`./packages/cactus-plugin-ledger-connector-corda/src/test/typescript/integration/flow-database-access-v4.8.test.ts`,
`./packages/cactus-test-plugin-consortium-manual/src/test/typescript/integration/plugin-consortium-manual/openapi/openapi-validation.test.ts`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import path from "path";
import test, { Test } from "tape-promise/tape";
import { v4 as uuidv4 } from "uuid";
import { readFile } from "fs/promises";
import { randomUUID as uuidv4 } from "node:crypto";
import path from "node:path";
import { readFile } from "node:fs/promises";

import "jest-extended";

import { LogLevelDesc } from "@hyperledger/cactus-common";
import {
PluginImport,
PluginImportAction,
PluginImportType,
} from "@hyperledger/cactus-core-api";
Expand All @@ -14,9 +16,9 @@ import {
ConfigService,
} from "@hyperledger/cactus-cmd-api-server";

const logLevel: LogLevelDesc = "TRACE";
const logLevel: LogLevelDesc = "INFO";

test("can install plugins at runtime with specified version based on imports", async (t: Test) => {
describe("ApiServer", () => {
const pluginsPath = path.join(
__dirname,
"../../../../../../", // walk back up to the project root
Expand All @@ -25,59 +27,61 @@ test("can install plugins at runtime with specified version based on imports", a
);
const pluginManagerOptionsJson = JSON.stringify({ pluginsPath });

const configService = new ConfigService();

const apiServerOptions = await configService.newExampleConfig();
apiServerOptions.pluginManagerOptionsJson = pluginManagerOptionsJson;
apiServerOptions.authorizationProtocol = AuthorizationProtocol.NONE;
apiServerOptions.configFile = "";
apiServerOptions.apiCorsDomainCsv = "*";
apiServerOptions.apiPort = 0;
apiServerOptions.cockpitPort = 0;
apiServerOptions.grpcPort = 0;
apiServerOptions.crpcPort = 0;
apiServerOptions.apiTlsEnabled = false;
apiServerOptions.plugins = [
{
packageName: "@hyperledger/cactus-plugin-keychain-memory",
type: PluginImportType.Local,
action: PluginImportAction.Install,
options: {
instanceId: uuidv4(),
keychainId: uuidv4(),
logLevel,
version: "0.9.0",
},
const aPluginImport: PluginImport = {
packageName: "@hyperledger/cactus-plugin-keychain-memory",
type: PluginImportType.Local,
action: PluginImportAction.Install,
options: {
instanceId: uuidv4(),
keychainId: uuidv4(),
logLevel,
version: "0.9.0",
},
];
const config = await configService.newExampleConfigConvict(apiServerOptions);

const apiServer = new ApiServer({
config: config.getProperties(),
});

const startResponse = apiServer.start();
await t.doesNotReject(
startResponse,
"failed to start API server with dynamic plugin imports configured for it...",
);
t.ok(startResponse, "startResponse truthy OK");
};

const packageFilePath = path.join(
pluginsPath,
apiServerOptions.plugins[0].options.instanceId,
aPluginImport.options.instanceId,
"node_modules",
`${apiServerOptions.plugins[0].packageName}`,
`${aPluginImport.packageName}`,
"package.json",
);
const pkgJsonStr = await readFile(packageFilePath, "utf-8");
const { version } = JSON.parse(pkgJsonStr);

t.strictEquals(
version,
apiServerOptions.plugins[0].options.version,
`Package version strictly equal to ${version}`,
);
const configService = new ConfigService();

test.onFinish(() => apiServer.shutdown());
let apiServer: ApiServer;

beforeAll(async () => {
const apiSrvOpts = await configService.newExampleConfig();
apiSrvOpts.pluginManagerOptionsJson = pluginManagerOptionsJson;
apiSrvOpts.authorizationProtocol = AuthorizationProtocol.NONE;
apiSrvOpts.logLevel = logLevel;
apiSrvOpts.configFile = "";
apiSrvOpts.apiCorsDomainCsv = "*";
apiSrvOpts.apiPort = 0;
apiSrvOpts.cockpitPort = 0;
apiSrvOpts.grpcPort = 0;
apiSrvOpts.crpcPort = 0;
apiSrvOpts.apiTlsEnabled = false;
apiSrvOpts.plugins = [aPluginImport];
const config = await configService.newExampleConfigConvict(apiSrvOpts);

apiServer = new ApiServer({
config: config.getProperties(),
});
});

afterAll(async () => {
await apiServer.shutdown();
});

test("can install plugins at runtime with specified version based on imports", async () => {
const startResponse = apiServer.start();
await expect(startResponse).toResolve();

const pkgJsonStr = await readFile(packageFilePath, "utf-8");
const { version } = JSON.parse(pkgJsonStr);

expect(version).toEqual(aPluginImport.options.version);
});
});

0 comments on commit 499f703

Please sign in to comment.