~ubuntu-branches/ubuntu/wily/node-negotiator/wily

« back to all changes in this revision

Viewing changes to test/mediaType.js

  • Committer: Package Import Robot
  • Author(s): Jérémy Lal
  • Date: 2013-10-20 17:33:37 UTC
  • Revision ID: package-import@ubuntu.com-20131020173337-75k05okhr2qhqcy1
Tags: upstream-0.3.0
Import upstream version 0.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(function() {
 
2
  var configuration, preferredMediaTypes, testConfigurations, testCorrectType, _i, _len,
 
3
    _this = this;
 
4
 
 
5
  preferredMediaTypes = require('../lib/mediaType').preferredMediaTypes;
 
6
 
 
7
  this["Should not return a media type when no media type provided"] = function(test) {
 
8
    test.deepEqual(preferredMediaTypes('*/*', []), []);
 
9
    return test.done();
 
10
  };
 
11
 
 
12
  this["Should not return a media type when no media type is acceptable"] = function(test) {
 
13
    test.deepEqual(preferredMediaTypes('application/json', ['text/html']), []);
 
14
    return test.done();
 
15
  };
 
16
 
 
17
  this["Should not return a media type with q = 0"] = function(test) {
 
18
    test.deepEqual(preferredMediaTypes('text/html;q=0', ['text/html']), []);
 
19
    return test.done();
 
20
  };
 
21
 
 
22
  testCorrectType = function(c) {
 
23
    return _this["Should return " + c.selected + " for access header " + c.accept + " with provided types " + c.provided] = function(test) {
 
24
      test.deepEqual(preferredMediaTypes(c.accept, c.provided), c.selected);
 
25
      return test.done();
 
26
    };
 
27
  };
 
28
 
 
29
  testConfigurations = [
 
30
    {
 
31
      accept: 'text/html',
 
32
      provided: ['text/html'],
 
33
      selected: ['text/html']
 
34
    }, {
 
35
      accept: '*/*',
 
36
      provided: ['text/html'],
 
37
      selected: ['text/html']
 
38
    }, {
 
39
      accept: 'text/*',
 
40
      provided: ['text/html'],
 
41
      selected: ['text/html']
 
42
    }, {
 
43
      accept: 'application/json, text/html',
 
44
      provided: ['text/html'],
 
45
      selected: ['text/html']
 
46
    }, {
 
47
      accept: 'text/html;q=0.1',
 
48
      provided: ['text/html'],
 
49
      selected: ['text/html']
 
50
    }, {
 
51
      accept: 'application/json, text/html',
 
52
      provided: ['application/json', 'text/html'],
 
53
      selected: ['application/json', 'text/html']
 
54
    }, {
 
55
      accept: 'application/json;q=0.2, text/html',
 
56
      provided: ['application/json', 'text/html'],
 
57
      selected: ['text/html', 'application/json']
 
58
    }, {
 
59
      accept: 'application/json;q=0.2, text/html',
 
60
      provided: null,
 
61
      selected: ['text/html', 'application/json']
 
62
    }
 
63
  ];
 
64
 
 
65
  for (_i = 0, _len = testConfigurations.length; _i < _len; _i++) {
 
66
    configuration = testConfigurations[_i];
 
67
    testCorrectType(configuration);
 
68
  }
 
69
 
 
70
}).call(this);