import { LogConfig } from '@basemaps/shared';
import { LambdaAlbRequest } from '@linzjs/lambda';
import o from 'ospec';
import { handleRequest } from '../index.js';
o.spec('LambdaXyz index', () => {
    function req(path, method = 'get') {
        return new LambdaAlbRequest({
            requestContext: null,
            httpMethod: method.toUpperCase(),
            path,
            body: null,
            isBase64Encoded: false,
        }, {}, LogConfig.get());
    }
    o('should export handler', async () => {
        const foo = await import('../index.js');
        o(typeof foo.handler).equals('function');
    });
    o.spec('version', () => {
        const origVersion = process.env.GIT_VERSION;
        const origHash = process.env.GIT_HASH;
        o.after(() => {
            process.env.GIT_VERSION = origVersion;
            process.env.GIT_HASH = origHash;
        });
        o('should return version', async () => {
            process.env.GIT_VERSION = '1.2.3';
            process.env.GIT_HASH = 'abc456';
            const response = await handleRequest(req('/version'));
            o(response.status).equals(200);
            o(response.statusDescription).equals('ok');
            o(response.header('cache-control')).equals('no-store');
            o(JSON.parse(response.body)).deepEquals({
                version: '1.2.3',
                hash: 'abc456',
            });
        });
    });
    o('should respond to /ping', async () => {
        const res = await handleRequest(req('/ping'));
        o(res.status).equals(200);
        o(res.statusDescription).equals('ok');
        o(res.header('cache-control')).equals('no-store');
    });
});
