var stub         = require('./fixtures/stub'),
    configfile   = require('./../configfile'), // To prevent compile errors in transaction.js.
    Transaction  = require('../transaction');

function _set_up(callback) {
    this.transaction = Transaction.createTransaction();
    callback();
}

function _tear_down(callback) {
    callback();
}

exports.transaction = {
    setUp : _set_up,
    tearDown : _tear_down,

    'add_body_filter': function (test) {
        var self = this;

        test.expect(3);

        this.transaction.add_body_filter('text/plain', function (ct, enc, buf) {
            // The actual functionality of these filter functions is tested in
            // mailbody.js.  This just makes sure the plumbing is in place.

            test.ok(ct.indexOf('text/plain') === 0, "correct body part");
            test.ok(/utf-?8/i.test(enc), "correct encoding");
            test.equal(buf.toString().trim(), "Text part", "correct body contents");
        });

        [
            "Content-Type: multipart/alternative; boundary=abcd\n",
            "\n",
            "--abcd\n",
            "Content-Type: text/plain\n",
            "\n",
            "Text part\n",
            "--abcd\n",
            "Content-Type: text/html\n",
            "\n",
            "<p>HTML part</p>\n",
            "--abcd--\n",
        ].forEach(function (line) {
            self.transaction.add_data(line);
        });
        this.transaction.end_data(function () {
            test.done();
        });
    },
};

@@ -1507,12 +1507,823 @@
 ;%0A    %7D,
+%0A%0A    'regression: attachment_hooks before set_banner/add_body_filter': function (test) %7B%0A        var self = this;%0A%0A        test.expect(2);%0A%0A        this.transaction.attachment_hooks(function () %7B%7D);%0A        this.transaction.set_banner('banner');%0A        this.transaction.add_body_filter('', function () %7B%0A            test.ok(true, %22body filter called%22);%0A        %7D);%0A        %5B%0A            %22Content-Type: text/plain%5Cn%22,%0A            %22%5Cn%22,%0A            %22Some text%5Cn%22,%0A        %5D.forEach(function (line) %7B%0A            self.transaction.add_data(line);%0A        %7D);%0A        this.transaction.end_data(function () %7B%0A            self.transaction.message_stream.get_data(function (body) %7B%0A                test.ok(/banner$/.test(body.trim()), %22banner applied%22);%0A                test.done();%0A            %7D);%0A        %7D);%0A    %7D,
 %0A%7D;%0A

Add regression test for order of Txn method calls