I would need your help regarding a type error on the argument of the loginAs()
function in a controller test.
Context: I have set up authentication for 2 different models (User & Facility), everything works perfectly via Postman calls. My Facility model can have multiple Offers, and an Offer belongs to a Facility. My controller test makes a request to this URL: /api/v1/facilities/${facility.id}/offers
, it's a nested route, protected with Facility authentication and guard.
Here is my test code:
import { test } from '@japa/runner'
import Facility from 'App/Models/Facility'
import { FacilityFactory } from 'Database/factories/FacilityFactory'
import { status, json } from '../../../shared-examples'
test.group('#GET /api/v1/facilities/:facility_id/offers', (group): void => {
let facility: Facility
group.each.setup(async (): Promise<void> => {
facility = await FacilityFactory.with('offers', 20).create()
await facility.load('offers')
})
test('returns 200 status', async ({ client }): Promise<void> => {
const response = await client
.get(`/api/v1/facilities/${facility.id}/offers`)
.guard('facility')
.loginAs(facility) // The type argument [Facility] is not assignable to the type parameter never
status(response, 200)
})
})
My test passes without issues, but I have an error during the build on .loginAs(facility)
, which is as follows: The type argument [Facility] is not assignable to the type parameter never
. Here is the typing of the loginAs()
function: loginAs(...args: never): ApiRequest
from Adonis.
I can't understand this error. Here is the link to the Adonis documentation for the usage of loginAs()
: Adonis Doc
If you have any ideas, I'm all ears
Thank you very much