'use strict';

var _assert = require('assert');

var _assert2 = _interopRequireDefault(_assert);

var _mocha = require('mocha');

var _hostname = require('../../src/criteria/hostname.js');

var _fs = require('fs');

var _fs2 = _interopRequireDefault(_fs);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

(0, _mocha.describe)('CriteriaHostname', function () {
    (0, _mocha.describe)('match exact', function () {
        (0, _mocha.it)('should return expected lua', function (done) {
            _fs2.default.readFile(__dirname + '/hostname.exact.papi.json', 'utf8', function (err, options) {
                if (err) {
                    throw err;
                }
                var opts = JSON.parse(options);

                var expected = 'ngx.var.host == swapVars("' + opts.values[0] + '") or ngx.var.host == swapVars("' + opts.values[1] + '") or ngx.var.host == swapVars("' + opts.values[2] + '")';

                var criteria = new _hostname.CriteriaHostname(opts);
                var actual = criteria.process();
                _assert2.default.equal(actual, expected);
                done();
            });
        });
    });

    (0, _mocha.describe)('match pattern', function () {
        (0, _mocha.it)('should return expected lua', function (done) {
            _fs2.default.readFile(__dirname + '/hostname.pattern.papi.json', 'utf8', function (err, options) {
                if (err) {
                    throw err;
                }
                var opts = JSON.parse(options);

                var expected = 'matches(ngx.var.host, swapVars("' + opts.values[0] + '")) or matches(ngx.var.host, swapVars("' + opts.values[1] + '")) or matches(ngx.var.host, swapVars("' + opts.values[2] + '"))';

                var criteria = new _hostname.CriteriaHostname(opts);
                var actual = criteria.process();
                _assert2.default.equal(actual, expected);
                done();
            });
        });
    });
});