1 | const assert = require('assert');
|
2 | const common = require('../common.js');
|
3 |
|
4 | describe('contentType tests',function(){
|
5 |
|
6 | describe('json types',function(){
|
7 | it('should match application/json',function(){
|
8 | assert(common.doContentType(['application/json'],'json'));
|
9 | });
|
10 | it('should match application/hal+json',function(){
|
11 | assert(common.doContentType(['application/hal+json'],'json'));
|
12 | });
|
13 | it('should match application/ld+json',function(){
|
14 | assert(common.doContentType(['application/ld+json'],'json'));
|
15 | });
|
16 | it('should match application/x-www-form-urlencoded',function(){
|
17 | assert(common.doContentType(['application/json-patch+json'],'json'));
|
18 | });
|
19 | it('should match application/json; charset=utf-8',function(){
|
20 | assert(common.doContentType(['application/json; charset=utf-8'],'json'));
|
21 | });
|
22 | it('should match application/json;charset=UTF-8',function(){
|
23 | assert(common.doContentType(['application/json;charset=UTF-8'],'json'));
|
24 | });
|
25 | it('should match text/json',function(){
|
26 | assert(common.doContentType(['text/json'],'json'));
|
27 | });
|
28 | it('should not match application/yaml',function(){
|
29 | assert(!common.doContentType(['application/yaml'],'json'));
|
30 | });
|
31 | it('should not match text/plain',function(){
|
32 | assert(!common.doContentType(['text/plain'],'json'));
|
33 | });
|
34 | });
|
35 |
|
36 | describe('xml tests',function(){
|
37 | it('should match application/xml',function(){
|
38 | assert(common.doContentType(['application/xml'],'xml'));
|
39 | });
|
40 | it('should match application/xml; charset=utf-8',function(){
|
41 | assert(common.doContentType(['application/xml; charset=utf-8'],'xml'));
|
42 | });
|
43 | it('should match text/xml',function(){
|
44 | assert(common.doContentType(['text/xml'],'xml'));
|
45 | });
|
46 | it('should match image/svg+xml',function(){
|
47 | assert(common.doContentType(['image/svg+xml'],'xml'));
|
48 | });
|
49 | it('should match application/rss+xml',function(){
|
50 | assert(common.doContentType(['application/rss+xml'],'xml'));
|
51 | });
|
52 | it('should match application/rdf+xml',function(){
|
53 | assert(common.doContentType(['application/rdf+xml'],'xml'));
|
54 | });
|
55 | it('should match application/atom+xml',function(){
|
56 | assert(common.doContentType(['application/atom+xml'],'xml'));
|
57 | });
|
58 | it('should match application/mathml+xml',function(){
|
59 | assert(common.doContentType(['application/mathml+xml'],'xml'));
|
60 | });
|
61 | it('should match application/hal+xml',function(){
|
62 | assert(common.doContentType(['application/hal+xml'],'xml'));
|
63 | });
|
64 | it('should not match text/plain',function(){
|
65 | assert(!common.doContentType(['text/plain'],'xml'));
|
66 | });
|
67 | it('should not match application/json',function(){
|
68 | assert(!common.doContentType(['application/json'],'xml'));
|
69 | });
|
70 | });
|
71 |
|
72 | describe('yaml tests',function(){
|
73 | it('should match application/x-yaml',function(){
|
74 | assert(common.doContentType(['application/x-yaml'],'yaml'));
|
75 | });
|
76 | it('should match text/x-yaml',function(){
|
77 | assert(common.doContentType(['text/x-yaml'],'yaml'));
|
78 | });
|
79 | it('should not match text/plain',function(){
|
80 | assert(!common.doContentType(['text/plain'],'yaml'));
|
81 | });
|
82 | it('should not match application/xml',function(){
|
83 | assert(!common.doContentType(['application/xml'],'yaml'));
|
84 | });
|
85 | });
|
86 |
|
87 | describe('form tests',function(){
|
88 | it('should match multipart/form-data',function(){
|
89 | assert(common.doContentType(['multipart/form-data'],'form'));
|
90 | });
|
91 | it('should match application/x-www-form-urlencoded',function(){
|
92 | assert(common.doContentType(['application/x-www-form-urlencoded'],'form'));
|
93 | });
|
94 | it('should match application/octet-stream',function(){
|
95 | assert(common.doContentType(['application/octet-stream'],'form'));
|
96 | });
|
97 | it('should not match text/plain',function(){
|
98 | assert(!common.doContentType(['text/plain'],'form'));
|
99 | });
|
100 | });
|
101 |
|
102 | });
|
103 |
|
104 | describe('array tests',function(){
|
105 |
|
106 | describe('positive tests',function(){
|
107 | it('should match application/json and another type',function(){
|
108 | assert(common.doContentType(['application/json','text/plain'],'json'));
|
109 | });
|
110 | it('should match another type and application/json',function(){
|
111 | assert(common.doContentType(['text/plain','application/json'],'json'));
|
112 | });
|
113 | });
|
114 | describe('negative tests',function(){
|
115 | it('should not match two other types',function(){
|
116 | assert(!common.doContentType(['text/plain','image/jpeg'],'json'));
|
117 | });
|
118 | it('should not match an empty array',function(){
|
119 | assert(!common.doContentType([],'json'));
|
120 | });
|
121 | it('should not match an unknown format',function(){
|
122 | assert(!common.doContentType(['text/plain'],'text'));
|
123 | });
|
124 | });
|
125 | });
|
126 |
|