forked from loafle/openapi-generator-original
add in more tests
This commit is contained in:
@@ -25,25 +25,60 @@ class PetAPITests: XCTestCase {
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
func testxxx() {
|
||||
let expectation = self.expectationWithDescription("testLogin")
|
||||
PetstoreClientAPI.UserAPI.loginUser(username: "swiftTester", password: "swift").execute().then { response -> Void in
|
||||
expectation.fulfill()
|
||||
func test1CreatePet() {
|
||||
let expectation = self.expectationWithDescription("testCreatePet")
|
||||
let newPet = Pet()
|
||||
let category = PetstoreClient.Category()
|
||||
category.id = 1234
|
||||
category.name = "eyeColor"
|
||||
newPet.category = category
|
||||
newPet.id = 1000
|
||||
newPet.name = "Fluffy"
|
||||
newPet.status = .Available
|
||||
PetstoreClientAPI.PetAPI.addPet(body: newPet).execute().then { response -> Void in
|
||||
expectation.fulfill()
|
||||
}.always {
|
||||
// Noop for now
|
||||
}.error { errorType -> Void in
|
||||
// The server isn't returning JSON - and currently the alamofire implementation
|
||||
// always parses responses as JSON, so making an exception for this here
|
||||
// Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0."
|
||||
// UserInfo={NSDebugDescription=Invalid value around character 0.}
|
||||
let error = errorType as NSError
|
||||
if error.code == 3840 {
|
||||
expectation.fulfill()
|
||||
} else {
|
||||
XCTFail("error logging in")
|
||||
}
|
||||
XCTFail("error creating pet")
|
||||
}
|
||||
self.waitForExpectationsWithTimeout(testTimeout, handler: nil)
|
||||
}
|
||||
|
||||
func test2GetPet() {
|
||||
let expectation = self.expectationWithDescription("testGetPet")
|
||||
PetstoreClientAPI.PetAPI.getPetById(petId: 1000).execute().then { response -> Void in
|
||||
let pet = response.body
|
||||
XCTAssert(pet.id == 1000, "invalid id")
|
||||
XCTAssert(pet.name == "Fluffy", "invalid name")
|
||||
expectation.fulfill()
|
||||
}.always {
|
||||
// Noop for now
|
||||
}.error { errorType -> Void in
|
||||
XCTFail("error creating pet")
|
||||
}
|
||||
self.waitForExpectationsWithTimeout(testTimeout, handler: nil)
|
||||
}
|
||||
|
||||
func test3DeletePet() {
|
||||
let expectation = self.expectationWithDescription("testDeletePet")
|
||||
PetstoreClientAPI.PetAPI.deletePet(petId: 1000).execute().always { response -> Void in
|
||||
// expectation.fulfill()
|
||||
}.always {
|
||||
// Noop for now
|
||||
}.error { errorType -> Void in
|
||||
// The server gives us no data back so alamofire parsing fails - at least
|
||||
// verify that is the error we get here
|
||||
// Error Domain=com.alamofire.error Code=-6006 "JSON could not be serialized. Input data was nil or zero
|
||||
// length." UserInfo={NSLocalizedFailureReason=JSON could not be serialized. Input data was nil or zero
|
||||
// length.}
|
||||
let error = errorType as NSError
|
||||
if error.code == -6006 {
|
||||
expectation.fulfill()
|
||||
} else {
|
||||
XCTFail("error logging out")
|
||||
}
|
||||
}
|
||||
self.waitForExpectationsWithTimeout(testTimeout, handler: nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,25 +25,65 @@ class StoreAPITests: XCTestCase {
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
func testxxx() {
|
||||
let expectation = self.expectationWithDescription("testLogin")
|
||||
PetstoreClientAPI.UserAPI.loginUser(username: "swiftTester", password: "swift").execute().then { response -> Void in
|
||||
expectation.fulfill()
|
||||
func test1PlaceOrder() {
|
||||
let order = Order()
|
||||
order.id = 1000
|
||||
order.petId = 1000
|
||||
order.complete = false
|
||||
order.quantity = 10
|
||||
order.shipDate = NSDate()
|
||||
order.status = .Placed
|
||||
let expectation = self.expectationWithDescription("testPlaceOrder")
|
||||
PetstoreClientAPI.StoreAPI.placeOrder(body: order).execute().then { response -> Void in
|
||||
let order = response.body
|
||||
XCTAssert(order.id == 1000, "invalid id")
|
||||
XCTAssert(order.quantity == 10, "invalid quantity")
|
||||
XCTAssert(order.status == .Placed, "invalid status")
|
||||
expectation.fulfill()
|
||||
}.always {
|
||||
// Noop for now
|
||||
}.error { errorType -> Void in
|
||||
// The server isn't returning JSON - and currently the alamofire implementation
|
||||
// always parses responses as JSON, so making an exception for this here
|
||||
// Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0."
|
||||
// UserInfo={NSDebugDescription=Invalid value around character 0.}
|
||||
let error = errorType as NSError
|
||||
if error.code == 3840 {
|
||||
expectation.fulfill()
|
||||
} else {
|
||||
XCTFail("error logging in")
|
||||
}
|
||||
XCTFail("error placing order")
|
||||
}
|
||||
self.waitForExpectationsWithTimeout(testTimeout, handler: nil)
|
||||
}
|
||||
|
||||
func test2GetOrder() {
|
||||
let expectation = self.expectationWithDescription("testGetOrder")
|
||||
PetstoreClientAPI.StoreAPI.getOrderById(orderId: "1000").execute().then { response -> Void in
|
||||
let order = response.body
|
||||
XCTAssert(order.id == 1000, "invalid id")
|
||||
XCTAssert(order.quantity == 10, "invalid quantity")
|
||||
XCTAssert(order.status == .Placed, "invalid status")
|
||||
expectation.fulfill()
|
||||
}.always {
|
||||
// Noop for now
|
||||
}.error { errorType -> Void in
|
||||
XCTFail("error placing order")
|
||||
}
|
||||
self.waitForExpectationsWithTimeout(testTimeout, handler: nil)
|
||||
}
|
||||
|
||||
func test3DeleteOrder() {
|
||||
let expectation = self.expectationWithDescription("testDeleteOrder")
|
||||
PetstoreClientAPI.StoreAPI.deleteOrder(orderId: "1000").execute().then { response -> Void in
|
||||
expectation.fulfill()
|
||||
}.always {
|
||||
// Noop for now
|
||||
}.error { errorType -> Void in
|
||||
// The server gives us no data back so alamofire parsing fails - at least
|
||||
// verify that is the error we get here
|
||||
// Error Domain=com.alamofire.error Code=-6006 "JSON could not be serialized. Input data was nil or zero
|
||||
// length." UserInfo={NSLocalizedFailureReason=JSON could not be serialized. Input data was nil or zero
|
||||
// length.}
|
||||
let error = errorType as NSError
|
||||
if error.code == -6006 {
|
||||
expectation.fulfill()
|
||||
} else {
|
||||
XCTFail("error deleting order")
|
||||
}
|
||||
}
|
||||
self.waitForExpectationsWithTimeout(testTimeout, handler: nil)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ class UserAPITests: XCTestCase {
|
||||
self.waitForExpectationsWithTimeout(testTimeout, handler: nil)
|
||||
}
|
||||
|
||||
func testCreateUser() {
|
||||
func test1CreateUser() {
|
||||
let expectation = self.expectationWithDescription("testCreateUser")
|
||||
let newUser = User()
|
||||
newUser.email = "test@test.com"
|
||||
@@ -99,22 +99,17 @@ class UserAPITests: XCTestCase {
|
||||
self.waitForExpectationsWithTimeout(testTimeout, handler: nil)
|
||||
}
|
||||
|
||||
func testGetUser() {
|
||||
func test2GetUser() {
|
||||
let expectation = self.expectationWithDescription("testGetUser")
|
||||
PetstoreClientAPI.UserAPI.getUserByName(username: "test@test.com").execute().then { response -> Void in
|
||||
let user = response.body
|
||||
if (user.userStatus == 0 &&
|
||||
user.email == "test@test.com" &&
|
||||
user.firstName == "Test" &&
|
||||
user.lastName == "Tester" &&
|
||||
user.id == 1000 &&
|
||||
user.password == "test!" &&
|
||||
user.phone == "867-5309") {
|
||||
|
||||
expectation.fulfill()
|
||||
} else {
|
||||
XCTFail("invalid user object")
|
||||
}
|
||||
XCTAssert(user.userStatus == 0, "invalid userStatus")
|
||||
XCTAssert(user.email == "test@test.com", "invalid email")
|
||||
XCTAssert(user.firstName == "Test", "invalid firstName")
|
||||
XCTAssert(user.lastName == "Tester", "invalid lastName")
|
||||
XCTAssert(user.password == "test!", "invalid password")
|
||||
XCTAssert(user.phone == "867-5309", "invalid phone")
|
||||
expectation.fulfill()
|
||||
}.always {
|
||||
// Noop for now
|
||||
}.error { errorType -> Void in
|
||||
@@ -122,5 +117,27 @@ class UserAPITests: XCTestCase {
|
||||
}
|
||||
self.waitForExpectationsWithTimeout(testTimeout, handler: nil)
|
||||
}
|
||||
|
||||
func test3DeleteUser() {
|
||||
let expectation = self.expectationWithDescription("testDeleteUser")
|
||||
PetstoreClientAPI.UserAPI.deleteUser(username: "test@test.com").execute().then { response -> Void in
|
||||
expectation.fulfill()
|
||||
}.always {
|
||||
// Noop for now
|
||||
}.error { errorType -> Void in
|
||||
// The server gives us no data back so alamofire parsing fails - at least
|
||||
// verify that is the error we get here
|
||||
// Error Domain=com.alamofire.error Code=-6006 "JSON could not be serialized. Input data was nil or zero
|
||||
// length." UserInfo={NSLocalizedFailureReason=JSON could not be serialized. Input data was nil or zero
|
||||
// length.}
|
||||
let error = errorType as NSError
|
||||
if error.code == -6006 {
|
||||
expectation.fulfill()
|
||||
} else {
|
||||
XCTFail("error logging out")
|
||||
}
|
||||
}
|
||||
self.waitForExpectationsWithTimeout(testTimeout, handler: nil)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user