"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const test_helper_1 = require("../../helpers/test-helper");
const database_init_1 = __importDefault(require("../../helpers/database-init"));
const no_logger_1 = __importDefault(require("../../../fixtures/no-logger"));
const types_1 = require("../../../../lib/types");
// import { DEFAULT_ENV } from '../../../../lib/util/constants';
let app;
let db;
const testUser = { name: 'test', id: -9999 };
beforeAll(async () => {
    db = await (0, database_init_1.default)('feature_304_api_client', no_logger_1.default);
    app = await (0, test_helper_1.setupAppWithCustomConfig)(db.stores, {
        experimental: {
            flags: {
                strictSchemaValidation: true,
                optimal304: true,
            },
        },
    });
    await app.services.featureToggleService.createFeatureToggle('default', {
        name: 'featureX',
        description: 'the #1 feature',
        impressionData: true,
    }, types_1.TEST_AUDIT_USER);
    await app.services.featureToggleService.createFeatureToggle('default', {
        name: 'featureY',
        description: 'soon to be the #1 feature',
    }, types_1.TEST_AUDIT_USER);
    await app.services.featureToggleService.createFeatureToggle('default', {
        name: 'featureZ',
        description: 'terrible feature',
    }, types_1.TEST_AUDIT_USER);
    await app.services.featureToggleService.createFeatureToggle('default', {
        name: 'featureArchivedX',
        description: 'the #1 feature',
    }, types_1.TEST_AUDIT_USER);
    await app.services.featureToggleService.archiveToggle('featureArchivedX', testUser, types_1.TEST_AUDIT_USER);
    await app.services.featureToggleService.createFeatureToggle('default', {
        name: 'featureArchivedY',
        description: 'soon to be the #1 feature',
    }, types_1.TEST_AUDIT_USER);
    await app.services.featureToggleService.archiveToggle('featureArchivedY', testUser, types_1.TEST_AUDIT_USER);
    await app.services.featureToggleService.createFeatureToggle('default', {
        name: 'featureArchivedZ',
        description: 'terrible feature',
    }, types_1.TEST_AUDIT_USER);
    await app.services.featureToggleService.archiveToggle('featureArchivedZ', testUser, types_1.TEST_AUDIT_USER);
    await app.services.featureToggleService.createFeatureToggle('default', {
        name: 'feature.with.variants',
        description: 'A feature toggle with variants',
    }, types_1.TEST_AUDIT_USER);
    await app.services.featureToggleService.saveVariants('feature.with.variants', 'default', [
        {
            name: 'control',
            weight: 50,
            weightType: 'fix',
            stickiness: 'default',
        },
        {
            name: 'new',
            weight: 50,
            weightType: 'variable',
            stickiness: 'default',
        },
    ], types_1.TEST_AUDIT_USER);
});
afterAll(async () => {
    await app.destroy();
    await db.destroy();
});
test('returns calculated hash', async () => {
    const res = await app.request
        .get('/api/client/features')
        .expect('Content-Type', /json/)
        .expect(200);
    expect(res.headers.etag).toBe('"61824cd0:16"');
    expect(res.body.meta.etag).toBe('"61824cd0:16"');
});
test('returns 304 for pre-calculated hash', async () => {
    return app.request
        .get('/api/client/features')
        .set('if-none-match', '"61824cd0:16"')
        .expect(304);
});
test('returns 200 when content updates and hash does not match anymore', async () => {
    await app.services.featureToggleService.createFeatureToggle('default', {
        name: 'featureNew304',
        description: 'the #1 feature',
    }, types_1.TEST_AUDIT_USER);
    await app.services.configurationRevisionService.updateMaxRevisionId();
    const res = await app.request
        .get('/api/client/features')
        .set('if-none-match', 'ae443048:16')
        .expect(200);
    expect(res.headers.etag).toBe('"61824cd0:17"');
    expect(res.body.meta.etag).toBe('"61824cd0:17"');
});
//# sourceMappingURL=feature.optimal304.e2e.test.js.map