"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const database_config_1 = require("../../test/e2e/helpers/database-config");
const test_config_1 = require("../../test/config/test-config");
const db_migrate_shared_1 = require("db-migrate-shared");
const pg_1 = require("pg");
const migrator_1 = require("../../migrator");
const core_1 = require("./core");
db_migrate_shared_1.log.setLogLevel('error');
async function initSchema(db) {
    const client = new pg_1.Client(db);
    await client.connect();
    await client.query(`DROP SCHEMA IF EXISTS ${db.schema} CASCADE`);
    await client.query(`CREATE SCHEMA IF NOT EXISTS ${db.schema}`);
    await client.end();
}
describe('System user definitions in code and db', () => {
    let dbDefinition;
    beforeAll(async () => {
        jest.setTimeout(15000);
        const config = (0, test_config_1.createTestConfig)({
            db: {
                ...(0, database_config_1.getDbConfig)(),
                pool: { min: 1, max: 4 },
                schema: 'system_user_alignment_test',
                ssl: false,
            },
        });
        await initSchema(config.db);
        const e2e = {
            ...config.db,
            connectionTimeoutMillis: 2000,
        };
        await (0, migrator_1.migrateDb)(config);
        const client = new pg_1.Client(config.db);
        await client.connect();
        const query = await client.query(`select * from system_user_alignment_test.users where id = -1337;`);
        dbDefinition = query.rows[0];
    });
    test('usernames match', () => {
        expect(core_1.SYSTEM_USER.username).toBe(dbDefinition.username);
    });
    test('ids match', () => {
        expect(core_1.SYSTEM_USER.id).toBe(dbDefinition.id);
    });
    test('names match', () => {
        expect(core_1.SYSTEM_USER.name).toBe(dbDefinition.name);
    });
    test('emails match', () => {
        expect('email' in core_1.SYSTEM_USER).toBe(false);
        expect(dbDefinition.email).toBe(null);
    });
    test('image URLs are both falsy', () => {
        expect(Boolean(core_1.SYSTEM_USER.imageUrl)).toBe(Boolean(dbDefinition.image_url));
    });
    test('isApi is false on variable definition', () => {
        // we don't set this in the DB, so let's just test the
        // definition
        expect(core_1.SYSTEM_USER.isAPI).toBe(false);
    });
});
//# sourceMappingURL=core.test.js.map