callApi('get', route('apiV2.ping')); $json = $response->decodeResponseJson(); $this->assertApiResponseStatusIs($json, ApiStatus::OK()); $response = $this->json('get', route('apiV2.ping'), ['timestamp' => time()], [ 'X-API-TIMESTAMP' => time() + 119 ]); $json = $response->decodeResponseJson(); $this->assertApiResponseStatusIs($json, ApiStatus::OK()); $response = $this->json('get', route('apiV2.ping'), ['timestamp' => time()], [ 'X-API-TIMESTAMP' => time() + 121 ]); $json = $response->decodeResponseJson(); $this->assertApiResponseStatusIs($json, ApiStatus::KO()); $json->assertFragment(['data' => [ 'code' => ApiError::wrongTimeStamp()->value, 'message' => ApiError::wrongTimeStamp()->label ]]); } /** * route: apiV2.authenticate */ public function testApiAuthenticate() { extract($this->getCustomer()); $response = $this->callApi( 'post', route('apiV2.authenticate'), ['bearer_pwd' => $service->bearer_pwd], ['Authorization' => sprintf('Bearer %s', $service->bearer_token)] ); $json = $response->decodeResponseJson(); $this->assertApiResponseStatusIs($json, ApiStatus::OK()); $this->assertNotEmpty($json->json('data')); $this->assertNotEmpty($json->json('data.api_token')); $this->assertTrue(Hash::check($json->json('data.api_token'), Service::findOrFail($service->id)->api_token)); } }