-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplicationTest.php
More file actions
119 lines (98 loc) · 2.95 KB
/
Copy pathApplicationTest.php
File metadata and controls
119 lines (98 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
use Carbon\Carbon;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class ApplicationTest extends TestCase
{
use DatabaseTransactions;
public function setUp(): void
{
parent::setUp();
$this->app->instance('middleware.disable', true);
DB::delete('DELETE FROM applications');
}
/**
* @return $this
*/
public function test_it_lists_apps()
{
$app = \App\Models\Application::create([
'tenant_user_id' => '999',
'tenant_id' => 1,
'name' => 'test',
'description' => null,
'key' => '1234567890',
]);
$data = [
'data' => [
[
'id' => $app->id,
'name' => 'test',
'description' => null,
'key' => '1234567890',
],
],
];
$response = $this->json('GET', '/' . config('app.api_version') . '/apps?userId=999');
$response->assertStatus(200);
$response->assertJsonFragment($data);
}
/**
* @return $this
*/
public function test_it_gets_app()
{
$app = \App\Models\Application::create([
'tenant_user_id' => '999',
'tenant_id' => 1,
'name' => 'test',
'description' => null,
'key' => '1234567890',
]);
$data = [
'data' => [
'id' => $app->id,
'name' => 'test',
'description' => null,
'key' => '1234567890',
],
];
$response = $this->json('GET', '/' . config('app.api_version') . '/apps/'.$app->id);
$response->assertStatus(200);
$response->assertJsonFragment($data);
}
/**
* @return $this
*/
public function test_it_deletes_app()
{
$app = \App\Models\Application::create([
'tenant_user_id' => '999',
'tenant_id' => 1,
'name' => 'test',
'description' => null,
'key' => '1234567890',
]);
$this->json('DELETE', '/' . config('app.api_version') . '/apps/'.$app->id)->assertStatus(200);
$this->assertDatabaseHas('applications', [
'id' => $app->id,
'deleted_at' => Carbon::now()->toDateTimeString(),
]);
}
/**
* @return $this
*/
public function test_it_creates_app()
{
$this->markTestSkipped('Bug Request POST parameters lost when unit testing https://github.com/laravel/lumen-framework/issues/559 upgrade to Lumen 5.4.2+');
$this->json('POST', '/' . config('app.api_version') . '/apps/', [
'userId' => '55',
'name' => 'Hello',
])->assertStatus(200);
$this->assertDatabaseMissing('applications', [
'tenant_user_id' => '55',
'name' => 'Hello',
]);
}
}