"use strict";
// COMMENTED OUT BC:  Moved to cli
// import * as path from "path";
// import "mocha";
// import "chai";
// import { expect } from "chai";
// import { ProjectConfig } from "@codiac.io/codiac-relay-contracts";
// import { IBetterLogger, LogLevel } from '@codiac.io/codiac-common/IBetterLogger';
// import { BetterConsoleLogger } from "@codiac.io/codiac-common/better-logger"
// import { ICodiacClient } from "@codiac.io/codiac-api-client";
// import { LocalOps, ProjectContextRepo, DxConstants, CliEnviro, ProjectEnviro, CliGlobalConfigRepo } from "../../ops";
// import { MockUi } from "../mock-ui";
// import { TenantContextualizer } from "../tenant-contextualizer";
// import { Container } from "inversify";
// import { INTERFACES } from "@codiac.io/codiac-common";
// import { cwd } from "process";
// import { INTERFACES_OPS } from "@codiac.io/codiac-ops-common";
// import { TtyOutputStyler } from "@codiac.io/cli-tools";
// export type CliTestContext = {
//   ioc: Container,
//   logger: IBetterLogger,
//   projCfg: ProjectConfig,
//   codiacVersion: string,
//   codeRoot: string,
//   projectRoot: string,
//   cliConfigDir: string,
//   projCfgRepo: ProjectContextRepo,
//   localOps: LocalOps,
//   apiUrl: string,
//   apiClient: ICodiacClient,
//   mockUi: MockUi, 
//   outputStyler: TtyOutputStyler
// }
// function harness(): CliTestContext {
//   let ctx = <CliTestContext>{ };
//   ctx.ioc = new Container();
//   ctx.logger = new BetterConsoleLogger({ LogLevelsToShow: [LogLevel.trace, LogLevel.debug, LogLevel.error, LogLevel.warn, LogLevel.detail, LogLevel.detail] });
//   ctx.projCfg = new ProjectConfig("myTestProj", DxConstants.UNREGISTERED_TENANT_CODE, ctx.projCfg.codeVersion);
//   ctx.codiacVersion = "0.0.0";
//   ctx.codeRoot = process.cwd();
//   ctx.projectRoot = path.join(ctx.codeRoot, "src/test/my-test-proj");
//   ctx.cliConfigDir = path.join(ctx.codeRoot, "src/test/mock-cli-config");
//   ctx.projCfgRepo = new ProjectContextRepo({ projectRoot: ctx.projectRoot });
//   // ctx.cliCfgRepo = new CliGlobalConfigRepo({ cliConfigDir: ctx.cliConfigDir, version: "1.0.1" });
//   ctx.mockUi = new MockUi();
//   ctx.outputStyler = new TtyOutputStyler();
//   ctx.ioc.bind(INTERFACES.IBetterLogger).toConstantValue(ctx.logger);
//   ctx.ioc.bind(CliEnviro).toConstantValue({ cliConfigDir: cwd(), version: "1.0.1" });
//   ctx.ioc.bind(ProjectEnviro).toConstantValue({ projectRoot: ctx.projectRoot });
//   ctx.ioc.bind(ProjectContextRepo).toConstantValue(ctx.projCfgRepo);
//   ctx.ioc.bind(INTERFACES_CLI.IUserInputProvider).toConstantValue(ctx.mockUi);
//   ctx.ioc.bind(INTERFACES_CLI.IOutputStyler).toConstantValue(ctx.outputStyler);
//   ctx.localOps = new LocalOps(ctx.ioc); // , ctx.codiacVersion, ctx.projectRoot, ctx.cfgRepo, ctx.mockUi, ctx.mockUi, ctx.logger)
//   ctx.apiUrl = "http://localhost:5775/"; // "https://toybox01.codiac.io/api/"; // CodiacRestClient.DEFAULT_API_URL;
//   ctx.apiClient = CodiacRestClient.create(ctx.logger, ctx.apiUrl);
//   return ctx;
// }
// describe("When tenant context is needed on a project without a tenant assigned", () => { 
//   it("then user chooosing to create new shall register a new tenant", async () => {
//     return new Promise<void>(async (resolve,reject) => {
//       try {
//         let ctx = harness();
//         let tenCon = new TenantContextualizer(ctx.projCfg, ctx.apiClient, ctx.apiClient, ctx.projCfgRepo, ctx.mockUi, ctx.mockUi, ctx.logger);
//         ctx.mockUi.setValue("userName", "mark.freydl@codiac.io");
//         ctx.mockUi.setValue("password", "abc123");
//         ctx.mockUi.setValue("tenantCode", TenantContextualizer.CODE_FOR_NEW_TENANT);
//         ctx.mockUi.setValue("tenantName", "Test MCF Tenant Inc.")
//         let context = await tenCon.establishTenantContext();
//         console.log(JSON.stringify(context));
//         expect(ctx.mockUi.responses["tenantCode"]).to.not.equal(undefined, "the contextualizer must prompt for tenantCode");
//         expect(context.userName).to.equal("mark.freydl@codiac.io", "username must match the username in the original context");
//         expect(context.currentTenantCode).to.not.equal(undefined, "tenantCode cannot be undefined");
//         expect(context.currentTenantCode).to.not.equal("cod", "tenantCode must NOT match the original value");
//         expect(ctx.projCfg.tenantCode).to.equal(context.currentTenantCode, "The new tenant code must be written to the project config instance in memory.")
//         let fromFile = await ctx.projCfgRepo.readProjectConfig();
//         expect(fromFile.tenantCode).to.equal(context.currentTenantCode, "The new tenant code must be written to the project config file.")
//         resolve();
//         // done();
//       } catch (err) {
//         // console.log(err);
//         // resolve();
//         reject(err);
//         // done(err);
//       }
//     });
//   });
//   it("then user context with a current tenant shall prompt for selection", async () => {
//     return new Promise<void>(async (resolve,reject) => {
//       try {
//         let ctx = harness();
//         let tenCon = new TenantContextualizer(ctx.projCfg, ctx.apiClient, ctx.apiClient, ctx.projCfgRepo, ctx.mockUi, ctx.mockUi, ctx.logger);
//         ctx.mockUi.setValue("userName", "mark.freydl@codiac.io");
//         ctx.mockUi.setValue("password", "abc123");
//         ctx.mockUi.setValue("tenantCode", "cod")
//         // mockUi.setValue("tenantName", "Test MCF Tenant Inc.")
//         let context = await tenCon.establishTenantContext();
//         console.log(JSON.stringify(context));
//         expect(ctx.mockUi.responses["tenantCode"]).to.not.equal(undefined, "the contextualizer must prompt for tenantCode");
//         expect(context.userName).to.equal("mark.freydl@codiac.io", "username must match the username in the original context");
//         expect(context.currentTenantCode).to.not.equal(undefined, "tenatnCode cannot be undefined");
//         expect(context.currentTenantCode).to.equal("cod", "tenantCode must match the given value");
//         resolve();
//         // done();
//       } catch (err) {
//         // console.log(err);
//         // resolve();
//         reject(err);
//         // done(err);
//       }
//     });
//   });
//   it("Then user context shall be switched to project tenant", async () => {
//     return new Promise<void>(async (resolve,reject) => {
//       try {
//         let ctx = harness();
//         ctx.projCfg.tenantCode = "bid";
//         ctx.mockUi.setValue("userName", "mark.freydl@codiac.io");
//         // ctx.mockUi.setValue("tenantCode", "cod")
//         // mockUi.setValue("tenantName", "Test MCF Tenant Inc.")
//         ctx.mockUi.setValue("password", "abc123");
//         let tenCon = new TenantContextualizer(ctx.projCfg, ctx.apiClient, ctx.apiClient, ctx.projCfgRepo, ctx.mockUi, ctx.mockUi, ctx.logger);
//         // Make sure User has tokens for each tenant
//         let storedContext = await tenCon.authenticate("bid", "mark.freydl@codiac.io");
//         let initialUserContext = await tenCon.authenticate("cod", "mark.freydl@codiac.io");
//         if (!initialUserContext) expect.fail("Test invalid: Unable to set up an initial user context.");
//         let context = await tenCon.establishTenantContext();
//         console.log(JSON.stringify(context));
//         expect(context.currentTenantCode).to.equal(ctx.projCfg.tenantCode, "User tenantCode must match the project config");
//         expect(ctx.mockUi.responses["tenantCode"]).to.equal(undefined, "the contextualizer must NOT prompt for tenantCode");
//         expect(context.userName).to.equal(initialUserContext.userName, "username must match the username in the original context");
//         expect(context.currentTenantCode).to.not.equal(undefined, "tenantCode cannot be undefined");
//         resolve();
//         // done();
//       } catch (err) {
//         // console.log(err);
//         // resolve();
//         reject(err);
//         // done(err);
//       }
//     });
//   });
// });
//# sourceMappingURL=tenant-contextualizer.spec.js.map