tenant = Tenant::factory()->create(); $this->otherTenant = Tenant::factory()->create(); $this->service = app(ClientSmsUnsubscribeLinkService::class); }); it('токен на пару «клиент + номер» постоянный', function () { $first = $this->service->tokenFor($this->tenant->id, '79990000001'); $second = $this->service->tokenFor($this->tenant->id, '79990000001'); expect($second)->toBe($first) ->and(strlen($first))->toBe(12) ->and(ClientSmsUnsubscribeLink::count())->toBe(1); }); it('у разных клиентов на один номер разные ссылки', function () { $mine = $this->service->tokenFor($this->tenant->id, '79990000001'); $theirs = $this->service->tokenFor($this->otherTenant->id, '79990000001'); expect($theirs)->not->toBe($mine) ->and(ClientSmsUnsubscribeLink::count())->toBe(2); }); it('по токену находится тот самый клиент и тот самый номер', function () { $token = $this->service->tokenFor($this->tenant->id, '79990000002'); $link = ClientSmsUnsubscribeLink::findOrFail($token); expect($link->tenant_id)->toBe($this->tenant->id) ->and($link->phone)->toBe('79990000002'); }); it('в токене нет букв и цифр, которые путаются при чтении вслух', function () { $tokens = []; foreach (range(1, 20) as $i) { $tokens[] = $this->service->tokenFor($this->tenant->id, '7999000'.str_pad((string) $i, 4, '0', STR_PAD_LEFT)); } // 0/O/o, 1/l/I — человек диктует ссылку по телефону, путаница = чужая страница expect(implode('', $tokens))->not->toMatch('/[0OolI1]/'); });