Expected status code 200 but received 201.

Posted 2 months ago by hjortur17

I can't figure out why I'm receiving 201 instead of 200. Here is the test and the controller

public function users_may_only_reply_a_maximum_of_once_per_minute()
    {
        $this->signIn();

        $thread = create('App\Thread');
        $reply = make('App\Reply', [
            'body' => 'My simple reply.'
        ]);

        $this->post($thread->path().'/athugasemdir', $reply->toArray())
            ->assertStatus(200);

        $this->post($thread->path().'/athugasemdir', $reply->toArray())
            ->assertStatus(422);
    }
public function store($channelId, Thread $thread)
    {
        if (Gate::denies('create', new Reply)) {
            return response(
                'Sorry, you are posting too frequently. Please take a brake.', 422
            );
        }
        
        try {
            request()->validate(['body' => 'required|spamfree']);

            $reply = $thread->addReply([
                'body' => request('body'),
                'user_id' => auth()->id()
            ]);
        } catch (\Exception $e) {
            return response(
                'Sorry, your reply could not be saved at this time', 422
            );  
        }

        return $reply->load('owner');
    }

Please sign in or create an account to participate in this conversation.