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.0

The Auth Plugin

In This Lesson

We'll learn how to test authenticated routes in AdonisJS/Japa. First, we'll install and register the Auth API Client plugin. Then, we'll learn how to use our User Factory to create a user and login as them for our test's request.

Created by
@tomgobich
Published

Notes Used to Craft this Lesson

Similar to session and shield, AdonisJS Auth has an API Client plugin we can use to add helpful authentication methods for our tests.

// tests/bootstrap.ts
import { authApiClient } from "@adonisjs/auth/plugins/api_client";

// ...

export const plugins: Config["plugins"] = [
  assert(),
  openapi({
    schemas: [new URL("../docs/openapi.json", import.meta.url)],
  }),
  apiClient(),
  pluginAdonisJS(app),
++  authApiClient(app),
  sessionApiClient(app),
  shieldApiClient(),
  disallowPinnedTests({
    disallow: !!process.env.CI,
  }),
];

Join the Discussion 0 comments

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

Be the first to comment!