var commands = require('../../../lib/commands'),
    show = commands.show,
    testResource = require('../../test_resource');

var here = process.cwd();
exports.setUp = function (done) {
    show._loadApemanfile = function () {
        return {
            basedir: testResource.resolveWorkFile('.')
        };
    };
    process.env.APEMAN_PRINT_DISABLED = true;
    process.chdir(testResource.resolveMockFile('mock_apeman_app'));
    done();
};
exports.tearDown = function (done) {
    process.env.APEMAN_PRINT_DISABLED = false;
    process.chdir(here);
    done();
};

exports['Get show message'] = function (test) {
    var data = {
        foo: {
            bar: {},
            baz: {
                quz: {
                    'quzz': 123
                }
            }
        }
    };

    test.ok(
        show._msg(data, 'foo.baz', false)
    );
    test.ok(
        show._msg(data, '', false)
    );
    test.done();
};

exports['Run Show command.'] = function (test) {
    show({}, function () {
        show({namespace: 'basedir'}, function () {
            test.done();
        });
    });
};

exports['Run Show command with keys only option.'] = function (test) {
    show({keysOnly: true}, function () {
        test.throws(function () {
            show({
                keysOnly: true,
                namespace: '__never_exists__'
            }, function () {
            });
        });
        test.done();
    });
};