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 #6.1

Testing Auth Protected Routes

In This Lesson

We'll learn how to test auth-protected routes via the auth middleware and non-auth-protected routes via the guest middleware. We'll ensure our user is redirected appropriately and shown a flash message where applicable

Created by
@tomgobich
Published

Notes Used to Craft this Lesson

What we want to do now is write a test for the sad path where our unauthenticated user is blocked from accessing the page because our authentication middleware is protecting the route.

test("not allow an unauthenticated user to view the page", async ({
  assert,
  client,
  route,
}) => {
  const response = await client.get(route("settings.account"));

  response.assertOk();
  response.assertTextIncludes("Unauthorized access");
});

Join the Discussion 0 comments

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

Be the first to comment!