-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
When trying to run all test for this code (playground link)
When running one by one it works ok.
Here is the code:
bring cloud;
bring util;
bring expect;
bring http;
struct BookRequest {
title: str;
author: str;
}
struct BookResposne extends BookRequest {
bookID: str;
createdAt: str;
}
let api = new cloud.Api();
api.post("/books", inflight (req: cloud.ApiRequest) => {
try {
let bookRequest = BookRequest.parseJson(req.body!);
let response = BookResposne {
bookID: util.uuidv4(),
title: bookRequest.title,
author: bookRequest.author,
createdAt: "2024-04-14"
};
return {
status: 200,
body: Json.stringify(response)
};
} catch e {
return {
status: 400,
body: e
};
}
});
test "POST /books should return 200 with correct body " {
let body = Json.stringify({title: "A Title", author: "An Author"});
let result = http.post("{api.url}/books", { body: body });
expect.equal(result.status, 200);
}
test "POST /books should return 400 without body " {
let result = http.post("{api.url}/books");
expect.equal(result.status, 400);
}
test "POST /books should return 400 with empty body " {
let body = Json.stringify({});
let result = http.post("{api.url}/books", { body: body });
expect.equal(result.status, 400);
}
test "POST /books should return 400 without title " {
let body = Json.stringify({ author: "An Author"});
let result = http.post("{api.url}/books", { body: body });
expect.equal(result.status, 400);
}
test "POST /books should return 400 without author " {
let body = Json.stringify({title: "A Title" });
let result = http.post("{api.url}/books", { body: body });
expect.equal(result.status, 400);
}
Metadata
Metadata
Assignees
Labels
No labels
