faker = \Faker\Factory::create(); Model::reguard(); $this->makeTestData(); $this->withoutMiddleware( ThrottleRequests::class ); } public function testNumericParse() { $this->assertFalse(is_numeric("2760.0,139.14")); } public function testNoAmountGiven() { $data = [ // 'amount' => 0, 'client_id' => $this->client->hashed_id, 'invoices' => [ [ 'invoice_id' => $this->invoice->hashed_id, 'amount' => 10, ], ], 'credits' => [ [ 'credit_id' => $this->credit->hashed_id, 'amount' => 5 ] ], 'date' => '2019/12/12', ]; $response = false; try { $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, ])->post('/api/v1/payments/', $data); } catch (ValidationException $e) { $message = json_decode($e->validator->getMessageBag(), 1); nlog($e->validator->getMessageBag()); } $response->assertStatus(200); } public function testInValidPaymentAmount() { $data = [ 'amount' => "10,33", 'client_id' => $this->client->hashed_id, 'invoices' => [ ], 'date' => '2019/12/12', ]; $response = false; try { $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, ])->post('/api/v1/payments/', $data); } catch (ValidationException $e) { $message = json_decode($e->validator->getMessageBag(), 1); nlog($e->validator->getMessageBag()); } $response->assertStatus(302); } public function testValidPayment() { $data = [ 'amount' => 0, 'client_id' => $this->client->hashed_id, 'invoices' => [ ], 'date' => '2019/12/12', ]; $response = false; try { $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, ])->post('/api/v1/payments/', $data); } catch (ValidationException $e) { $message = json_decode($e->validator->getMessageBag(), 1); nlog($e->validator->getMessageBag()); } $response->assertStatus(200); } public function testValidPaymentWithAmount() { $data = [ 'amount' => 0, 'client_id' => $this->client->hashed_id, 'invoices' => [ [ 'invoice_id' => $this->invoice->hashed_id, 'amount' => 10, ], ], 'credits' => [ [ 'credit_id' => $this->credit->hashed_id, 'amount' => 5 ] ], 'date' => '2019/12/12', ]; $response = false; try { $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, ])->post('/api/v1/payments/', $data); } catch (ValidationException $e) { $message = json_decode($e->validator->getMessageBag(), 1); nlog($e->validator->getMessageBag()); } $response->assertStatus(200); } public function testValidPaymentWithInvalidData() { $data = [ 'amount' => 0, 'client_id' => $this->client->hashed_id, 'invoices' => [ [ 'invoice_id' => $this->invoice->hashed_id, ], ], 'credits' => [ [ 'credit_id' => $this->credit->hashed_id, 'amount' => 5 ] ], 'date' => '2019/12/12', ]; $response = false; try{ $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, ])->post('/api/v1/payments/', $data); }catch(ValidationException $e){ $response->assertStatus(302); } } }