Skip to content

Commit

Permalink
fix: add Unit Tests for Api-Server configuration testing
Browse files Browse the repository at this point in the history
Unit tests for testing default config behaviour + user-defined
configuration for shutdown hook

Closes: hyperledger-cacti#1619
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
  • Loading branch information
m-courtin committed Dec 10, 2021
1 parent 9058b20 commit 8b06f66
Showing 1 changed file with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import "jest-extended";
import {
ApiServer,
// AuthorizationProtocol,
ConfigService,
} from "../../../../main/typescript/public-api";

describe("api-server shutdown-hook configuration tests", () => {
// create a config service as base for the following UTs
const configService = new ConfigService();

it("enables the shutdown hook based on schema-default", async () => {
const expectedResult = true;
const apiServerOptions = await configService.newExampleConfig();
const config = await configService.newExampleConfigConvict(
apiServerOptions,
);

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

// check apiServerOptions
expect(apiServerOptions).not.toBeUndefined();
expect(apiServerOptions.enableShutdownHook).toBe(expectedResult);

// check apiServer
expect(apiServer).toBeTruthy();
const result = apiServer["enableShutdownHook"];
expect(result).toBe(expectedResult);
});

it("disables the shutdown hook based on the config value set to false", async () => {
const expectedResult = false;
const apiServerOptions = await configService.newExampleConfig();

// disable shutdown hook
apiServerOptions.enableShutdownHook = false;

const config = await configService.newExampleConfigConvict(
apiServerOptions,
true,
);

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

// check apiServerOptions
expect(apiServerOptions).not.toBeUndefined();
expect(apiServerOptions.enableShutdownHook).toBe(expectedResult);

// check apiServer
expect(apiServer).toBeTruthy();
const result = apiServer["enableShutdownHook"];
expect(result).toBe(expectedResult);
});

it("enables the shutdown hook based on the config value set to true", async () => {
const expectedResult = true;
const apiServerOptions = await configService.newExampleConfig();

// disable shutdown hook
apiServerOptions.enableShutdownHook = true;

const config = await configService.newExampleConfigConvict(
apiServerOptions,
true,
);

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

// check apiServerOptions
expect(apiServerOptions).not.toBeUndefined();
expect(apiServerOptions.enableShutdownHook).toBe(expectedResult);

// check apiServer
expect(apiServer).toBeTruthy();
const result = apiServer["enableShutdownHook"];
expect(result).toBe(expectedResult);
});
});

0 comments on commit 8b06f66

Please sign in to comment.