-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from nicp0nim/tests
make tests for app: register, login, logout, clients
- Loading branch information
Showing
16 changed files
with
395 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
APP_NAME='RestApi' | ||
APP_ENV=testing | ||
APP_KEY=base64:CS3VLz1BGmBBZBTSCQLShZ5NaM+A1MZukOro1fT4hRU= | ||
APP_DEBUG=true | ||
APP_URL=http://localhost:8080 | ||
|
||
LOG_CHANNEL=stack | ||
|
||
DB_CONNECTION=testing | ||
DB_TEST_DATABASE=testing | ||
DB_TEST_USERNAME=root | ||
DB_TEST_PASSWORD= | ||
|
||
QUEUE_DRIVER=sync | ||
BROADCAST_DRIVER=log | ||
CACHE_DRIVER=array | ||
QUEUE_CONNECTION=sync | ||
SESSION_DRIVER=array | ||
SESSION_LIFETIME=120 | ||
|
||
REDIS_HOST=127.0.0.1 | ||
REDIS_PASSWORD=null | ||
REDIS_PORT=6379 | ||
|
||
MAIL_DRIVER=smtp | ||
MAIL_HOST=smtp.mailtrap.io | ||
MAIL_PORT=2525 | ||
MAIL_USERNAME=null | ||
MAIL_PASSWORD=null | ||
MAIL_ENCRYPTION=null | ||
|
||
AWS_ACCESS_KEY_ID= | ||
AWS_SECRET_ACCESS_KEY= | ||
AWS_DEFAULT_REGION=us-east-1 | ||
AWS_BUCKET= | ||
|
||
PUSHER_APP_ID= | ||
PUSHER_APP_KEY= | ||
PUSHER_APP_SECRET= | ||
PUSHER_APP_CLUSTER=mt1 | ||
|
||
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" | ||
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" | ||
|
||
TELESCOPE_ENABLED=false | ||
TELESCOPE_USERS=1,2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
language: php | ||
|
||
services: | ||
- mysql | ||
before_script: | ||
- composer install | ||
- cp .env.example .env | ||
- cp .env.travis .env | ||
- mysql -e 'create database testing;' | ||
- composer self-update | ||
- composer install --no-interaction | ||
- php artisan key:generate | ||
- php artisan migrate --seed | ||
- php artisan passport:install | ||
script: | ||
- vendor/bin/phpunit | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
use App\User; | ||
use Illuminate\Database\Seeder; | ||
|
||
class UserSeeder extends Seeder | ||
{ | ||
/** | ||
* Run the database seeds. | ||
* | ||
* @return void | ||
*/ | ||
public function run() | ||
{ | ||
factory(User::class, 10)->create(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
<?php | ||
|
||
namespace Tests\Feature; | ||
|
||
use App\Client; | ||
use App\User; | ||
use Tests\TestCase; | ||
|
||
class ClientTest extends TestCase | ||
{ | ||
public function testsClientsAreCreatedCorrectly() | ||
{ | ||
$user = factory(User::class)->create(); | ||
$token = $user->createToken('RestApi')->accessToken; | ||
$headers = ['Authorization' => "Bearer $token"]; | ||
$payload = [ | ||
'name' => 'Szczepańska', | ||
'vat_number' => '6529411372', | ||
'street' => 'Sądowa 15A/28', | ||
'city' => 'Bogatynia', | ||
'post_code' => '22-090', | ||
'email' => '[email protected]' | ||
]; | ||
|
||
$this->json('POST', '/api/clients', $payload, $headers) | ||
->assertStatus(200) | ||
->assertJson([ | ||
'success' => true, | ||
'data' => [ | ||
'id' => 11, | ||
'name' => 'Szczepańska', | ||
'vat_number' => '6529411372', | ||
'street' => 'Sądowa 15A/28', | ||
'city' => 'Bogatynia', | ||
'post_code' => '22-090', | ||
'email' => '[email protected]' | ||
], | ||
'message' => 'Client created successfully.' | ||
]); | ||
} | ||
|
||
public function testsClientsAreUpdatedCorrectly() | ||
{ | ||
$user = factory(User::class)->create(); | ||
$token = $user->createToken('RestApi')->accessToken; | ||
$headers = ['Authorization' => "Bearer $token"]; | ||
$article = factory(Client::class)->create([ | ||
'name' => 'Szczepańska', | ||
'vat_number' => '6529411372', | ||
'street' => 'Sądowa 15A/28', | ||
'city' => 'Bogatynia', | ||
'post_code' => '22-090', | ||
'email' => '[email protected]' | ||
]); | ||
|
||
$payload = [ | ||
'name' => 'Barańska', | ||
'vat_number' => '1234567890', | ||
'street' => 'Rolna 12', | ||
'city' => 'Warszawa', | ||
'post_code' => '01-000', | ||
'email' => '[email protected]' | ||
]; | ||
|
||
$response = $this->json('PUT', '/api/clients/'.$article->id, $payload, $headers) | ||
->assertStatus(200) | ||
->assertJson([ | ||
'success' => true, | ||
'data' => [ | ||
'id' => 11, | ||
'name' => 'Barańska', | ||
'vat_number' => '1234567890', | ||
'street' => 'Rolna 12', | ||
'city' => 'Warszawa', | ||
'post_code' => '01-000', | ||
'email' => '[email protected]' | ||
], | ||
'message' => 'Client updated successfully.' | ||
]); | ||
} | ||
|
||
public function testsClientsAreDeletedCorrectly() | ||
{ | ||
$user = factory(User::class)->create(); | ||
$token = $user->createToken('RestApi')->accessToken; | ||
$headers = ['Authorization' => "Bearer $token"]; | ||
$article = factory(Client::class)->create([ | ||
'name' => 'Szczepańska', | ||
'vat_number' => '6529411372', | ||
'street' => 'Sądowa 15A/28', | ||
'city' => 'Bogatynia', | ||
'post_code' => '22-090', | ||
'email' => '[email protected]' | ||
]); | ||
|
||
$this->json('DELETE', '/api/clients/'.$article->id, [], $headers) | ||
->assertStatus(200); | ||
} | ||
|
||
public function testClientsAreListedCorrectly() | ||
{ | ||
factory(Client::class)->create([ | ||
'name' => 'Szczepańska', | ||
'vat_number' => '6529411372', | ||
'street' => 'Sądowa 15A/28', | ||
'city' => 'Bogatynia', | ||
'post_code' => '22-090', | ||
'email' => '[email protected]' | ||
]); | ||
|
||
factory(Client::class)->create([ | ||
'name' => 'Barańska', | ||
'vat_number' => '1234567890', | ||
'street' => 'Rolna 12', | ||
'city' => 'Warszawa', | ||
'post_code' => '01-000', | ||
'email' => '[email protected]' | ||
]); | ||
|
||
$user = factory(User::class)->create(); | ||
$token = $user->createToken('RestApi')->accessToken; | ||
$headers = ['Authorization' => "Bearer $token"]; | ||
|
||
$response = $this->json('GET', '/api/clients', [], $headers) | ||
->assertStatus(200) | ||
->assertJsonStructure([ | ||
'success', | ||
'data' => [ | ||
'*' => [ | ||
'id', | ||
'name', | ||
'vat_number', | ||
'street', | ||
'city', | ||
'post_code', | ||
'email' | ||
] | ||
], | ||
'message' | ||
]); | ||
} | ||
} |
Oops, something went wrong.