Ready to get started?

Join Adocasts Plus for $8/mo, or sign into an existing Adocasts Plus account, to get access to all of our lessons.

robot mascot smiling

Pragmatic Testing in AdonisJS with Japa #4.3

testing VineJS Validations & Working with CSRF

In This Lesson

Learn Functional Testing for POST requests. We'll cover sending JSON and form payloads and how to assert validation errors. We'll also discuss how to set up and use CSRF protection with the Session and Shield plugins.

Created by
@tomgobich
Published

Notes Used to Craft this Lesson

Okay, so next we have in our PostsController a store method mimicking a post creation, along with validation.

// app/controllers/posts_controller.ts
export default class PostsController {
  // ...

  async store({ request, response }: HttpContext) {
    const data = await request.validateUsing(postValidator)
    const post = {
      id: randomInt(100),
      ...data,
    }

    return response.created(post)
  }

  // ...
}

Join the Discussion 0 comments

Create a free account to join in on the discussion
robot comment bubble

Be the first to comment!