<commit_before>'use strict';

const Mock = require('mockjs');
const assert = require('power-assert');

const DingTalk = require('../../../lib/dingtalk');
const options = require('./../../fixtures/test.config.json');

describe('test/lib/api/user.test.js', () => {
  let dingtalk;

  before(function* () {
    dingtalk = new DingTalk(options);
  });

  function getRandomMobile() {
    return '134444' + Mock.mock('@string("number", 5)');
  }

  function* createUser(mobile) {
    const userId = mobile || getRandomMobile();
    yield dingtalk.user.create({
      userid: userId,
      name: 'user-' + userId,
      mobile: userId,
      department: [ 1 ],
    });
    return yield dingtalk.user.get(userId);
  }

  it('create', function* () {
    const mobile = getRandomMobile();
    const user = yield dingtalk.user.create({
      userid: mobile,
      name: 'user-' + mobile,
      mobile,
      department: [ 1 ],
    });
    assert(user.userid);
    console.log('%j', user);

    yield dingtalk.user.delete(mobile);
  });

  it('update', function* () {
    let user = yield createUser();
    const userId = user.userid;

    const result = yield dingtalk.user.update({
      userid: userId,
      name: 'user-test-' + userId,
    });
    assert(result.errcode === 0);
    console.log('%j', result);

    user = yield dingtalk.user.get(userId);
    assert(user.name === 'user-test-' + userId);
    console.log('%j', user);

    yield dingtalk.user.delete(userId);
  });

  it('get', function* () {
    let user = yield createUser();
    const userId = user.userid;

    user = yield dingtalk.user.get(userId);
    assert(user.userid);
    console.log('%j', user);

    yield dingtalk.user.delete(userId);
  });

  it('get undefined when not exist', function* () {
    const user = yield dingtalk.user.get('$#abc');
    console.log('%j', user);
    assert(!user);
  });

  it('list', function* () {
    const userList = yield dingtalk.user.list('1');<commit_msg>test: change userName to \'user-{userId}\' (#16)<commit_after>'use strict';

const Mock = require('mockjs');
const assert = require('power-assert');

const DingTalk = require('../../../lib/dingtalk');
const options = require('./../../fixtures/test.config.json');

describe('test/lib/api/user.test.js', () => {
  let dingtalk;

  before(function* () {
    dingtalk = new DingTalk(options);
  });

  function getRandomMobile() {
    return '134444' + Mock.mock('@string("number", 5)');
  }

  function* createUser(mobile) {
    const userId = mobile || getRandomMobile();
    yield dingtalk.user.create({
      userid: userId,
      name: 'user-' + userId,
      mobile: userId,
      department: [ 1 ],
    });
    return yield dingtalk.user.get(userId);
  }

  it('create', function* () {
    const mobile = getRandomMobile();
    const user = yield dingtalk.user.create({
      userid: mobile,
      name: 'user-' + mobile,
      mobile,
      department: [ 1 ],
    });
    assert(user.userid);
    console.log('%j', user);

    yield dingtalk.user.delete(mobile);
  });

  it('update', function* () {
    let user = yield createUser();
    const userId = user.userid;

    const result = yield dingtalk.user.update({
      userid: userId,
      name: 'user-' + userId,
    });
    assert(result.errcode === 0);
    console.log('%j', result);

    user = yield dingtalk.user.get(userId);
    assert(user.name === 'user-' + userId);
    console.log('%j', user);

    yield dingtalk.user.delete(userId);
  });

  it('get', function* () {
    let user = yield createUser();
    const userId = user.userid;

    user = yield dingtalk.user.get(userId);
    assert(user.userid);
    console.log('%j', user);

    yield dingtalk.user.delete(userId);
  });

  it('get undefined when not exist', function* () {
    const user = yield dingtalk.user.get('$#abc');
    console.log('%j', user);
    assert(!user);
  });

  it('list', function* () {
    const userList = yield dingtalk.user.list('1');
{'fraction_non_alphanumeric': 0.18391095370604604, 'fraction_numerical': 0.006071338224133569, 'mean_word_length': 2.957957957957958, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4007421', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1278, 'n_words': 278}