Reputation: 1523
I am trying to use database and laravel-lighthouse in tests. I am using the traits for GraphQL and Database Testing, mutation works but tests don't.
class MyTest extends TestCase{
use MakesGraphQLRequests;
use RefreshDatabase;
public function testGraphQLDatabaseTest(){
$this->graphQL(/** @lang GraphQL */ '
mutation CreatePost($title: String!) {
createPost(title: $title) {
id
}
}
',['title' => 'test title']);
$this->assertDatabaseHas('posts', [
'title' => 'test title',
]); // It says that expect table posts with title' => 'test title' but 'posts' table is empty
}
}
Upvotes: 0
Views: 547
Reputation: 317
Which database driver are you using? SQLite3 with :memory:?
An alternative way of checking could be to use the Entities itself. E.g.:
$this->assertEquals('test title', Post::find(1)->title);
At least you could give it a try. If this also doesn't work I would try to create the entry with Post::create(...) first. If this works, it's a problem with your Resolver. Maybe you can also show the corresponding GraphQL schema to use.
Upvotes: 1
Reputation: 1523
I have some Facades in the mutation in this case I just add the facades fake or stub to figure out the issue.
// Example
// At the beginning of the test
public function testGraphQLDatabaseTest(){
Mail::fake();
//...
}
Upvotes: 0