Publication initiale de RelaisSMS : documentation et sources nettoyees
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Contact;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class OvhStopCallbackTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_ovh_stop_callback_marks_matching_contacts_as_sms_opt_out(): void
|
||||
{
|
||||
config(['relais_sms.ovh.stop_callback_token' => 'secret-token']);
|
||||
|
||||
$cardDavContact = Contact::query()->create([
|
||||
'source' => 'carddav',
|
||||
'external_id' => 'remote-carddav',
|
||||
'last_name' => 'CardDAV',
|
||||
]);
|
||||
$cardDavContact->phoneNumbers()->create([
|
||||
'raw_number' => '06 11 11 11 11',
|
||||
'normalized_number' => '+33611111111',
|
||||
'country' => 'FR',
|
||||
'is_valid' => true,
|
||||
'is_mobile' => true,
|
||||
'is_primary' => true,
|
||||
]);
|
||||
|
||||
$galetteContact = Contact::query()->create([
|
||||
'source' => 'galette',
|
||||
'external_id' => 'remote-galette',
|
||||
'last_name' => 'Galette',
|
||||
]);
|
||||
$galetteContact->phoneNumbers()->create([
|
||||
'raw_number' => '06 11 11 11 11',
|
||||
'normalized_number' => '+33611111111',
|
||||
'country' => 'FR',
|
||||
'is_valid' => true,
|
||||
'is_mobile' => true,
|
||||
'is_primary' => true,
|
||||
]);
|
||||
|
||||
$this->postJson(route('ovh.sms.stop-callback', ['token' => 'secret-token']), [
|
||||
'sender' => '06 11 11 11 11',
|
||||
'message' => 'STOP',
|
||||
])
|
||||
->assertOk()
|
||||
->assertJson([
|
||||
'status' => 'ok',
|
||||
'sender' => '+33611111111',
|
||||
'updated_contacts' => 2,
|
||||
'already_opted_out_contacts' => 0,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('contacts', [
|
||||
'id' => $cardDavContact->id,
|
||||
'sms_opt_out' => true,
|
||||
]);
|
||||
$this->assertDatabaseHas('contacts', [
|
||||
'id' => $galetteContact->id,
|
||||
'sms_opt_out' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_ovh_stop_callback_requires_configured_token(): void
|
||||
{
|
||||
config(['relais_sms.ovh.stop_callback_token' => 'secret-token']);
|
||||
|
||||
$this->postJson(route('ovh.sms.stop-callback', ['token' => 'bad-token']), [
|
||||
'sender' => '06 11 11 11 11',
|
||||
])->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_ovh_stop_callback_accepts_sender_in_query_string(): void
|
||||
{
|
||||
config(['relais_sms.ovh.stop_callback_token' => 'secret-token']);
|
||||
|
||||
$contact = Contact::query()->create([
|
||||
'source' => 'local',
|
||||
'last_name' => 'Local',
|
||||
]);
|
||||
$contact->phoneNumbers()->create([
|
||||
'raw_number' => '07 55 55 00 04',
|
||||
'normalized_number' => '+33755550004',
|
||||
'country' => 'FR',
|
||||
'is_valid' => true,
|
||||
'is_mobile' => true,
|
||||
'is_primary' => true,
|
||||
]);
|
||||
|
||||
$this->getJson(route('ovh.sms.stop-callback', [
|
||||
'token' => 'secret-token',
|
||||
'sender' => '+33755550004',
|
||||
]))
|
||||
->assertOk()
|
||||
->assertJson([
|
||||
'status' => 'ok',
|
||||
'updated_contacts' => 1,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('contacts', [
|
||||
'id' => $contact->id,
|
||||
'sms_opt_out' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user