<commit_before>'use strict';

const dbDsl = require('dumonda-me-server-test-util').dbDSL;
const db = require('dumonda-me-server-test-util').db;
const eMail = require('dumonda-me-server-lib').eMail;
const sinon = require('sinon');
const testee = requireSrc('invitations');
const fs = require('fs');
const tmp = require('tmp');

describe('Send invitations emails', function () {

    let stubSendEMail, sandbox;

    beforeEach(async function () {
        let stubFileSync;
        await dbDsl.init(6);
        sandbox = sinon.sandbox.create();
        stubSendEMail = sandbox.stub(eMail, 'sendEMail');
        stubSendEMail.resolves({});
        stubFileSync = sandbox.stub(tmp, 'fileSync');
        stubFileSync.returns({name: 'test', Body: 'test'});
        sandbox.stub(fs, 'writeFileSync');

    });

    afterEach(function () {
        sandbox.restore();
    });

    it('Send invitation', async function () {
        dbDsl.invitationSentBeforeRegistration('3',
            [{emailOfUserToInvite: '<EMAIL>', sendingEmailPending: true}]);
        await dbDsl.sendToDb();

        await testee.sendInvitations();

        stubSendEMail.calledWith("invitePerson", {
            name: `user Meier3`, userImage: sinon.match.any,
            unsubscribeLink: `${process.env.DUMONDA_ME_DOMAIN}unsubscribe/invitedUser/<EMAIL>`
        }, 'de', '<EMAIL>').should.be.true;

        let notification = await db.cypher()
            .match(`(invitedUser:InvitedUser)<-[:SENDING_EMAIL_PENDING]-(:User {userId: '3'})`)
            .return(`invitedUser`).end().send();
        notification.length.should.equals(0);
    });
});<commit_msg>Test sending multiple invitations for a user.<commit_after>'use strict';

const dbDsl = require('dumonda-me-server-test-util').dbDSL;
const db = require('dumonda-me-server-test-util').db;
const eMail = require('dumonda-me-server-lib').eMail;
const sinon = require('sinon');
const testee = requireSrc('invitations');
const fs = require('fs');
const tmp = require('tmp');

describe('Send invitations emails', function () {

    let stubSendEMail, sandbox;

    beforeEach(async function () {
        let stubFileSync;
        await dbDsl.init(6);
        sandbox = sinon.sandbox.create();
        stubSendEMail = sandbox.stub(eMail, 'sendEMail');
        stubSendEMail.resolves({});
        stubFileSync = sandbox.stub(tmp, 'fileSync');
        stubFileSync.returns({name: 'test', Body: 'test'});
        sandbox.stub(fs, 'writeFileSync');

    });

    afterEach(function () {
        sandbox.restore();
    });

    it('Sending invitation', async function () {
        dbDsl.invitationSentBeforeRegistration('3',
            [{emailOfUserToInvite: '<EMAIL>', sendingEmailPending: true}]);
        await dbDsl.sendToDb();

        await testee.sendInvitations();

        stubSendEMail.calledWith("invitePerson", {
            name: `user Meier3`, userImage: sinon.match.any,
            unsubscribeLink: `${process.env.DUMONDA_ME_DOMAIN}unsubscribe/invitedUser/<EMAIL>`
        }, 'de', '<EMAIL>').should.be.true;

        let notification = await db.cypher()
            .match(`(invitedUser:InvitedUser)<-[:SENDING_EMAIL_PENDING]-(:User {userId: '3'})`)
            .return(`invitedUser`).end().send();
        notification.length.should.equals(0);
    });

    it('Sending multiple invitations from same user', async function () {
        dbDsl.invitationSentBeforeRegistration('3',
            [{emailOfUserToInvite: '<EMAIL>', sendingEmailPending: true}]);
        dbDsl.invitationSentBeforeRegistration('3',
            [{emailOfUserToInvite: '<EMAIL>', sendingEmailPending: true}]);
        dbDsl.invitationSentBeforeRegistration('3',
            [{emailOfUserToInvite: '<EMAIL>.me', sendingEmailPending: true}]);
        await dbDsl.sendToDb();

        await testee.sendInvitations();

        stubSendEMail.calledWith("invitePerson", {
            name: `user Meier3`, userImage: sinon.match.any,
            unsubscribeLink: `${process.env.DUMONDA_ME_DOMAIN}unsubscribe/invitedUser/<EMAIL>`
        }, 'de', '<EMAIL>').should.be.true;

        stubSendEMail.calledWith("invitePerson", {
            name: `user Meier3`, userImage: sinon.match.any,
            unsubscribeLink: `${process.env.DUMONDA_ME_DOMAIN}unsubscribe/invitedUser/<EMAIL>`
        }, 'de', '<EMAIL>').should.be.true;

        stubSendEMail.calledWith("invitePerson", {
            name: `user Meier3`, userImage: sinon.match.any,
            unsubscribeLink: `${process.env.DUMONDA_ME_DOMAIN}unsubscribe/invitedUser/<EMAIL>`
        }, 'de', '<EMAIL>').should.be.true;

        let notification = await db.cypher()
            .match(`(invitedUser:InvitedUser)<-[:SENDING_EMAIL_PENDING]-(:User {userId: '3'})`)
            .return(`invitedUser`).end().send();
        notification.length.should.equals(0);
    });
});
{'fraction_non_alphanumeric': 0.15917098445595854, 'fraction_numerical': 0.0037305699481865284, 'mean_word_length': 3.225919439579685, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 18, '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': '1456414', 'n_tokens_mistral': 1536, 'n_tokens_neox': 1545, 'n_words': 242}