-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathformdata.ts
33 lines (32 loc) · 1.19 KB
/
formdata.ts
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
import { app, ValidationError } from "../api";
app.category("optional", () => {
app.put("/formdata/stream/uploadfile", "StreamUploadFile", (request) => {
if (!(request.body instanceof Buffer)) {
throw new ValidationError(`Expected binary body but got ${typeof request.body}`, undefined, request.body);
}
return {
status: 200,
body: {
contentType: "application/text",
rawContent: request.body.toString(),
},
};
});
app.post("/formsdataurlencoded/pet/add/:petId", "UpdatePetWithForm", (request) => {
const petId = request.params.petId;
if (petId !== "1") {
throw new ValidationError(`Expected petID 1 but got ${petId}`, undefined, request.params);
}
request.expect.containsHeader("content-type", "application/x-www-form-urlencoded");
request.expect.bodyEquals({ pet_type: "dog", pet_food: "meat", name: "Fido", pet_age: "42" });
return {
status: 200,
};
});
app.post("/formsdataurlencoded/partialConstantBody", "UrlEncodedDataWithPartialConstantBody", (request) => {
request.expect.bodyEquals({ grant_type: "access_token", access_token: "foo", service: "bar" });
return {
status: 200,
};
});
});