const { expect } = require('chai');

const { runActivityTaskFunction } = require('../../src/activity_task_runner/run');

describe('Activity Task Runner', () => {
    it('runs tasks with JSON input', () => {
        const originalInput = {
            foo: 'bar',
        };
        const originalResult = {
            done: true,
        };
        const task = {
            input: JSON.stringify(originalInput),
        };
        function func(input) {
            expect(input).to.deep.equal(originalInput);
            return Promise.resolve().then(() => originalResult);
        }
        return runActivityTaskFunction(task, func).then(result => {
            expect(result).to.be.a.string;
            expect(JSON.parse(result)).to.deep.equal(originalResult);
        });
    });
    it('runs tasks with no input', () => {
        const task = {};
        function func(input) {
            expect(input).to.be.undefined;
        }
        return runActivityTaskFunction(task, func);
    });
    it('runs tasks with empty string as input', () => {
        const task = {
            input: '',
        };
        function func(input) {
            expect(input).to.be.undefined;
        }
        return runActivityTaskFunction(task, func);
    });
    it('handles tasks returning undefined', () => {
        const task = {};
        const func = () => undefined;
        return runActivityTaskFunction(task, func).then(result => {
            expect(result).to.equal('');
        });
    });
    it('handles tasks returning null', () => {
        const task = {};
        const func = () => null;
        return runActivityTaskFunction(task, func).then(result => {
            expect(result).to.equal('null');
        });
    });
    it('handles tasks returning empty strings', () => {
        const task = {};
        const func = () => '';
        return runActivityTaskFunction(task, func).then(result => {
            expect(result).to.equal('""');
        });
    });
});

@@ -427,38 +427,84 @@
         
-function func(input) %7B
+let called = 0;%0A        function func(input) %7B%0A            called++;
 %0A       
@@ -687,32 +687,72 @@
 hen(result =%3E %7B%0A
+            expect(called).to.equal(1);%0A
             expe

Test that activity task runner only calls func 1x