-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDeleteQueryserviceNamespaceJobTest.php
More file actions
108 lines (85 loc) · 3.48 KB
/
Copy pathDeleteQueryserviceNamespaceJobTest.php
File metadata and controls
108 lines (85 loc) · 3.48 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
<?php
namespace Tests\Jobs;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use App\Http\Curl\HttpRequest;
use App\Jobs\DeleteQueryserviceNamespaceJob;
use App\QueryserviceNamespace;
use Illuminate\Support\Facades\DB;
use App\WikiManager;
use App\User;
use App\Wiki;
use Carbon\Carbon;
use Illuminate\Contracts\Queue\Job;
class DeleteQueryserviceNamespaceJobTest extends TestCase
{
use RefreshDatabase;
public function testDeleteNamespace()
{
$user = User::factory()->create(['verified' => true]);
$wiki = Wiki::factory()->create( [ 'deleted_at' => Carbon::now()->subDays(30)->timestamp ] );
WikiManager::factory()->create(['wiki_id' => $wiki->id, 'user_id' => $user->id]);
$namespace = 'asdf';
$host = config('app.queryservice_host');
$dbRow = QueryserviceNamespace::create([
'namespace' => $namespace,
'backend' => $host,
]);
DB::table('queryservice_namespaces')->where(['id'=>$dbRow->id])->limit(1)->update(['wiki_id' => $wiki->id]);
putenv('CURLOPT_TIMEOUT_DELETE_QUERYSERVICE_NAMESPACE=1234');
$mockResponse = 'DELETED: '.$namespace;
$request = $this->createMock(HttpRequest::class);
$request->expects($this->exactly(1))
->method('execute')
->willReturn( $mockResponse );
$request->expects($this->exactly(1))
->method('setOptions')
->with(
[
CURLOPT_URL => $dbRow->backend.'/bigdata/namespace/' . $namespace,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_TIMEOUT => 1234,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
// User agent is needed by the query service...
CURLOPT_USERAGENT => 'WBStack DeleteQueryserviceNamespaceJob',
CURLOPT_CUSTOMREQUEST => 'DELETE',
CURLOPT_HTTPHEADER => [
'content-type: text/plain',
]
]);
$job = new DeleteQueryserviceNamespaceJob($wiki->id);
$job->handle( $request );
$this->assertSame(
0,
QueryserviceNamespace::where( ['namespace' => $namespace ])->count()
);
}
public function testNoWiki() {
$mockJob = $this->createMock(Job::class);
$mockJob->expects($this->once())
->method('fail')
->with(new \RuntimeException("Wiki not found for 123"));
$request = $this->createMock(HttpRequest::class);
$request->expects($this->never())
->method('execute');
$job = new DeleteQueryserviceNamespaceJob(123);
$job->setJob($mockJob);
$job->handle($request);
}
public function testNoNamespace() {
$user = User::factory()->create(['verified' => true]);
$wiki = Wiki::factory()->create( [ 'deleted_at' => Carbon::now()->subDays(30)->timestamp ] );
WikiManager::factory()->create(['wiki_id' => $wiki->id, 'user_id' => $user->id]);
$mockJob = $this->createMock(Job::class);
$mockJob->expects($this->once())
->method('fail')
->with(new \RuntimeException("Namespace for wiki {$wiki->id} not found."));
$request = $this->createMock(HttpRequest::class);
$request->expects($this->never())
->method('execute');
$job = new DeleteQueryserviceNamespaceJob($wiki->id);
$job->setJob($mockJob);
$job->handle($request);
}
}