forked from swagger-api/swagger-js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathswagger-operation-spec.js
224 lines (222 loc) · 8.94 KB
/
swagger-operation-spec.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
// Generated by CoffeeScript 1.6.3
(function() {
window.api_key = 'special-key';
describe('Operations for version 1.2 spec', function() {
beforeEach(function() {
var success;
success = function() {
return console.log("success");
};
window.authorizations.add("key", new ApiKeyAuthorization("api_key", "special-key", "header"));
window.swagger = new SwaggerApi({
url: 'http://petstore.swagger.wordnik.com/api/api-docs',
success: success
});
return waitsFor(function() {
return swagger.ready != null;
});
});
describe("verifies the nickname is sanitized", function() {
it("returns the same nickname", function() {
var pet;
pet = window.swagger.apis.pet;
return expect(pet.sanitize("getSomething")).toBe("getSomething");
});
it("strips spaces in the nickname", function() {
var pet;
pet = window.swagger.apis.pet;
return expect(pet.sanitize("get something")).toBe("get_something");
});
it("strips dots in the nickname", function() {
var pet;
pet = window.swagger.apis.pet;
return expect(pet.sanitize("get.something")).toBe("get_something");
});
it("strips $ in the nickname", function() {
var pet;
pet = window.swagger.apis.pet;
return expect(pet.sanitize("get$something")).toBe("get_something");
});
it("strips punctuation in the nickname", function() {
var pet;
pet = window.swagger.apis.pet;
return expect(pet.sanitize("get[something]")).toBe("get_something");
});
it("strips curlies in the nickname", function() {
var pet;
pet = window.swagger.apis.pet;
return expect(pet.sanitize("get{something}")).toBe("get_something");
});
return it("strips punctuation in the nickname", function() {
var pet;
pet = window.swagger.apis.pet;
return expect(pet.sanitize(" \\]}{Get$$_./\[something]")).toBe("Get_something");
});
});
return describe("verifies the get pet operation", function() {
beforeEach(function() {
window.body = null;
window.response = null;
window.callback = null;
window.error = null;
window.success_callback = function(data) {
return window.response = data;
};
return window.error_callback = function(data) {
return window.error = data;
};
});
it("verifies the response messages from the get operation", function() {
var operation, responseMessages;
operation = swagger.pet.operations.getPetById;
console.log(operation);
responseMessages = operation.responseMessages;
expect(responseMessages).toBeDefined;
expect(responseMessages.length).toBe(2);
expect(responseMessages[0].code).toBe(400);
return expect(responseMessages[1].code).toBe(404);
});
it("gets help() from the get pet operation", function() {
var operation;
operation = swagger.pet.operations.getPetById;
return expect(operation.help()).toBe("* petId (required) - ID of pet that needs to be fetched");
});
it("verifies the get pet operation", function() {
var operation, param, parameters;
operation = swagger.pet.operations.getPetById;
expect(operation.method).toBe("get");
parameters = operation.parameters;
expect(parameters).toBeDefined;
expect(parameters.length).toBe(1);
param = parameters[0];
expect(param.name).toBe("petId");
expect(param.type).toBe("integer");
expect(param.paramType).toBe("path");
return expect(param.description).toBeDefined;
});
it("verifies the post pet operation", function() {
var operation, param, parameters;
operation = swagger.pet.operations.addPet;
expect(operation.method).toBe("post");
parameters = operation.parameters;
expect(parameters).toBeDefined;
expect(parameters.length).toBe(1);
param = parameters[0];
expect(param.name).toBe("body");
expect(param.type).toBe("Pet");
expect(param.paramType).toBe("body");
return expect(param.description).toBeDefined;
});
it("verifies the put pet operation", function() {
var operation, param, parameters;
operation = swagger.pet.operations.updatePet;
expect(operation.method).toBe("put");
parameters = operation.parameters;
expect(parameters).toBeDefined;
expect(parameters.length).toBe(1);
param = parameters[0];
expect(param.name).toBe("body");
expect(param.type).toBe("Pet");
expect(param.paramType).toBe("body");
return expect(param.description).toBeDefined;
});
it("verifies the findByTags operation", function() {
var operation, param, parameters;
operation = swagger.pet.operations.findPetsByTags;
expect(operation.method).toBe("get");
parameters = operation.parameters;
expect(parameters).toBeDefined;
expect(parameters.length).toBe(1);
param = parameters[0];
console.log(param);
expect(param.name).toBe("tags");
expect(param.type).toBe("string");
expect(param.paramType).toBe("query");
return expect(param.description).toBeDefined;
});
it("verifies the patch pet operation", function() {
var operation, param, parameters, produces;
operation = swagger.pet.operations.partialUpdate;
expect(operation.method).toBe("patch");
produces = operation.produces;
expect(produces.length).toBe(2);
expect(produces[0]).toBe("application/json");
expect(produces[1]).toBe("application/xml");
parameters = operation.parameters;
expect(parameters).toBeDefined;
expect(parameters.length).toBe(2);
param = parameters[0];
expect(param.name).toBe("petId");
expect(param.type).toBe("string");
expect(param.paramType).toBe("path");
expect(param.description).toBeDefined;
param = parameters[1];
expect(param.name).toBe("body");
expect(param.type).toBe("Pet");
expect(param.paramType).toBe("body");
return expect(param.description).toBeDefined;
});
it("verifies the post pet operation with form", function() {
var consumes, operation, param, parameters;
operation = swagger.pet.operations.updatePetWithForm;
expect(operation.method).toBe("post");
consumes = operation.consumes;
expect(consumes.length).toBe(1);
expect(consumes[0]).toBe("application/x-www-form-urlencoded");
parameters = operation.parameters;
expect(parameters).toBeDefined;
expect(parameters.length).toBe(3);
param = parameters[0];
expect(param.name).toBe("petId");
expect(param.type).toBe("string");
expect(param.paramType).toBe("path");
expect(param.description).toBeDefined;
param = parameters[1];
expect(param.name).toBe("name");
expect(param.type).toBe("string");
expect(param.paramType).toBe("form");
expect(param.description).toBeDefined;
expect(param.required).toBe(false);
param = parameters[2];
expect(param.name).toBe("status");
expect(param.type).toBe("string");
expect(param.paramType).toBe("form");
expect(param.description).toBeDefined;
return expect(param.required).toBe(false);
});
it("verifies a file upload", function() {
var consumes, operation, param, parameters;
operation = swagger.pet.operations.uploadFile;
expect(operation.method).toBe("post");
consumes = operation.consumes;
expect(consumes.length).toBe(1);
expect(consumes[0]).toBe("multipart/form-data");
parameters = operation.parameters;
expect(parameters).toBeDefined;
expect(parameters.length).toBe(2);
param = parameters[0];
expect(param.name).toBe("additionalMetadata");
expect(param.type).toBe("string");
expect(param.paramType).toBe("form");
expect(param.required).toBe(false);
expect(param.description).toBeDefined;
param = parameters[1];
expect(param.name).toBe("file");
expect(param.type).toBe("File");
expect(param.paramType).toBe("body");
expect(param.description).toBeDefined;
return expect(param.required).toBe(false);
});
it("gets operations for the pet api", function() {
var ops;
ops = swagger.pet.operations;
return expect(ops).toBeDefined;
});
return it("gets help() from the file upload operation", function() {
var operation;
operation = swagger.pet.operations.uploadFile;
return expect(operation.help().trim()).toBe("* additionalMetadata - Additional data to pass to server\n* file - file to upload");
});
});
});
}).call(this);