tests: add maxAge option tests for res.sendFile
[express.git] / test / res.attachment.js
blob4c3d4aa2f1bec13ec2534f63cbbbf25aa16ab943
2 var Buffer = require('safe-buffer').Buffer
3 var express = require('../')
4   , request = require('supertest');
6 describe('res', function(){
7   describe('.attachment()', function(){
8     it('should Content-Disposition to attachment', function(done){
9       var app = express();
11       app.use(function(req, res){
12         res.attachment().send('foo');
13       });
15       request(app)
16       .get('/')
17       .expect('Content-Disposition', 'attachment', done);
18     })
19   })
21   describe('.attachment(filename)', function(){
22     it('should add the filename param', function(done){
23       var app = express();
25       app.use(function(req, res){
26         res.attachment('/path/to/image.png');
27         res.send('foo');
28       });
30       request(app)
31       .get('/')
32       .expect('Content-Disposition', 'attachment; filename="image.png"', done);
33     })
35     it('should set the Content-Type', function(done){
36       var app = express();
38       app.use(function(req, res){
39         res.attachment('/path/to/image.png');
40         res.send(Buffer.alloc(4, '.'))
41       });
43       request(app)
44       .get('/')
45       .expect('Content-Type', 'image/png', done);
46     })
47   })
49   describe('.attachment(utf8filename)', function(){
50     it('should add the filename and filename* params', function(done){
51       var app = express();
53       app.use(function(req, res){
54         res.attachment('/locales/日本語.txt');
55         res.send('japanese');
56       });
58       request(app)
59       .get('/')
60       .expect('Content-Disposition', 'attachment; filename="???.txt"; filename*=UTF-8\'\'%E6%97%A5%E6%9C%AC%E8%AA%9E.txt')
61       .expect(200, done);
62     })
64     it('should set the Content-Type', function(done){
65       var app = express();
67       app.use(function(req, res){
68         res.attachment('/locales/日本語.txt');
69         res.send('japanese');
70       });
72       request(app)
73       .get('/')
74       .expect('Content-Type', 'text/plain; charset=utf-8', done);
75     })
76   })