/** @overview nodeunit test case. */

var testResource = require('../../../test_resource'),
    mockInjector = require('../../../mock_injector'),
    expandDataSeedFiles = require('../../../../task/worker/expand_data_seed_files.js');

exports.setUp = function (done) {
    done();
};

exports.tearDown = function (done) {
    mockInjector.restoreAll();
    done();
};

exports['Create a scope.'] = function (test) {
    var scope = expandDataSeedFiles._scope({
        foo: 'bar'
    });
    test.ok(scope);
    test.equal(scope.foo, 'bar');
    test.done();
};

exports['Load patterns.'] = function (test) {
    expandDataSeedFiles._loadPatterns({
        ja: testResource.resolveMockFile('mock_patterns/ja/*.json')
    }, function (err, data) {
        test.ifError(err);
        data.ja.forEach(function (data) {
            test.ok(data.keys);
            test.ok(data.values);
        });
        test.done();
    });
};

exports['Choice pattern.'] = function (test) {
    var patterns = [
        {keys: ['atom'], values: ['ナトリウム', 'カリウム']}
    ];
    var data = expandDataSeedFiles._choicePattern(patterns);
    test.ok(data.atom);
    test.done();
};


exports['Expand data seed files.'] = function (test) {
    var workDir = testResource.resolveWorkFile('work_expand_data_seed_files_test');
    testResource.prepareCleanWorkDir(workDir, function () {
        expandDataSeedFiles({
            srcDir: testResource.resolveMockFile('mock_seeds'),
            patternFiles: {
                ja: testResource.resolveMockFile('mock_patterns/ja/*.json')
            },
            destDir: workDir
        }, function (err) {
            test.ifError(err);
            test.done();
        });
    });
};