PROBLEM with HEADER for test API Jetstream Sanctum Laravel 8x with PERMISSION

137 views Asked by At

I generated two tokens:

tokenA = As2 ... xxxxx //can perform ONLY  create
tokenB = Bs2 ... xxxxx //can perform ONLY update

I have the following problem:

$response = $this->withHeaders([
            'Accept' => 'application/json',
            'Authorization' => 'Bearer '.$tokenA],
        ])->post('/api/store',$data);
        $response->assertStatus(201);

//the store is made without problems

$response = $this->withHeaders([
            'Accept' => 'application/json',
            'Authorization' => 'Bearer '.tokenB,
        ])->put('/api/update',$dataUpdate);
        $respone->assertStatus(200);

//the test fails and returns 403. As if you don't have permission to do that

While if I call only:

$response = $this->withHeaders([
            'Accept' => 'application/json',
            'Authorization' => 'Bearer '.tokenB,
        ])->put('/api/update',$dataUpdate);
        $response->assertStatus(200);

the update is performed without problems.

How can I run the store and then the update in sequence?

It appears that $response continues to hold the value of tokenA.

0

There are 0 answers