forked from hyperledger-cacti/cacti
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add Unit Tests for Api-Server configuration testing
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
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
packages/cactus-cmd-api-server/src/test/typescript/unit/config/api-server-config.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |