Everywhere: Implement HTMX todo page
This commit is contained in:
@@ -9,9 +9,9 @@ struct AppTests {
|
||||
let app = try await Application.make(.testing)
|
||||
do {
|
||||
try await configure(app)
|
||||
try await app.autoMigrate()
|
||||
try await app.autoMigrate()
|
||||
try await test(app)
|
||||
try await app.autoRevert()
|
||||
try await app.autoRevert()
|
||||
}
|
||||
catch {
|
||||
try await app.asyncShutdown()
|
||||
@@ -19,7 +19,7 @@ struct AppTests {
|
||||
}
|
||||
try await app.asyncShutdown()
|
||||
}
|
||||
|
||||
|
||||
@Test("Test Hello World Route")
|
||||
func helloWorld() async throws {
|
||||
try await withApp { app in
|
||||
@@ -29,26 +29,26 @@ struct AppTests {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test("Getting all the Todos")
|
||||
func getAllTodos() async throws {
|
||||
try await withApp { app in
|
||||
let sampleTodos = [Todo(title: "sample1"), Todo(title: "sample2")]
|
||||
try await sampleTodos.create(on: app.db)
|
||||
|
||||
try await app.test(.GET, "todos", afterResponse: { res async throws in
|
||||
|
||||
try await app.test(.GET, "api/todos", afterResponse: { res async throws in
|
||||
#expect(res.status == .ok)
|
||||
#expect(try res.content.decode([TodoDTO].self) == sampleTodos.map { $0.toDTO()} )
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test("Creating a Todo")
|
||||
func createTodo() async throws {
|
||||
let newDTO = TodoDTO(id: nil, title: "test")
|
||||
|
||||
|
||||
try await withApp { app in
|
||||
try await app.test(.POST, "todos", beforeRequest: { req in
|
||||
try await app.test(.POST, "api/todos", beforeRequest: { req in
|
||||
try req.content.encode(newDTO)
|
||||
}, afterResponse: { res async throws in
|
||||
#expect(res.status == .ok)
|
||||
@@ -58,15 +58,15 @@ struct AppTests {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test("Deleting a Todo")
|
||||
func deleteTodo() async throws {
|
||||
let testTodos = [Todo(title: "test1"), Todo(title: "test2")]
|
||||
|
||||
|
||||
try await withApp { app in
|
||||
try await testTodos.create(on: app.db)
|
||||
|
||||
try await app.test(.DELETE, "todos/\(testTodos[0].requireID())", afterResponse: { res async throws in
|
||||
|
||||
try await app.test(.DELETE, "api/todos/\(testTodos[0].requireID())", afterResponse: { res async throws in
|
||||
#expect(res.status == .noContent)
|
||||
let model = try await Todo.find(testTodos[0].id, on: app.db)
|
||||
#expect(model == nil)
|
||||
|
||||
Reference in New Issue
Block a user