Skip to content

Commit c6bd5fe

Browse files
authored
Test create wiki api endpoint can accept a profile (#885)
This commit asserts that adding the additional profile parameter to the wiki creation API does not result in failure. The purpose of this is to make clear that UI development can go ahead and add this parameter to requests without it being necessary to have completed the api work first. It also adds assertions for the parameters that are required for the wiki creation api Bug: T388640
1 parent 57a8d41 commit c6bd5fe

File tree

1 file changed

+66
-12
lines changed

1 file changed

+66
-12
lines changed

tests/Routes/Wiki/CreateTest.php

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,22 @@ class CreateTest extends TestCase
2222
{
2323
protected $route = 'wiki/create';
2424

25+
const defaultData = [
26+
'domain' => 'dErP.com',
27+
'sitename' => 'merp',
28+
'username' => 'AdminBoss',
29+
'profile' => '{
30+
"audience": "narrow",
31+
"temporality": "permanent",
32+
"purpose": "data_hub"
33+
}'
34+
];
35+
2536
use OptionsRequestAllowed;
2637
use DatabaseTransactions;
2738

2839
/**
29-
* @dataProvider createProvider
40+
* @dataProvider createDispatchesSomeJobsProvider
3041
*/
3142
public function testWikiCreateDispatchesSomeJobs( $elasticSearchConfig )
3243
{
@@ -40,15 +51,7 @@ public function testWikiCreateDispatchesSomeJobs( $elasticSearchConfig )
4051
Config::set( 'wbstack.elasticsearch_shared_index_host', $sharedIndexHost );
4152
Config::set( 'wbstack.elasticsearch_shared_index_prefix', $sharedIndexPrefix );
4253

43-
// seed up ready db
44-
$manager = $this->app->make('db');
45-
$job = new ProvisionWikiDbJob();
46-
$job->handle($manager);
47-
48-
$dbRow = QueryserviceNamespace::create([
49-
'namespace' => "derp",
50-
'backend' => "wdqs.svc",
51-
]);
54+
$this->createSQLandQSDBs();
5255

5356
Queue::fake();
5457

@@ -62,7 +65,12 @@ public function testWikiCreateDispatchesSomeJobs( $elasticSearchConfig )
6265
[
6366
'domain' => 'dErP.com',
6467
'sitename' => 'merp',
65-
'username' => 'AdminBoss'
68+
'username' => 'AdminBoss',
69+
'profile' => '{
70+
"audience": "narrow",
71+
"temporality": "permanent",
72+
"purpose": "data_hub"
73+
}'
6674
]
6775
);
6876

@@ -109,7 +117,7 @@ public function testWikiCreateDispatchesSomeJobs( $elasticSearchConfig )
109117
}
110118
}
111119

112-
static public function createProvider() {
120+
static public function createDispatchesSomeJobsProvider() {
113121
yield [ [
114122
'enabledForNewWikis' => true,
115123
'clusterWithoutSharedIndex' => 'all',
@@ -219,4 +227,50 @@ public function testCreateWikiLimitsNumWikisPerUser()
219227
->assertJsonPath('data.domain', 'mywikidomain-2.com')
220228
->assertJsonPath('success', true );
221229
}
230+
231+
private function createSQLandQSDBs(): void {
232+
$manager = $this->app->make('db');
233+
$job = new ProvisionWikiDbJob();
234+
$job->handle($manager);
235+
236+
QueryserviceNamespace::create([
237+
'namespace' => "derp",
238+
'backend' => "wdqs.svc",
239+
]);
240+
}
241+
242+
/**
243+
* @dataProvider createWikiHandlesRangeOfPostValuesProvider
244+
*/
245+
public function testCreateWikiHandlesRangeOfPostValues($data, $expectedStatus): void {
246+
$this->createSQLandQSDBs();
247+
Queue::fake();
248+
$user = User::factory()->create(['verified' => true]);
249+
$response = $this->actingAs($user, 'api')
250+
->json(
251+
'POST',
252+
$this->route,
253+
$data
254+
);
255+
$response->assertStatus( $expectedStatus );
256+
}
257+
258+
static public function createWikiHandlesRangeOfPostValuesProvider(): array {
259+
$noDomain = self::defaultData;
260+
unset($noDomain['domain']);
261+
$noSitename = self::defaultData;
262+
unset($noSitename['sitename']);
263+
$noUsername = self::defaultData;
264+
unset($noUsername['username']);
265+
$noprofile = self::defaultData;
266+
unset($noprofile['profile']);
267+
return [
268+
'all params present' => [self::defaultData , 200],
269+
'missing domain' => [$noDomain, 422],
270+
'missing sitename' => [$noSitename, 422],
271+
'missing username' => [$noUsername, 422],
272+
'missing profile' => [$noprofile, 200]
273+
];
274+
}
275+
222276
}

0 commit comments

Comments
 (0)