text: /*!
   * Copyright (c) 2015-2017 Cisco Systems, Inc. See LICENSE file.
   */
  
  import '@ciscospark/internal-plugin-wdm';
  
  import {inBrowser} from '@ciscospark/common';
  import CiscoSpark from '@ciscospark/spark-core';
  import testUsers from '@ciscospark/test-helper-test-users';
  
  describe(`plugin-wdm`, function() {
    describe(`Device`, () => {
      this.timeout(30000);
      describe(`.services`, () => {
  
        let spark;
  
        before(`create user`, () => testUsers.create({count: 1})
          .then((users) => {
            spark = new CiscoSpark({
              credentials: {
                supertoken: users[0].token
              }
            });
          }));
  
        before(`register device`, () => spark.internal.device.register());
  
        const knownServices = [
          `conversation`,
          `room`,
          `locus`,
          `avatar`,
          `metrics`,
          `encryption`,
          `atlas`,
          `files`,
          `squaredFiles`,
          `feature`,
          `swupgrade`,
          `calendar`,
          `raindrop`,
          `wdm`,
          `janus`,
          `hydra`,
          `identityLookup`,
          `argonaut`,
          `apheleia`,
          `mercuryConnection`,
          `calliopeDiscovery`,
          `hecate`,
          `board`,
          `userApps`,
          `lyra`,
          `proximity`,
          `voicemail`,
          `acl`,
          `mercuryAlternateDC`
        ];
  
        const decommissionedServices = [
          `stickies`
        ];
  
        knownServices.forEach((service) => {
          describe(`.${service}`, () => {
            it(`responds to pings`, () => ping(service));
          });
        });
  
        describe(`each service written after the test suite was created`, () => {
          it(`responds to pings`, () => Object.keys(spark.internal.device.services)
            .map((service) => service.replace(`ServiceUrl`, ``))
            .filter((service) => !knownServices.includes(service))
            .filter((service) => !knownServices.includes(service) && !decommissionedServices.includes(service))
            .reduce((p, service) => p.then(() => ping(service)), Promise.resolve()));
        });
  
        function ping(service) {
          return spark.request({
            service,
            resource: `/ping`
          })
            .catch((res) => {
              if (res && res.statusCode === 0) {
                if (!inBrowser) {
                  throw new Error(`Network failure pinging "${service}" service\nThis often happens when a service is added to the service catalog before being deployed\n${res}`);
                }
  
                throw new Error(`Network error or CORS misconfigured on "${service}" service\nThis often happens when a service is added to the service catalog before being deployed\n${res}`);
              }
  
              throw res;
            });
        }
  
      });
    });
  });
  