fix(buffer): use node:buffer instead of safe-buffer (#6071)
[express.git] / test / res.attachment.js
blob1281584f3cbf1285b6422ba251458ffea8c83432
1 'use strict'
3 var Buffer = require('node:buffer').Buffer
4 var express = require('../')
5 , request = require('supertest');
7 describe('res', function(){
8 describe('.attachment()', function(){
9 it('should Content-Disposition to attachment', function(done){
10 var app = express();
12 app.use(function(req, res){
13 res.attachment().send('foo');
14 });
16 request(app)
17 .get('/')
18 .expect('Content-Disposition', 'attachment', done);
22 describe('.attachment(filename)', function(){
23 it('should add the filename param', function(done){
24 var app = express();
26 app.use(function(req, res){
27 res.attachment('/path/to/image.png');
28 res.send('foo');
29 });
31 request(app)
32 .get('/')
33 .expect('Content-Disposition', 'attachment; filename="image.png"', done);
36 it('should set the Content-Type', function(done){
37 var app = express();
39 app.use(function(req, res){
40 res.attachment('/path/to/image.png');
41 res.send(Buffer.alloc(4, '.'))
42 });
44 request(app)
45 .get('/')
46 .expect('Content-Type', 'image/png', done);
50 describe('.attachment(utf8filename)', function(){
51 it('should add the filename and filename* params', function(done){
52 var app = express();
54 app.use(function(req, res){
55 res.attachment('/locales/日本語.txt');
56 res.send('japanese');
57 });
59 request(app)
60 .get('/')
61 .expect('Content-Disposition', 'attachment; filename="???.txt"; filename*=UTF-8\'\'%E6%97%A5%E6%9C%AC%E8%AA%9E.txt')
62 .expect(200, done);
65 it('should set the Content-Type', function(done){
66 var app = express();
68 app.use(function(req, res){
69 res.attachment('/locales/日本語.txt');
70 res.send('japanese');
71 });
73 request(app)
74 .get('/')
75 .expect('Content-Type', 'text/plain; charset=utf-8', done);