Testing HTTP Header Manipulation Operations in Insomnia
This test suite validates the functionality of Header and HeaderList objects in the Insomnia SDK. It ensures proper parsing, unparsing, and manipulation of HTTP headers through comprehensive unit tests.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
kong/insomnia
packages/insomnia-sdk/src/objects/__tests__/headers.test.ts
import { describe, expect, it } from 'vitest';
import { Header, HeaderList } from '../headers';
// import { QueryParam, setUrlParser, Url, UrlMatchPattern } from '../urls';
describe('test Header object', () => {
it('test basic operations', () => {
// const header = new Header('Content-Type: application/json\nUser-Agent: MyClientLibrary/2.0\n');
const headerStr = 'Content-Type: application/json\nUser-Agent: MyClientLibrary/2.0\n';
const headerObjs = [
{ key: 'Content-Type', value: 'application/json' },
{ key: 'User-Agent', value: 'MyClientLibrary/2.0' },
];
expect(Header.parse(headerStr)).toEqual(headerObjs);
expect(
Header.parse(Header.unparse(headerObjs))
).toEqual(headerObjs);
});
it('HeaderList operations', () => {
const headerList = new HeaderList(
undefined,
[
new Header({ key: 'h1', value: 'v1' }),
new Header({ key: 'h2', value: 'v2' }),
]
);
const upserted = new Header({ key: 'h1', value: 'v1upserted' });
headerList.upsert(upserted);
expect(headerList.one('h1')).toEqual(upserted);
});
});