vapor/api-template

Tests fails using MySQL Provider

Closed this issue · 4 comments

In this function:

    func testPostRoutes() throws {
        let idOne = try create() ?? -1
        try fetchOne(id: idOne)
        try fetchAll(expectCount: 1)
        try patch(id: idOne)
        try put(id: idOne) // HERE

        let idTwo = try create() ?? -1
        try fetchAll(expectCount: 2)

        try deleteOne(id: idOne)
        try fetchAll(expectCount: 1)

        try deleteOne(id: idTwo)
        try fetchAll(expectCount: 0)

        let newIds = try (1...5).map { _ in try create() ?? 1 }
        try fetchAll(expectCount: newIds.count)
        try deleteAll()
        try fetchAll(expectCount: 0)
    }

When try put(id: idOne) is called, delete the initial post and create a new post, so the original idOne not exists anymore and fails here try deleteOne(id: idOne)

Fails using mysql, i don't know why pass using memory driver

@tanner0101 still happening

Could you clarify what the following sentence means:

When try put(id: idOne) is called, delete the initial post and create a new post, so the original idOne not exists anymore and fails here try deleteOne(id: idOne)

Read the comments please :D

func testPostRoutes() throws {
    let idOne = try create() ?? -1    // Post with id 1 is created.... So idOne is equal to 1
    try fetchOne(id: idOne)
    try fetchAll(expectCount: 1)
    try patch(id: idOne)
    try put(id: idOne)    // Put remove the original post, so Post 1 is deleted and create a post with id 2

    let idTwo = try create() ?? -1    // create a new post, in this case idTwo = 3
    try fetchAll(expectCount: 2)

    try deleteOne(id: idOne)    // Try to remove the post with id = 1 but this id not exist anymore because it was deleted in the put sentence.
    try fetchAll(expectCount: 1)

    try deleteOne(id: idTwo)
    try fetchAll(expectCount: 0)

    let newIds = try (1...5).map { _ in try create() ?? 1 }
    try fetchAll(expectCount: newIds.count)
    try deleteAll()
    try fetchAll(expectCount: 0)
}