all files / modules/extensions/__tests__/ multipart-test.js

100% Statements 22/22
100% Branches 0/0
100% Functions 11/11
100% Lines 22/22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49                                                      
const expect = require("expect");
const mach = require("../../index");
 
const getFixture = require("../../multipart/__tests__/getFixture");
 
describe("extensions/multipart", function () {
    beforeEach(function () {
        mach.extend(require("../multipart"));
    });
 
    let message;
 
    describe("a multipart message", function () {
        beforeEach(function () {
            message = new mach.Message(
        getFixture("content_type_no_filename"),
                {"Content-Type": "multipart/form-data; boundary=AaB03x"}
      );
        });
 
        it("knows its multipart boundary", function () {
            expect(message.multipartBoundary).toEqual("AaB03x");
        });
 
        it("parses its content correctly", function () {
            return message.parseContent().then(function (params) {
                expect(params.text).toEqual("contents");
            });
        });
    });
 
    describe("a message that is part of a multipart message", function () {
        beforeEach(function () {
            message = new mach.Message(
        "contents",
                {"Content-Disposition": "form-data; name=\"files\"; filename=\"escape \\\"quotes\""}
      );
        });
 
        it("knows its name", function () {
            expect(message.name).toEqual("files");
        });
 
        it("knows its filename", function () {
            expect(message.filename).toEqual("escape \"quotes");
        });
    });
});