Name: js-handler/node_modules/restify/node_modules/negotiator/test/mediaType.js
| 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: | ]; |
| 60: | |
| 61: | for (_i = 0, _len = testConfigurations.length; _i < _len; _i++) { |
| 62: | configuration = testConfigurations[_i]; |
| 63: | testCorrectType(configuration); |
| 64: | } |
| 65: | |
| 66: | }).call(this); |
