assertRelation returns 404 but Laravel Nova finds it correctly
nbyloff opened this issue · 0 comments
nbyloff commented
I have a simple Team resource with fields like this:
BelongsToMany::make('Users')->searchable()
->fields(new TeamUserFields),
HasMany::make('Whitelist Ips'),
The Nova UI works just fine and I can save new IP address to the team as expected. However when I run the test below it works fine on the users relation but the whitelist ips throws the error below.
$response = $this->novaDetail('teams', $team->id);
$response->assertOk()
->assertRelation('users', function($users) {
return $users->count() == 1;
})
->assertRelation('whitelistIps', function($ips) {
return $ips->count() == 0;
});
• Tests\Feature\Nova\UserResourceTest > team resource covered
ErrorException
Undefined array key "resources"
at vendor/laravel/framework/src/Illuminate/View/View.php:323
When I look at the data property in the View
class from the error above, it appears to show a 404 and is generating the nova-api incorrectly,
It's creating this with an incorrect resource URL slug:
/nova-api/whitelistIps?viaResource=teams&viaResourceId=1&viaRelationship=whitelistIps&relationshipType=hasMany
When it should be:
/nova-api/whitelist-ips?viaResource=teams&viaResourceId=1&viaRelationship=whitelistIps&relationshipType=hasMany
I have tried different variations of the relationship name, but that always returns "Field not found" error from this package. I am not sure how to get the resource name to generate correctly when using these tests