'use strict';
const assert = require('assert');
const context = require('../helpers/context');
describe('ctx.append(name, val)', () => {
it('should append multiple headers', () => {
const ctx = context();
ctx.append('x-foo', 'bar1');
ctx.append('x-foo', 'bar2');
assert.deepEqual(ctx.response.header['x-foo'], ['bar1', 'bar2']);
});
it('should accept array of values', () => {
const ctx = context();
ctx.append('Set-Cookie', ['foo=bar', 'fizz=buzz']);
ctx.append('Set-Cookie', 'hi=again');
assert.deepEqual(ctx.response.header['set-cookie'], ['foo=bar', 'fizz=buzz', 'hi=again']);
});
it('should get reset by res.set(field, val)', () => {
const ctx = context();
ctx.append('Link', '');
ctx.append('Link', '');
ctx.set('Link', '');
assert.equal(ctx.response.header.link, '');
});
it('should work with res.set(field, val) first', () => {
const ctx = context();
ctx.set('Link', '');
ctx.append('Link', '');
assert.deepEqual(ctx.response.header.link, ['', '']);
});
});