Files
insomnia/packages/insomnia-data/node-src/database/init-model/response.test.ts
Bingbing b09cde814d refactor: extract insomnia-data into workspace package (#10010)
Move insomnia-data models, services, database code, and common utilities into a dedicated workspace package. Update consumers to import from the new package entrypoints and declare workspace dependencies for the extracted package.
2026-06-02 09:49:10 +00:00

56 lines
1.5 KiB
TypeScript

import fs from 'node:fs';
import { tmpdir } from 'node:os';
import path from 'node:path';
import zlib from 'node:zlib';
import type { Response } from 'insomnia-data';
import { models, services } from 'insomnia-data';
import { describe, expect, it } from 'vitest';
import { initModel } from './index';
describe('migrate()', () => {
it('does it', async () => {
const bodyPath = path.join(tmpdir(), 'foo.zip');
fs.writeFileSync(bodyPath, zlib.gzipSync('Hello World!'));
const response = await initModel<Response>(models.response.type, {
bodyPath,
});
const body = (await services.helpers.getResponseBodyBuffer(response)).toString();
expect(response.bodyCompression).toBe('zip');
expect(body).toBe('Hello World!');
});
it('migrates leaves bodyCompression for null', async () => {
expect(
(
await initModel<Response>(models.response.type, {
bodyPath: '/foo/bar',
bodyCompression: null,
})
).bodyCompression,
).toBe(null);
});
it('migrates sets bodyCompression to zip if does not have one yet', async () => {
expect(
(
await initModel<Response>(models.response.type, {
bodyPath: '/foo/bar',
})
).bodyCompression,
).toBe('zip');
});
it('migrates leaves bodyCompression if string', async () => {
expect(
(
await initModel<Response>(models.response.type, {
bodyPath: '/foo/bar',
bodyCompression: 'zip',
})
).bodyCompression,
).toBe('zip');
});
});