assertFragment(['status' => $status->value()]); } /** * Raw Function to call api. * * @param string $method * @param string $uri * @param array $data * @param array $headers * @return \Illuminate\Testing\TestResponse */ protected function callApi( string $method, string $uri, array $data = [], array $headers = [] ): \Illuminate\Testing\TestResponse { if (!isset($data['timestamp'])) { $data['timestamp'] = \time(); } return $this->json($method, $uri, $data, $headers); } /** * Raw Function to call api with Token. * * @param \App\Models\Service $service * @param string $method * @param string $uri * @param array $data * @param array $headers * @return \Illuminate\Testing\TestResponse */ protected function callApiWithToken( Service $service, string $method, string $uri, array $data = [], array $headers = [] ): \Illuminate\Testing\TestResponse { $data['bearer_token'] = $service->bearer_token; $data['timestamp'] = \gmdate('Y-m-d H:i:s'); $data['signature'] = Helper::signRequest( $service->bearer_pwd, $uri, $method, $data ); return $this->callApi($method, $uri, $data, $headers); } /** * Get Customer models with given status (active or not). * * @param boolean $status The customer status for a brand. * @param boolean $random Randomize the customer to get. * @return array Data in array: customer, service, login, brand, info. */ protected function getCustomer(bool $status = true, bool $random = true): array { $login = CustomerLogin::query()->where('status', $status); if ($random) { $login = $login->inRandomOrder(); } /** @var \App\Models\CustomerLogin $login */ $login = $login->firstOrFail(); /** @var \App\Models\Brand $brand */ $brand = $login->brand; /** @var \App\Models\Customer $customer */ $customer = $login->customer; /** @var \App\Models\Service $service */ $service = $brand->services()->firstOrFail(); /** @var \App\Models\CustomerInfo $info */ $info = $customer->info($brand, Customer::FIRST_OR_FAIL); return compact('customer', 'service', 'login', 'brand', 'info'); } }