Skip to content

Commit 92800ae

Browse files
committed
add unit test for multipart error fix
1 parent 7e1e7b8 commit 92800ae

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

packages/serialization/multipart/test/common/multipartSerializationWriter.ts

+15
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@ describe("MultipartSerializationWriter", () => {
5050
.join(""),
5151
);
5252
});
53+
it("serializes multipart body with correct CRLF delimiters", () => {
54+
const multipartSerializationWriter = new MultipartSerializationWriter();
55+
const mpBody = new MultipartBody();
56+
mpBody.addOrReplacePart("testPart", "text/plain", "test content");
57+
mpBody.requestAdapter = {
58+
getSerializationWriterFactory: () => new JsonSerializationWriterFactory(),
59+
} as RequestAdapter;
60+
61+
multipartSerializationWriter.writeObjectValue(undefined, mpBody, serializeMultipartBody);
62+
const multipartContent = multipartSerializationWriter.getSerializedContent();
63+
const result = new TextDecoder().decode(multipartContent);
64+
65+
const expectedString = `--${mpBody.getBoundary()}\r\nContent-Type: text/plain\r\nContent-Disposition: form-data; name="testPart"\r\n\r\ntest content\r\n--${mpBody.getBoundary()}--\r\n`;
66+
assert.equal(result, expectedString);
67+
});
5368
it("writes a structured object", () => {
5469
const testEntity = {} as TestEntity;
5570
testEntity.id = "48d31887-5fad-4d73-a9f5-3c356e68a038";

0 commit comments

Comments
 (0)