store image in AWS s3 bucket and then the resulted URL in database, API using postman and swagger are working fine, but test case I'm unable to write

Viewed 23

This is the controller validator.

$validator = Validator::make($request->all(), [
            'name' => 'required|string|min:3|max:50',
            'description' => 'required|string|min:5|max:1000',
            'author' => 'required|string|min:5|max:50',
            'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg,tiff|max:2048',
            'price' => 'required',
            'quantity' => 'required|integer'
        ]);

This is my test case.

$response = $this->withHeaders([
        'Content-Type' => 'Application/json',
    ])
        ->json('POST', '/api/addbook', [
            "name" => "Harry Potter Book",
            "description" => "A Series of Harry Potter Books has been Released.",
            "author" => "J.K. Rowling",
            "image" => "Harry Potter and the Half-Blood Prince.jpg",
            "price" => "699.99",
            "quantity" => "1500",
            "token" => self::$token
        ]);
    $response->assertStatus(201)->assertJson(['message' => 'Book Added Successfully']);

Here in the image field, I am unable to add image. any idea how to add images in test cases, from anywhere, like storage, public, or from your system files. in to my laravel project.

0 Answers
Related