<commit_before>import should from 'should/as-function';
import Promise from 'bluebird';
import _ from 'lodash';
import Syncano from '../../src/syncano';
import {ValidationError} from '../../src/errors';
import {suffix, credentials, createCleaner} from './utils';


describe.only('Group', function() {
  this.timeout(15000);

  const cleaner = createCleaner();
  let connection = null;
  let Model = null;
  let Instance = null;
  const instanceName = suffix.get('Group');
  const groupLabel = suffix.get('group');
  const data = {
    instanceName,
    label: groupLabel,
    description: 'test',
    id: null
  };

  before(function() {
    connection = Syncano(credentials.getCredentials());
    Instance = connection.Instance;
    Model = connection.Group;

    return Instance.please().create({name: instanceName});
  });

  after(function() {
    return Instance.please().delete({name: instanceName});
  });

  afterEach(function() {
    return cleaner.clean();
  });

  it('should be validated', function() {
    should(Model().save()).be.rejectedWith(ValidationError);
  });

  it('should require "instanceName"', function() {
    should(Model({label: groupLabel}).save()).be.rejectedWith(/instanceName/);
  });

  it('should require "label"', function() {
    should(Model({instanceName}).save()).be.rejectedWith(/label/);
  });

  it('should valideate "label"', function() {
    should(Model({instanceName, label: {}}).save()).be.rejectedWith(/label/);
  });

  it('should valideate "description"', function() {
    should(Model({instanceName, groupLabel, description: 1337}).save()).be.rejectedWith(/description/);
  });

  it('should be able to save via model instance', function() {
    return Model(data).save()
      .then(cleaner.mark)
      .then((object) => {
        should(object).be.a.Object();
        should(object).have.property('id').which.is.Number();
        should(object).have.property('label').which.is.String().equal(data.label);
        should(object).have.property('instanceName').which.is.String().equal(instanceName);
        should(object).have.property('description').which.is.String().equal(data.description);
        should(object).have.property('links').which.is.Object();
      });
  });

  it('should be able to fetch users via model instance', function() {
    return Model(data).save()
      .then(cleaner.mark)
      .then((object) => {
        return object.users();
      })
      .then((users) => {
        should(users).have.property('objects').which.is.Array()
      })
  });

  it('should be able to update via model instance', function() {
    return Model(data).save()
      .then(cleaner.mark)
      .then((object) => {
        should(object).be.a.Object();
        should(object).have.property('id').which.is.Number();
        should(object).have.property('label').which.is.String().equal(data.label);
        should(object).have.property('instanceName').which.is.String().equal(data.instanceName);
        should(object).have.property('description').which.is.String().equal(data.description);

        object.description = 'new description';
        return object.save();
      })
      .then((object) => {
        should(object).be.a.Object();
        should(object).have.property('id').which.is.Number();
        should(object).have.property('label').which.is.String().equal(data.label);
        should(object).have.property('instanceName').which.is.String().equal(data.instanceName);
        should(object).have.property('description').which.is.String().equal('new description');
      });
  });

  it('should be able to delete via model instance', function() {
    return Model(data).save()
      .then((object) => {
        should(object).be.a.Object();
        should(object).have.property('id').which.is.Number();
        should(object).have.property('label').which.is.String().equal(data.label);
        should(object).have.property('instanceName').which.is.String().equal(instanceName);
        should(object).have.property('description').which.is.String().equal(data.description);
        should(object).have.property('links').which.is.Object();

        return object.delete();
      });
  });

  describe('#please()', function() {

    it('should be able to list objects', function() {
      return Model.please().list(data).then((objects) => {
        should(objects).be.an.Array();
      });
    });

    it('should be able to create an object', function() {
      return Model.please().create(data)
        .then(cleaner.mark)
        .then((object) => {
          should(object).be.a.Object();
          should(object).have.property('id').which.is.Number();
          should(object).have.property('label').which.is.String().equal(data.label);
          should(object).have.property('instanceName').which.is.String().equal(instanceName);
          should(object).have.property('description').which.is.String().equal(data.description);
          should(object).have.property('links').which.is.Object();
        });
    });

    it('should be able list users', function() {
      return Model.please().create(data)
        .then(cleaner.mark)
        .then((group) => {
          return Model.please().users({ id: group.id, instanceName})
        })
        .then((users) => {
          should(users).have.property('objects').which.is.Array();
        });
    });

    it('should be able to bulk create an objects', function() {
      const objects = [
        Model(data),
        Model(data)
      ];

      return Model.please().bulkCreate(objects)
        .then(cleaner.mark)
        .then((result) => {
          should(result).be.an.Array().with.length(2);
        });
    });

    it('should be able to get an object', function() {<commit_msg>[LIB-603] tests<commit_after>import should from 'should/as-function';
import Promise from 'bluebird';
import _ from 'lodash';
import Syncano from '../../src/syncano';
import {ValidationError} from '../../src/errors';
import {suffix, credentials, createCleaner} from './utils';


describe.only('Group', function() {
  this.timeout(15000);

  const cleaner = createCleaner();
  let connection = null;
  let Model = null;
  let Instance = null;
  const instanceName = suffix.get('Group');
  const groupLabel = suffix.get('group');
  const data = {
    instanceName,
    label: groupLabel,
    description: 'test',
    id: null
  };

  before(function() {
    connection = Syncano(credentials.getCredentials());
    Instance = connection.Instance;
    Model = connection.Group;

    return Instance.please().create({name: instanceName});
  });

  after(function() {
    return Instance.please().delete({name: instanceName});
  });

  afterEach(function() {
    return cleaner.clean();
  });

  it('should be validated', function() {
    should(Model().save()).be.rejectedWith(ValidationError);
  });

  it('should require "instanceName"', function() {
    should(Model({label: groupLabel}).save()).be.rejectedWith(/instanceName/);
  });

  it('should require "label"', function() {
    should(Model({instanceName}).save()).be.rejectedWith(/label/);
  });

  it('should valideate "label"', function() {
    should(Model({instanceName, label: {}}).save()).be.rejectedWith(/label/);
  });

  it('should valideate "description"', function() {
    should(Model({instanceName, groupLabel, description: 1337}).save()).be.rejectedWith(/description/);
  });

  it('should be able to save via model instance', function() {
    return Model(data).save()
      .then(cleaner.mark)
      .then((object) => {
        should(object).be.a.Object();
        should(object).have.property('id').which.is.Number();
        should(object).have.property('label').which.is.String().equal(data.label);
        should(object).have.property('instanceName').which.is.String().equal(instanceName);
        should(object).have.property('description').which.is.String().equal(data.description);
        should(object).have.property('links').which.is.Object();
      });
  });

  it('should be able to list users via model instance', function() {
    return Model(data).save()
      .then(cleaner.mark)
      .then((object) => {
        return object.users();
      })
      .then((users) => {
        should(users).be.an.Array()
      })
  });

  it('should be able to update via model instance', function() {
    return Model(data).save()
      .then(cleaner.mark)
      .then((object) => {
        should(object).be.a.Object();
        should(object).have.property('id').which.is.Number();
        should(object).have.property('label').which.is.String().equal(data.label);
        should(object).have.property('instanceName').which.is.String().equal(data.instanceName);
        should(object).have.property('description').which.is.String().equal(data.description);

        object.description = 'new description';
        return object.save();
      })
      .then((object) => {
        should(object).be.a.Object();
        should(object).have.property('id').which.is.Number();
        should(object).have.property('label').which.is.String().equal(data.label);
        should(object).have.property('instanceName').which.is.String().equal(data.instanceName);
        should(object).have.property('description').which.is.String().equal('new description');
      });
  });

  it('should be able to delete via model instance', function() {
    return Model(data).save()
      .then((object) => {
        should(object).be.a.Object();
        should(object).have.property('id').which.is.Number();
        should(object).have.property('label').which.is.String().equal(data.label);
        should(object).have.property('instanceName').which.is.String().equal(instanceName);
        should(object).have.property('description').which.is.String().equal(data.description);
        should(object).have.property('links').which.is.Object();

        return object.delete();
      });
  });

  describe('#please()', function() {

    it('should be able to list objects', function() {
      return Model.please().list(data).then((objects) => {
        should(objects).be.an.Array();
      });
    });

    it('should be able to create an object', function() {
      return Model.please().create(data)
        .then(cleaner.mark)
        .then((object) => {
          should(object).be.a.Object();
          should(object).have.property('id').which.is.Number();
          should(object).have.property('label').which.is.String().equal(data.label);
          should(object).have.property('instanceName').which.is.String().equal(instanceName);
          should(object).have.property('description').which.is.String().equal(data.description);
          should(object).have.property('links').which.is.Object();
        });
    });

    it('should be able list users', function() {
      return Model.please().create(data)
        .then(cleaner.mark)
        .then((group) => {
          return Model.please().users({ id: group.id, instanceName})
        })
        .then((users) => {
          should(users).be.an.Array();
        });
    });

    it('should be able to bulk create an objects', function() {
      const objects = [
        Model(data),
        Model(data)
      ];

      return Model.please().bulkCreate(objects)
        .then(cleaner.mark)
        .then((result) => {
          should(result).be.an.Array().with.length(2);
        });
    });

    it('should be able to get an object', function() {
{'fraction_non_alphanumeric': 0.18689043142078904, 'fraction_numerical': 0.0020209120463931113, 'mean_word_length': 3.1524990879241153, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, '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': '7124255', 'n_tokens_mistral': 3320, 'n_tokens_neox': 3240, 'n_words': 527}