Skip to content

Commit

Permalink
Rename functions
Browse files Browse the repository at this point in the history
  • Loading branch information
hansott committed Feb 28, 2024
1 parent 7bb5e0d commit caa6d9b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import * as t from "tap";
import { convertBodyToString } from "./convertBodyToString";
import { convertRequestBodyToString } from "./convertRequestBodyToString";

t.test("it converts object body to JSON string", async (t) => {
t.same(
convertBodyToString({ a: 1, b: 2, c: 3 }),
convertRequestBodyToString({ a: 1, b: 2, c: 3 }),
JSON.stringify({ a: 1, b: 2, c: 3 }, null, 2)
);
});

t.test("it converts string body to string", async (t) => {
t.same(convertBodyToString("hello"), "hello");
t.same(convertRequestBodyToString("hello"), "hello");
});

t.test("it returns undefined for non-plain object", async (t) => {
t.same(convertBodyToString(new Date()), undefined);
t.same(convertRequestBodyToString(new Date()), undefined);
});

t.test("it limits length to maxLength", async (t) => {
t.same(convertBodyToString("a".repeat(16385)), "a".repeat(16384));
t.same(convertRequestBodyToString("a".repeat(16385)), "a".repeat(16384));
});

t.test("it returns undefined for circular object", async (t) => {
const obj: Record<string, unknown> = {};
obj.a = obj;

t.same(convertBodyToString(obj), undefined);
t.same(convertRequestBodyToString(obj), undefined);
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isPlainObject } from "./isPlainObject";

export function convertBodyToString(
export function convertRequestBodyToString(
body: unknown,
maxLength = 16384
): string | undefined {
Expand All @@ -12,7 +12,7 @@ export function convertBodyToString(
try {
const serialized = JSON.stringify(body, null, 2);

return convertBodyToString(serialized, maxLength);
return convertRequestBodyToString(serialized, maxLength);
} catch {
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as t from "tap";
import { normalizeHeaders } from "./normalizeHeaders";
import { normalizeRequestHeaders } from "./normalizeRequestHeaders";

t.test("it normalizes headers", async (t) => {
t.same(
normalizeHeaders({
normalizeRequestHeaders({
string: "value",
array: ["a", "b"],
undefined: undefined,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Context } from "../agent/Context";

export function normalizeHeaders(
export function normalizeRequestHeaders(
headers: Context["headers"]
): Record<string, string | string[]> {
const normalized: Record<string, string | string[]> = {};
Expand Down

0 comments on commit caa6d9b

Please sign in to comment.