<commit_before>
// Too much stuff can go wrong with CMR, so it's really helpful to log what it's
// doing
/* eslint-disable no-console */

import uuid from 'uuid';
import retry from '@ciscospark/test-helper-retry';

const cmrs = new Set();

export default class CMR {
  static reserve(spark) {
    if (!spark) {
      return Promise.reject(new Error('spark is required'));
    }

    console.log('reserving cmr');
    return spark.request({
      method: 'POST',
      uri: `${process.env.WHISTLER_API_SERVICE_URL || 'https://whistler-prod.onint.ciscospark.com/api/v1'}/reservations`,
      headers: {
        authorization: `Bearer ${spark.credentials.supertoken.access_token}`,
        'cisco-no-http-redirect': null,
        'spark-user-agent': null,
        trackingid: `ITCLIENT_${uuid.v4()}_0_imi:true`
      },
      body: {
        resourceType: 'CMR_3',
        requestMetaData: {
          emailAddress: `<EMAIL>`,
          loginType: 'loginGuest'
        },
        reservedBy: 'Spark JavaScript SDK Test Suite'
      }
    })
      .then((res) => new CMR(spark, res.body))
      .then((cmr) => {
        console.log('reserved cmr');
        return cmr;
      });
  }

  constructor(spark, attrs) {
    Object.assign(this, attrs);
    this.spark = spark;
    this.sipAddress = `${this.responseMetaData.meetingId}@${this.responseMetaData.domain}`;
  }

  release() {
    console.log('releasing cmr');
    return this.spark.request({
      method: 'DELETE',
      uri: this.reservationUrl,
      headers: {
        authorization: `Bearer ${this.spark.credentials.supertoken.access_token}`,
        'cisco-no-http-redirect': null,
        'spark-user-agent': null
      }
    })
      .then(() => console.log('released cmr'));
  }

  waitForHostToJoin() {
    return retry(() => {
      console.log('checking if the host has joined');
      return this.spark.request({
        method: 'GET',
        uri: this.resourceUrl,
        headers: {
          authorization: `Bearer ${this.spark.credentials.supertoken.access_token}`,
          'cisco-no-http-redirect': null,
          'spark-user-agent': null
        }
      })
        .then((res) => {
          if (res.body && res.body.meeting.hostPresent) {
            console.log('the host has joined');
            return;
          }

          console.log('the host has not joined');
          throw new Error('Meeting host has not yet joined');
        });
    })
      .then(() => true)
      .catch((reason) => {
        console.warn(reason);
        return false;
      });
  }
}

if (typeof after !== 'undefined') {
  after(() => Promise.all([...cmrs].map((cmr) => cmr.release()
    .catch((reason) => console.warn('failed to release CMR', reason)))));
}
<commit_msg>test(plugin-phone): adjust CMR resourceType based on URL<commit_after>
// Too much stuff can go wrong with CMR, so it's really helpful to log what it's
// doing
/* eslint-disable no-console */

import uuid from 'uuid';
import retry from '@ciscospark/test-helper-retry';

const cmrs = new Set();

export default class CMR {
  static reserve(spark) {
    if (!spark) {
      return Promise.reject(new Error('spark is required'));
    }

    let resourceType = 'CMR_3';
    // Set resource type for known integration environment.
    if (process.env.WHISTLER_API_SERVICE_URL === 'https://whistler.onint.ciscospark.com/api/v1') {
      resourceType = 'CMR_4';
    }

    console.log('reserving cmr');
    return spark.request({
      method: 'POST',
      uri: `${process.env.WHISTLER_API_SERVICE_URL || 'https://whistler-prod.onint.ciscospark.com/api/v1'}/reservations`,
      headers: {
        authorization: `Bearer ${spark.credentials.supertoken.access_token}`,
        'cisco-no-http-redirect': null,
        'spark-user-agent': null,
        trackingid: `ITCLIENT_${uuid.v4()}_0_imi:true`
      },
      body: {
        resourceType,
        requestMetaData: {
          emailAddress: `<EMAIL>`,
          loginType: 'loginGuest'
        },
        reservedBy: 'Spark JavaScript SDK Test Suite'
      }
    })
      .then((res) => new CMR(spark, res.body))
      .then((cmr) => {
        console.log('reserved cmr');
        return cmr;
      });
  }

  constructor(spark, attrs) {
    Object.assign(this, attrs);
    this.spark = spark;
    this.sipAddress = `${this.responseMetaData.meetingId}@${this.responseMetaData.domain}`;
  }

  release() {
    console.log('releasing cmr');
    return this.spark.request({
      method: 'DELETE',
      uri: this.reservationUrl,
      headers: {
        authorization: `Bearer ${this.spark.credentials.supertoken.access_token}`,
        'cisco-no-http-redirect': null,
        'spark-user-agent': null
      }
    })
      .then(() => console.log('released cmr'));
  }

  waitForHostToJoin() {
    return retry(() => {
      console.log('checking if the host has joined');
      return this.spark.request({
        method: 'GET',
        uri: this.resourceUrl,
        headers: {
          authorization: `Bearer ${this.spark.credentials.supertoken.access_token}`,
          'cisco-no-http-redirect': null,
          'spark-user-agent': null
        }
      })
        .then((res) => {
          if (res.body && res.body.meeting.hostPresent) {
            console.log('the host has joined');
            return;
          }

          console.log('the host has not joined');
          throw new Error('Meeting host has not yet joined');
        });
    })
      .then(() => true)
      .catch((reason) => {
        console.warn(reason);
        return false;
      });
  }
}

if (typeof after !== 'undefined') {
  after(() => Promise.all([...cmrs].map((cmr) => cmr.release()
    .catch((reason) => console.warn('failed to release CMR', reason)))));
}

{'fraction_non_alphanumeric': 0.15549738219895287, 'fraction_numerical': 0.0017452006980802793, 'mean_word_length': 2.3731606827545617, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3635627', 'n_tokens_mistral': 1846, 'n_tokens_neox': 1807, 'n_words': 378}