public async provisionScope()

in lib/apiScenario/postmanCollectionRunnerClient.ts [191:266]


  public async provisionScope(scenarioDef: ScenarioDefinition, scope: Scope): Promise<void> {
    this.collection = new Collection({
      info: {
        id: this.opts.runId,
        name: this.opts.collectionName,
      },
    });
    // TODO: figure out what's this for
    this.collection.describe(
      JSON.stringify({
        apiScenarioFilePath: scenarioDef._filePath,
        // apiScenarioName: scenario.scenario,
        swaggerFilePaths: scenarioDef._swaggerFilePaths,
      })
    );

    const preScripts: string[] = [];

    if (scenarioDef.authentication) {
      this.collection.auth = this.checkAuthOption(
        scenarioDef.authentication,
        preScripts,
        scope.env
      );
    }

    if (preScripts.length > 0) {
      PostmanHelper.addEvent(this.collection.events, "prerequest", preScripts);
    }

    scope.env.resolve();

    this.runtimeEnv = new VariableScope({});
    this.runtimeEnv.set("tenantId", scope.env.get("tenantId")?.value, "string");
    this.runtimeEnv.set("client_id", scope.env.get("client_id")?.value, "string");
    this.runtimeEnv.set("client_secret", scope.env.get("client_secret")?.value, "string");
    this.runtimeEnv.set("armEndpoint", scope.env.get("armEndpoint")?.value, "string");
    this.runtimeEnv.set("subscriptionId", scope.env.get("subscriptionId")?.value, "string");
    this.runtimeEnv.set("resourceGroupName", scope.env.get("resourceGroupName")?.value, "string");
    this.runtimeEnv.set("location", scope.env.get("location")?.value, "string");

    for (const [name, variable] of scope.env.getVariables()) {
      if (!this.runtimeEnv.has(name) && !this.collection.variables.has(name)) {
        if (variable.type === "secureString" || variable.type === "secureObject") {
          this.runtimeEnv.set(name, variable.value, "secret");
          this.collection.variables.add(new Variable({ key: name, type: "secret" }));
        } else {
          this.collection.variables.add(
            new Variable({
              key: name,
              value: variable.value,
            })
          );
        }
      }
    }

    PostmanHelper.reservedCollectionVariables.forEach((variable) => {
      if (!this.collection.variables.has(variable.key)) {
        if (this.opts.skipAuth && variable.key === "x_enable_auth") {
          this.collection.variables.add(
            new Variable({
              key: variable.key,
              value: "false",
            })
          );
        } else {
          this.collection.variables.add(new Variable(variable));
        }
      }
    });

    if (this.opts.testProxy) {
      this.startTestProxyRecording();
    }
  }