<commit_before>const assert = require('assert');
const hook = require('../../src/custom/rfx-create-room-on-activate');
const sinon = require('sinon');
const Promise = require('bluebird');

describe('Hook `rfx-create-room-on-activate`', function suite() {
  before(function start() {
    return global.startService.call(this, {
      hooks: { 'users:activate': hook },
    });
  });
  after(global.clearRedis);

  it('should be able to create room after register', function test() {
    const amqpStub = sinon.stub(this.users.amqp, 'publishAndWait');
    const room = {
      id: 'ee39afd6-b99a-47d0-a43b-a942cfd5451f',
      name: 'Bar Station | Foo Scool',
      createdBy: '<EMAIL>',
    };

    amqpStub.withArgs('chat.internal.rooms.create')
      .returns(Promise.resolve(room));

    return this.dispatch('users.invite', {
        email: '<EMAIL>',
        ctx: {
          firstName: 'Foo',
          lastName: 'Bar',
        },
        metadata: {
          '*.localhost': {
            scool: 'Foo Scool',
            station: 'Bar Station',
          },
        },
      })
      .reflect()
      .then(inspectPromise())
      .then(result => {
        assert.ok(result.context.token.secret);

        return this.dispatch('users.register', {
          username: '<EMAIL>',
          password: '<PASSWORD>',
          inviteToken: result.context.token.secret,
          audience: '*.localhost',
        });
      })
      .reflect()
      .then(inspectPromise())
      .then(result => {
        const stubArgs = amqpStub.args[0];
        assert.equal(stubArgs[0], 'chat.internal.rooms.create');
        assert.deepEqual(stubArgs[1], { name: room.name, createdBy: room.createdBy });

        assert.equal(result.user.username, '<EMAIL>');
        assert.equal(
          result.user.metadata['*.localhost'].roomId,
          'ee39afd6-b99a-47d0-a43b-a942cfd5451f'
        );

        amqpStub.restore();
      });
  });
});
<commit_msg>tests: fix rfx hook<commit_after>/* global inspectPromise */

const _ = require('lodash');
const assert = require('assert');
const hook = require('../../src/custom/rfx-create-room-on-activate');
const sinon = require('sinon');
const Promise = require('bluebird');

describe('Hook `rfx-create-room-on-activate`', function suite() {
  before(_.partial(global.startService, { hooks: { 'users:activate': hook } }));
  after(global.clearRedis);

  it('should be able to create room after register', function test() {
    const amqpStub = sinon.stub(this.users.amqp, 'publishAndWait');
    const room = {
      id: 'ee39afd6-b99a-47d0-a43b-a942cfd5451f',
      name: 'Bar Station | Foo Scool',
      createdBy: '<EMAIL>',
    };

    amqpStub.withArgs('chat.internal.rooms.create')
      .returns(Promise.resolve(room));

    return this.dispatch('users.invite', {
      email: '<EMAIL>',
      ctx: {
        firstName: 'Foo',
        lastName: 'Bar',
      },
      metadata: {
        '*.localhost': {
          stationSchool: 'Foo Scool',
          stationName: 'Bar Station',
        },
      },
    })
    .reflect()
    .then(inspectPromise())
    .then(result => {
      assert.ok(result.context.token.secret);

      return this.dispatch('users.register', {
        username: '<EMAIL>',
        password: '<PASSWORD>',
        inviteToken: result.context.token.secret,
        audience: '*.localhost',
      });
    })
    .reflect()
    .then(inspectPromise())
    .then(result => {
      const stubArgs = amqpStub.args[0];
      assert.equal(stubArgs[0], 'chat.internal.rooms.create');
      assert.deepEqual(stubArgs[1], { name: room.name, createdBy: room.createdBy });

      assert.equal(result.user.username, '<EMAIL>');
      assert.equal(
        result.user.metadata['*.localhost'].roomId,
        'ee39afd6-b99a-47d0-a43b-a942cfd5451f'
      );

      amqpStub.restore();

      return null;
    });
  });
});

{'fraction_non_alphanumeric': 0.16907962771458118, 'fraction_numerical': 0.019131334022750777, 'mean_word_length': 2.514078110808356, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '6263923', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1246, 'n_words': 209}