Blame view

node_modules/cors/test/issue-2.js 1.42 KB
f7563de62   Palak Handa   first commit
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
50
51
52
53
54
55
56
  (function () {
    /*global describe, it*/
  
    'use strict';
  
    var should = require('should'),
      express = require('express'),
      supertest = require('supertest'),
      cors = require('../lib');
  
    var app,
      corsOptions;
  
    /* -------------------------------------------------------------------------- */
  
    app = express();
    corsOptions = {
      origin: true,
      methods: ['POST'],
      credentials: true,
      maxAge: 3600
    };
    app.options('/api/login', cors(corsOptions));
    app.post('/api/login', cors(corsOptions), function (req, res) {
      res.send('LOGIN');
    });
  
    /* -------------------------------------------------------------------------- */
  
    describe('issue  #2', function () {
      it('OPTIONS works', function (done) {
        supertest(app)
          .options('/api/login')
          .expect(204)
          .set('Origin', 'http://example.com')
          .end(function (err, res) {
            should.not.exist(err);
            res.headers['access-control-allow-origin'].should.eql('http://example.com');
            done();
          });
      });
      it('POST works', function (done) {
        supertest(app)
          .post('/api/login')
          .expect(200)
          .set('Origin', 'http://example.com')
          .end(function (err, res) {
            should.not.exist(err);
            res.headers['access-control-allow-origin'].should.eql('http://example.com');
            res.text.should.eql('LOGIN');
            done();
          });
      });
    });
  
  }());