Skip to content

Commit

Permalink
fix: headers assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
izatop committed Nov 12, 2020
1 parent 11f8c45 commit 7bb1570
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 2 additions & 3 deletions packages/app/src/Transport/HeadersAbstract.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {assert, compare, curry, ILogable, isBoolean, isFunction} from "@typesafeunit/util";
import {assert, ILogable, isBoolean, isFunction} from "@typesafeunit/util";
import {HeaderAssertValue, IHeaders} from "../interfaces";
import {KeyValueReadonlyMap} from "./KeyValueReadonlyMap";

Expand All @@ -10,10 +10,9 @@ export abstract class HeadersAbstract extends KeyValueReadonlyMap

public assert(header: string, expected: HeaderAssertValue): void {
const clientValue = this.get(header.toLowerCase());
const cmp = curry(compare, clientValue);
if (Array.isArray(expected)) {
assert(
expected.some(cmp),
expected.some((e) => clientValue.includes(e)),
`Wrong header "${header}" value, allowed: ${expected.join(", ")}`,
);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/app/test/src/Request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ describe("Request", () => {
test("JSONTransform", async () => {
const request = new Request(
"/u/123",
{"Content-Type": "application/json"},
{"Content-Type": "application/json;"},
JSON.stringify({field1: "Value1", num: 123}),
);

expect(() => request.headers.assert("content-type", "application/json")).not.toThrow();
expect(await JSONTransform(request))
.toMatchSnapshot();
});
Expand Down

0 comments on commit 7bb1570

Please sign in to comment.