<commit_before>JUser                         = require './user'
JGroup                        = require './group'
JAccount                      = require './account'
JSession                      = require './session'
JInvitation                   = require './invitation'
{ async
  expect
  withDummyClient
  generateDummyClient
  withConvertedUser
  generateRandomEmail
  generateRandomString
  checkBongoConnectivity
  generateDummyUserFormData } = require '../../../testhelper'


# making sure we have mongo connection before tests
beforeTests = -> before (done) ->

  checkBongoConnectivity done


# here we have actual tests
runTests = ->

  describe 'workers.social.invitation.create', ->

    describe 'if user is not a member yet', ->

      it 'should receive the invitation', (done) ->

        email = generateRandomEmail()

        withConvertedUser { createGroup: yes }, (data) ->
          { client: adminClient, userFormData: adminUserFormData } = data

          queue = [

            (next) ->
              # creating an invitation for the unregistered user
              invitationReq = { invitations:[ { email } ] }
              JInvitation.create adminClient, invitationReq, (err) ->
                expect(err).to.not.exist
                next()

            (next) ->
              # expecting invitation to exist
              params = { email, groupName: adminClient.context.group }
              JInvitation.one params, (err, invitation) ->
                expect(err).to.not.exist
                expect(invitation).to.exist
                next()

          ]

          async.series queue, done


    describe 'if user is already member', ->

      it 'should not receive the invitation', (done) ->

        registeredEmail = null

        # registering a user and creating a group
        withConvertedUser { createGroup: yes }, (data) ->
          { group, client: adminClient, userFormData: adminUserFormData } = data

          queue = [

            (next) -><commit_msg>tests: invitation: added return invite codes test<commit_after>JUser                         = require './user'
JGroup                        = require './group'
JAccount                      = require './account'
JSession                      = require './session'
JInvitation                   = require './invitation'
{ async
  expect
  withDummyClient
  generateDummyClient
  withConvertedUser
  generateRandomEmail
  generateRandomString
  checkBongoConnectivity
  generateDummyUserFormData } = require '../../../testhelper'


# making sure we have mongo connection before tests
beforeTests = -> before (done) ->

  checkBongoConnectivity done


# here we have actual tests
runTests = ->

  describe 'workers.social.invitation.create', ->

    describe 'if user is not a member yet', ->

      it 'should receive the invitation', (done) ->

        email = generateRandomEmail()

        withConvertedUser { createGroup: yes }, (data) ->
          { client: adminClient, userFormData: adminUserFormData } = data

          queue = [

            (next) ->
              # creating an invitation for the unregistered user
              invitationReq = { invitations:[ { email } ] }
              JInvitation.create adminClient, invitationReq, (err) ->
                expect(err).to.not.exist
                next()

            (next) ->
              # expecting invitation to exist
              params = { email, groupName: adminClient.context.group }
              JInvitation.one params, (err, invitation) ->
    describe 'if user asks for the invite codes', ->

      it 'should receive the invitate codes', (done) ->

        email = generateRandomEmail()

        withConvertedUser { createGroup: yes }, (data) ->
          { client: adminClient, userFormData: adminUserFormData } = data

          # creating an invitation for the unregistered user
          invitationReq = { invitations:[ { email } ], returnCodes: yes }
          JInvitation.create adminClient, invitationReq, (err, res) ->
            expect(err).to.not.exist
            expect(res[0].email is email).to.be.true
            done()


                expect(err).to.not.exist
                expect(invitation).to.exist
                next()

          ]

          async.series queue, done


    describe 'if user is already member', ->

      it 'should not receive the invitation', (done) ->

        registeredEmail = null

        # registering a user and creating a group
        withConvertedUser { createGroup: yes }, (data) ->
          { group, client: adminClient, userFormData: adminUserFormData } = data

          queue = [

            (next) ->
{'fraction_non_alphanumeric': 0.09475719810915342, 'fraction_numerical': 0.00021486892995272884, 'mean_word_length': 1.8628536285362853, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, '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': '5008650', 'n_tokens_mistral': 1184, 'n_tokens_neox': 1115, 'n_words': 340}