syropian's avatar

Queued Image Upload: Assert job handler modified model correctly?

I have a photo post model, and when a user saves their post, the image gets uploaded locally, and then a job is dispatched to take that image, upload it to the cloud, and update the model with the new cloud url.

From what I understand, when you fake the Queue class, you can only spy on the act of a job getting pushed to a queue, not the result of the job itself. So when feature testing my "photo post" saving, how can I assert that not only was a job pushed to the queue, but that it was successfully uploaded to my (faked) cloud storage?

Or is the idea that you'd write a completely separate test for the job class itself? I'm pretty new to testing, so these little snafoos are still a mystery to me :D

0 likes
2 replies
danmatthews's avatar
Level 5

In the interest of separating things, i would write a separate test.

The controller presumably does it's part - pushes the item to the queue, then the handler for the queued job is a separate part of the process as it's executed 'later' rather than synchronously.

If you wanted to test that it all works together, you could change the queue driver in you .env.testing file to sync, meaning that the action would happen immediately, you could then test the state of the altered photo post model.

Please or to participate in this conversation.