Skip to content

Commit

Permalink
Add more tests (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewturner authored Sep 7, 2024
1 parent ede4d31 commit 69a81ba
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion tests/RequestDefinitionBuilder.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RequestDefinitionBuilder } from '../src/RequestDefinitionBuilder';
import { Item, ItemGroup, Collection, Url } from 'postman-collection';
import { Item, ItemGroup, Collection, Url, Header, RequestBody } from 'postman-collection';
import { readFileSync } from 'fs';

describe('Request Definition Builder', () => {
Expand All @@ -21,4 +21,52 @@ describe('Request Definition Builder', () => {

expect(actual).toBe('\n\nGET host.com/\n ?color=red');
});

test('Header is added', () => {
getRequest.request.headers.clear();
const header = new Header('option');
header.key = 'SomeHeader';
header.value = 'SomeValue';
getRequest.request.headers.add(header);

const target = new RequestDefinitionBuilder()
.from(getRequest)
.appendHeaders();

const actual = target.toString();

expect(actual).toBe('\nSomeHeader: SomeValue');
});

test('Multiple headers are added', () => {
getRequest.request.headers.clear();
const header1 = new Header('option');
header1.key = 'SomeHeader1';
header1.value = 'SomeValue1';
getRequest.request.headers.add(header1);
const header2 = new Header('option');
header2.key = 'SomeHeader2';
header2.value = 'SomeValue2';
getRequest.request.headers.add(header2);

const target = new RequestDefinitionBuilder()
.from(getRequest)
.appendHeaders();

const actual = target.toString();

expect(actual).toBe('\nSomeHeader1: SomeValue1\nSomeHeader2: SomeValue2');
});

test('Body is added with default content-type header', () => {
getRequest.request.body = new RequestBody({ mode: 'json', raw: '{ "some": "value" }' });

const target = new RequestDefinitionBuilder()
.from(getRequest)
.appendBody();

const actual = target.toString();

expect(actual).toBe('\nContent-Type: application/json\n\n{ "some": "value" }');
});
});

0 comments on commit 69a81ba

Please sign in to comment.