<commit_before>'use strict';

const users = require('elyoos-server-test-util').user;
const dbDsl = require('elyoos-server-test-util').dbDSL;
const requestHandler = require('elyoos-server-test-util').requestHandler;
const moment = require('moment');

describe('Get events of a commitment', function () {

    let startTime;

    beforeEach(async function () {
        await dbDsl.init(8);
        startTime = Math.floor(moment.utc().valueOf() / 1000);

        dbDsl.createRegion('region-1', {});
        dbDsl.createRegion('region-2', {});
        dbDsl.createRegion('region-1-1', {upperRegionLayerCode: 'region-1'});
        dbDsl.createRegion('region-1-2', {upperRegionLayerCode: 'region-1'});

        dbDsl.createCommitment('1', {
            adminId: '1', topics: ['Spiritual', 'Meditation'], language: 'de', created: 700, modified: 701,
            website: 'https://www.example.org/', regions: ['region-1-1', 'region-1-2']
        });

        dbDsl.createCommitmentEvent({commitmentId: '1', eventId: '22',
            startDate: startTime - 100, endDate: startTime + 200, region: 'region-2', topics: ['Spiritual']});

        dbDsl.createCommitmentEvent({commitmentId: '1', eventId: '23',
            startDate: startTime - 300, endDate: startTime - 200, region: 'region-2', topics: ['Environmental']});
    });

    afterEach(function () {
        return requestHandler.logout();
    });

    it('Getting upcoming events', async function () {
        await dbDsl.sendToDb();
        await requestHandler.login(users.validUser);
        let res = await requestHandler.get('/api/commitment/event', {commitmentId: '1', upComing: true, page: 0});
        res.status.should.equal(200);

        res.body.events.length.should.equals(1);
        res.body.events[0].eventId.should.equals('22');
        res.body.events[0].title.should.equals('event22Title');
        res.body.events[0].description.should.equals('event22Description');
        res.body.events[0].startDate.should.equals(startTime - 100);
        res.body.events[0].endDate.should.equals(startTime + 200);
        res.body.events[0].region.should.equals('region-2');
        res.body.events[0].location.should.equals('event22Location');
        res.body.events[0].topics.length.should.equals(1);
        res.body.events[0].topics.should.include('Spiritual');
    });

    it('Getting past events', async function () {
        await dbDsl.sendToDb();
        await requestHandler.login(users.validUser);
        let res = await requestHandler.get('/api/commitment/event', {commitmentId: '1', upComing: false, page: 0});
        res.status.should.equal(200);

        res.body.events.length.should.equals(1);
        res.body.events[0].eventId.should.equals('23');
        res.body.events[0].title.should.equals('event23Title');
        res.body.events[0].description.should.equals('event23Description');
        res.body.events[0].startDate.should.equals(startTime - 300);
        res.body.events[0].endDate.should.equals(startTime - 200);
        res.body.events[0].region.should.equals('region-2');
        res.body.events[0].location.should.equals('event23Location');
        res.body.events[0].topics.length.should.equals(1);
        res.body.events[0].topics.should.include('Environmental');
    });

    it('Get non existing commitment', async function () {
        let res = await requestHandler.get('/api/commitment', {commitmentId: '2'});
        res.status.should.equal(404);
    });

});<commit_msg>Removed topic from event.<commit_after>'use strict';

const users = require('elyoos-server-test-util').user;
const dbDsl = require('elyoos-server-test-util').dbDSL;
const requestHandler = require('elyoos-server-test-util').requestHandler;
const moment = require('moment');

describe('Get events of a commitment', function () {

    let startTime;

    beforeEach(async function () {
        await dbDsl.init(8);
        startTime = Math.floor(moment.utc().valueOf() / 1000);

        dbDsl.createRegion('region-1', {});
        dbDsl.createRegion('region-2', {});
        dbDsl.createRegion('region-1-1', {upperRegionLayerCode: 'region-1'});
        dbDsl.createRegion('region-1-2', {upperRegionLayerCode: 'region-1'});

        dbDsl.createCommitment('1', {
            adminId: '1', topics: ['Spiritual', 'Meditation'], language: 'de', created: 700, modified: 701,
            website: 'https://www.example.org/', regions: ['region-1-1', 'region-1-2']
        });

        dbDsl.createCommitmentEvent({commitmentId: '1', eventId: '22',
            startDate: startTime - 100, endDate: startTime + 200, region: 'region-2'});

        dbDsl.createCommitmentEvent({commitmentId: '1', eventId: '23',
            startDate: startTime - 300, endDate: startTime - 200, region: 'region-2'});
    });

    afterEach(function () {
        return requestHandler.logout();
    });

    it('Getting upcoming events', async function () {
        await dbDsl.sendToDb();
        await requestHandler.login(users.validUser);
        let res = await requestHandler.get('/api/commitment/event', {commitmentId: '1', upComing: true, page: 0});
        res.status.should.equal(200);

        res.body.events.length.should.equals(1);
        res.body.events[0].eventId.should.equals('22');
        res.body.events[0].title.should.equals('event22Title');
        res.body.events[0].description.should.equals('event22Description');
        res.body.events[0].startDate.should.equals(startTime - 100);
        res.body.events[0].endDate.should.equals(startTime + 200);
        res.body.events[0].region.should.equals('region-2');
        res.body.events[0].location.should.equals('event22Location');
    });

    it('Getting past events', async function () {
        await dbDsl.sendToDb();
        await requestHandler.login(users.validUser);
        let res = await requestHandler.get('/api/commitment/event', {commitmentId: '1', upComing: false, page: 0});
        res.status.should.equal(200);

        res.body.events.length.should.equals(1);
        res.body.events[0].eventId.should.equals('23');
        res.body.events[0].title.should.equals('event23Title');
        res.body.events[0].description.should.equals('event23Description');
        res.body.events[0].startDate.should.equals(startTime - 300);
        res.body.events[0].endDate.should.equals(startTime - 200);
        res.body.events[0].region.should.equals('region-2');
        res.body.events[0].location.should.equals('event23Location');
    });

    it('Get non existing commitment', async function () {
        let res = await requestHandler.get('/api/commitment', {commitmentId: '2'});
        res.status.should.equal(404);
    });

});
{'fraction_non_alphanumeric': 0.17091836734693877, 'fraction_numerical': 0.03241296518607443, 'mean_word_length': 3.2371265098537827, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '5828586', 'n_tokens_mistral': 2177, 'n_tokens_neox': 2054, 'n_words': 319}