'use strict';

var _mocha = require('mocha');

var _chai = require('chai');

var _supertest = require('supertest');

var _supertest2 = _interopRequireDefault(_supertest);

var _integrationSpecInt = require('../_integration.spec-int.js');

var _integrationSpecInt2 = _interopRequireDefault(_integrationSpecInt);

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

(0, _mocha.describe)('BehaviorDownstreamCache', function () {

    var headerCacheControl = 'Cache-Control';
    var headerExpires = 'Expires';
    var headerPragma = 'Pragma';

    (0, _mocha.describe)('allowFromValue', function () {

        var request = (0, _supertest2.default)(_integrationSpecInt2.default.urlPrefix);

        (0, _mocha.it)('should return the expected headers', function (done) {

            request.get(_integrationSpecInt2.default.testUrl('downstreamCache.allowFromValue.papi.json')).expect(200).end(function (err, res) {
                (0, _chai.expect)(res.headers[headerCacheControl.toLowerCase()]).to.equal('max-age=7776000', headerCacheControl + ' header not set correctly');

                // eg. 1 January, 1970 00:00:01 GMT
                (0, _chai.expect)(res.headers[headerExpires.toLowerCase()]).to.match(/[0-9]+ \w+ [0-9]+ [0-9]+:[0-9]+:[0-9]+ GMT/, headerExpires + ' header not set correctly');

                done();
            });
        });
    });

    (0, _mocha.describe)('bust', function () {

        var request = (0, _supertest2.default)(_integrationSpecInt2.default.urlPrefix);

        (0, _mocha.it)('should return the expected headers', function (done) {

            request.get(_integrationSpecInt2.default.testUrl('downstreamCache.bust.papi.json')).expect(200).end(function (err, res) {
                (0, _chai.expect)(res.headers[headerCacheControl.toLowerCase()]).to.equal('max-age=0, no-cache, no-store', headerCacheControl + ' header not set correctly');

                (0, _chai.expect)(res.headers[headerExpires.toLowerCase()]).to.equal('1 January, 1970 00:00:01 GMT', headerExpires + ' header not set correctly');

                (0, _chai.expect)(res.headers[headerPragma.toLowerCase()]).to.equal('no-cache', headerPragma + ' header not set correctly');

                done();
            });
        });
    });

    (0, _mocha.describe)('must revalidate', function () {

        var request = (0, _supertest2.default)(_integrationSpecInt2.default.urlPrefix);

        (0, _mocha.it)('should return the expected headers', function (done) {

            request.get(_integrationSpecInt2.default.testUrl('downstreamCache.mustRevalidate.papi.json')).expect(200).end(function (err, res) {
                (0, _chai.expect)(res.headers[headerCacheControl.toLowerCase()]).to.equal('no-cache', headerCacheControl + ' header not set correctly');

                done();
            });
        });
    });
});