-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
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,54 @@ | ||
import { IDatabaseMap } from "@js-soft/docdb-access-abstractions"; | ||
import { BaseCommand } from "../../../src/cli/BaseCommand"; | ||
import { identityInitHandler } from "../../../src/cli/commands/identity/init"; | ||
import { ConnectorRuntimeConfig, createConnectorConfig } from "../../../src/ConnectorRuntimeConfig"; | ||
import { setupEnvironment } from "../setup"; | ||
|
||
describe("identity init", () => { | ||
let accountInfo: IDatabaseMap; | ||
let config: ConnectorRuntimeConfig; | ||
let originalArgv: any; | ||
beforeAll(() => { | ||
setupEnvironment(); | ||
config = createConnectorConfig(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
|
||
// Set process arguments back to the original value | ||
process.argv = originalArgv; | ||
}); | ||
|
||
beforeEach(async () => { | ||
const dbConnection = await BaseCommand.createDBConnection(config); | ||
const db = await dbConnection.getDatabase(`${config.database.dbNamePrefix}${config.database.dbName}`); | ||
|
||
accountInfo = await db.getMap("AccountInfo"); | ||
await accountInfo.get(""); | ||
const list = await accountInfo.list(); | ||
for (const item of list) { | ||
await accountInfo.delete(item.name); | ||
} | ||
// need to close as the data is only written to disk when the connection is closed | ||
await dbConnection.close(); | ||
|
||
// Remove all cached modules. The cache needs to be cleared before running | ||
// each command, otherwise you will see the same results from the command | ||
// run in your first test in subsequent tests. | ||
jest.resetModules(); | ||
|
||
// Each test overwrites process arguments so store the original arguments | ||
originalArgv = process.argv; | ||
}); | ||
|
||
test("identity creation", async () => { | ||
const consoleSpy = jest.spyOn(console, "log"); | ||
await identityInitHandler({ config: undefined }); | ||
expect(consoleSpy).toHaveBeenCalledWith("Identity created successfully!"); | ||
expect(consoleSpy).toHaveBeenCalledTimes(1); | ||
await identityInitHandler({ config: undefined }); | ||
expect(consoleSpy).toHaveBeenCalledWith("Identity already created!"); | ||
expect(consoleSpy).toHaveBeenCalledTimes(2); | ||
}); | ||
}); |
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,14 @@ | ||
export function setupEnvironment(): void { | ||
process.env.database = JSON.stringify({ | ||
driver: "lokijs", | ||
folder: "./", | ||
dbName: "default", | ||
dbNamePrefix: "local-" | ||
}); | ||
process.env.NODE_CONFIG_ENV = "test"; | ||
process.env.API_KEY = "test"; | ||
|
||
process.env["transportLibrary:baseUrl"] = process.env["NMSHD_TEST_BASEURL"]; | ||
process.env["transportLibrary:platformClientId"] = process.env["NMSHD_TEST_CLIENTID"]; | ||
process.env["transportLibrary:platformClientSecret"] = process.env["NMSHD_TEST_CLIENTSECRET"]; | ||
} |