"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const codegen_1 = require("codegen");
const dayjs_1 = __importDefault(require("dayjs"));
const utc_1 = __importDefault(require("dayjs/plugin/utc"));
const jest_fetch_mock_1 = __importDefault(require("jest-fetch-mock"));
const measurements_1 = require("resources/measurements");
dayjs_1.default.extend(utc_1.default);
const API_CONFIG = new codegen_1.Configuration({
    accessToken: '867-5309',
    basePath: 'https://api.made.up.host:1337',
});
const FAKE_MEASUREMENT = {
    meterName: 'someMeter',
    value: 9001,
};
const FAKE_RESPONSE = {
    meter_name: 'someMeter',
    value: 9001,
};
const FAKE_ISO_STRING = '2021-09-10T16:36:59.663Z';
describe('Measurements resource', () => {
    it('makes create requests with either dates or ISO strings', async () => {
        const m = new measurements_1.Measurements(API_CONFIG);
        // Make one request with time as a string
        jest_fetch_mock_1.default.once(JSON.stringify(FAKE_RESPONSE));
        const resp1 = await m.create(Object.assign(Object.assign({}, FAKE_MEASUREMENT), { time: FAKE_ISO_STRING }));
        expect(resp1).toEqual(FAKE_MEASUREMENT);
        const firstRequest = jest_fetch_mock_1.default.mock.calls[0];
        // Make one request with time as a date object
        jest_fetch_mock_1.default.once(JSON.stringify(FAKE_RESPONSE));
        const resp2 = await m.create(Object.assign(Object.assign({}, FAKE_MEASUREMENT), { time: (0, dayjs_1.default)(FAKE_ISO_STRING).utc(true).toDate() }));
        expect(resp2).toEqual(FAKE_MEASUREMENT);
        const secondRequest = jest_fetch_mock_1.default.mock.calls[1];
        // Ensure that the outgoing requests are identical, regardless of
        // whether a date object or an ISO string was passed for `time`
        expect(firstRequest).toEqual(secondRequest);
        // Snapshot the requests so that we can tell if the generated API
        // requests ever change.
        expect(jest_fetch_mock_1.default.mock.calls).toMatchSnapshot();
    });
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVhc3VyZW1lbnRzLnRlc3Q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