text: const assert = require('assert');
  const nock = require('nock');
  const extend = require('extend');
  const omit = require('object.omit');
  const openwhisk = require('openwhisk');
  const { auth, describe } = require('../../resources/auth-helper');
  const { adapt, negativeHandler } = require('../../resources/test-helper');
  let classify = require('../../../packages/natural-language-classifier-v1/actions/classify');
  
  let ow;
  let credentials;
  let payload = {
    classifier_id: 'example_classifier_id',
    text: 'How is the weather today',
    headers: {
      'User-Agent': 'openwhisk'
    }
  };
  
  before(() => {
    if (process.env.TEST_OPENWHISK && auth) {
      ow = openwhisk(auth.ow);
      classify = adapt(classify, 'natural-language-classifier-v1/classify', ow);
      credentials = auth.natural_language_classifier;
    } else {
      credentials = {
        username: 'username',
        password: 'password'
      };
      beforeEach(() => {
        nock('https://gateway.watsonplatform.net/natural-language-classifier')
          .post(`/api/v1/classifiers/${payload.classifier_id}/classify`)
          .reply(200, {});
      });
    }
    payload = extend({}, payload, credentials);
  });
  
  describe('classify', () => {
    it('should fail if credentials are missing', () => {
      const params = omit(payload, ['username', 'password']);
      return classify
        .test(params)
        .then(() => {
          assert.fail('No failure on missing credentials');
        })
        .catch(err => negativeHandler(err));
    });
    it('should fail if classifier_id is missing', () => {
      const params = omit(payload, ['classifier_id']);
      return classify
        .test(params)
        .then(() => {
          assert.fail('No failure on missing classifier_id');
        })
        .catch(err => negativeHandler(err));
    });
    it('should fail if text is missing', () => {
      const params = omit(payload, ['text']);
      return classify
        .test(params)
        .then(() => {
          assert.fail('No failure on missing text');
        })
        .catch(err => negativeHandler(err));
    });
    it('should generate a valid payload', () => {
      if (!(process.env.TEST_OPENWHISK && auth)) {
        const params = payload;
        return classify
          .test(params)
          .then(() => {
            assert.ok(true);
          })
          .catch(() => {
            assert.fail('Failure on valid payload');
          });
      }
    });
    it('should succeed with __bx_creds as credential source', () => {
      if (!(process.env.TEST_OPENWHISK && auth)) {
        const params = { __bx_creds: { natural_language_classifier: payload } };
        return classify
          .test(params)
          .then(() => {
            assert.ok(true);
          })
          .catch(() => {
            assert.fail('Failure on valid payload');
          });
      }
    });
  });
  