<commit_before>/**!
 *
 * Copyright (c) 2015-2016 Cisco Systems, Inc. See LICENSE file.
 */

import {assert} from '@ciscospark/test-helper-chai';
import sinon from '@ciscospark/test-helper-sinon';
import spark from '../../..';
import testUsers from '@ciscospark/test-helper-test-users';

describe(`ciscospark`, function() {
  this.timeout(60000);

  describe(`#teams`, () => {
    describe(`#memberships`, () => {
      let team;

      const memberships = [];

      let user1;
      before(() => {
        return testUsers.create({count: 1})
          .then((users) => {
            user1 = users[0];
          });
      });

      before(() => spark.teams.create({
        name: `Cisco Spark Team Test`
      })
        .then((t) => {
          team = t;

          return spark.rooms.create({
            title: `Cisco Spark Team Room Test`,
            teamId: team.id
          });
        }));

      afterEach(() => Promise.all(memberships.map((membership) => {
        return spark.teamMemberships.remove(membership)
          .catch((reason) => {
            console.error(`Failed to delete membership`, reason);
          });
      }))
        .then(() => {
          while (memberships.length) {
            memberships.pop();
          }
        }));

      describe(`#create()`, () => {
        it(`adds a person to a team by user id`, () => spark.teamMemberships.create({
          personId: user1.id,
          teamId: team.id
        })
          .then((membership) => {
            memberships.push(membership);
            assert.isTeamMembership(membership);
            assert.equal(membership.teamId, team.id);
          }));

        it(`adds a person to a team by user email`, () => spark.teamMemberships.create({
          personEmail: user1.email,
          teamId: team.id
        })
          .then((membership) => {
            memberships.push(membership);
            assert.isTeamMembership(membership);
            assert.equal(membership.teamId, team.id);
          }));

        it(`adds a person to a team as a moderator`, () => spark.teamMemberships.create({
          personId: user1.id,
          teamId: team.id,
          isModerator: true
        })
          .then((membership) => {
            memberships.push(membership);
            assert.isTeamMembership(membership);
            assert.equal(membership.teamId, team.id);
            assert.isTrue(membership.isModerator);
          }));
      });

      describe(`#get()`, () => {
        it(`retrieves a single team membership`, () => spark.teamMemberships.create({
          personId: user1.id,
          teamId: team.id
        })
          .then((membership) => spark.teamMemberships.get(membership)
             .then((m) => {
               memberships.push(m);
               assert.isTeamMembership(m);
              //  Skipping equality assertiong for now due to create date
              //  mismatch
              //  assert.deepEqual(m, membership);
             })));
      });

      describe(`#list()`, () => {
        let user2, user3;

        before(() => testUsers.create({count: 3})
          .then((users) => {
            [user2, user3] = users;
          }));

        before(() => Promise.all([<commit_msg>test(ciscospark): adjust test to address in-prod breaking change<commit_after>/**!
 *
 * Copyright (c) 2015-2016 Cisco Systems, Inc. See LICENSE file.
 */

import {assert} from '@ciscospark/test-helper-chai';
import sinon from '@ciscospark/test-helper-sinon';
import spark from '../../..';
import testUsers from '@ciscospark/test-helper-test-users';

describe(`ciscospark`, function() {
  this.timeout(60000);

  describe(`#teams`, () => {
    describe(`#memberships`, () => {
      let team;

      const memberships = [];

      let user1;
      before(() => {
        return testUsers.create({count: 1})
          .then((users) => {
            user1 = users[0];
          });
      });

      before(() => spark.teams.create({
        name: `Cisco Spark Team Test`
      })
        .then((t) => {
          team = t;

          return spark.rooms.create({
            title: `Cisco Spark Team Room Test`,
            teamId: team.id
          });
        }));

      afterEach(() => Promise.all(memberships.map((membership) => {
        return spark.teamMemberships.remove(membership)
          .catch((reason) => {
            console.error(`Failed to delete membership`, reason);
          });
      }))
        .then(() => {
          while (memberships.length) {
            memberships.pop();
          }
        }));

      describe(`#create()`, () => {
        it(`adds a person to a team by user id`, () => spark.teamMemberships.create({
          personId: user1.id,
          teamId: team.id
        })
          .then((membership) => {
            memberships.push(membership);
            assert.isTeamMembership(membership);
            assert.equal(membership.teamId, team.id);
          }));

        it(`adds a person to a team by user email`, () => spark.teamMemberships.create({
          personEmail: user1.email,
          teamId: team.id
        })
          .then((membership) => {
            memberships.push(membership);
            assert.isTeamMembership(membership);
            assert.equal(membership.teamId, team.id);
          }));

        it(`adds a person to a team as a moderator`, () => spark.teamMemberships.create({
          personId: user1.id,
          teamId: team.id,
          isModerator: true
        })
          .then((membership) => {
            memberships.push(membership);
            assert.isTeamMembership(membership);
            assert.equal(membership.teamId, team.id);
            assert.isTrue(membership.isModerator);

            // prevent this test from breaking other tests
            membership.isModerator = false;
            return spark.teamMemberships.update(membership);
          }));
      });

      describe(`#get()`, () => {
        it(`retrieves a single team membership`, () => spark.teamMemberships.create({
          personId: user1.id,
          teamId: team.id
        })
          .then((membership) => spark.teamMemberships.get(membership)
             .then((m) => {
               memberships.push(m);
               assert.isTeamMembership(m);
              //  Skipping equality assertiong for now due to create date
              //  mismatch
              //  assert.deepEqual(m, membership);
             })));
      });

      describe(`#list()`, () => {
        let user2, user3;

        before(() => testUsers.create({count: 3})
          .then((users) => {
            [user2, user3] = users;
          }));

        before(() => Promise.all([
{'fraction_non_alphanumeric': 0.1509433962264151, 'fraction_numerical': 0.007786762503743636, 'mean_word_length': 1.773671096345515, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 53, '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': '419230', 'n_tokens_mistral': 1949, 'n_tokens_neox': 1883, 'n_words': 375}