|
5 | 5 | use App\Jobs\ElasticSearchAliasInit; |
6 | 6 | use App\Jobs\MediawikiInit; |
7 | 7 | use App\Jobs\ProvisionWikiDbJob; |
| 8 | +use App\KnowledgeEquityResponse; |
8 | 9 | use App\QueryserviceNamespace; |
9 | 10 | use App\User; |
10 | 11 | use App\Wiki; |
@@ -310,4 +311,82 @@ public function testCreateWithProfileCreatesProfiles(): void { |
310 | 311 | WikiProfile::where(['wiki_id' => $id])->count() |
311 | 312 | ); |
312 | 313 | } |
| 314 | + |
| 315 | + public function testCreateWithKERCreatesProfiles(): void { |
| 316 | + $this->createSQLandQSDBs(); |
| 317 | + Queue::fake(); |
| 318 | + $user = User::factory()->create(['verified' => true]); |
| 319 | + $response = $this->actingAs($user, 'api') |
| 320 | + ->json( |
| 321 | + 'POST', |
| 322 | + $this->route, |
| 323 | + [...self::defaultData, 'knowledgeEquityResponse' => [ |
| 324 | + // This only tests the selectedOption since in the future this will become required while |
| 325 | + // the freeTextResponse will not. |
| 326 | + 'selectedOption' => 'yes', |
| 327 | + ]] |
| 328 | + ); |
| 329 | + $id = $response->decodeResponseJson()['data']['id']; |
| 330 | + $this->assertEquals(1, |
| 331 | + KnowledgeEquityResponse::where(['wiki_id' => $id])->count() |
| 332 | + ); |
| 333 | + } |
| 334 | + |
| 335 | + public function testCreateWithKERRejectsIfSelectedOptionIsInvalid(): void { |
| 336 | + $this->createSQLandQSDBs(); |
| 337 | + Queue::fake(); |
| 338 | + $user = User::factory()->create(['verified' => true]); |
| 339 | + $response = $this->actingAs($user, 'api') |
| 340 | + ->json( |
| 341 | + 'POST', |
| 342 | + $this->route, |
| 343 | + [...self::defaultData, 'knowledgeEquityResponse' => [ |
| 344 | + 'selectedOption' => 'yeeeeeah', |
| 345 | + ]] |
| 346 | + ); |
| 347 | + $response->assertStatus(422); |
| 348 | + // This only tests for the existance of an error key. |
| 349 | + // Using JSON path to check the specific errors message |
| 350 | + // binds very tightly to the laravel implemention of validation and was hard to make work. |
| 351 | + $response->assertJsonStructure(['errors']); |
| 352 | + } |
| 353 | + |
| 354 | + public function testCreateWithKERCreatesIf3000FreeTextResponse(): void { |
| 355 | + $this->createSQLandQSDBs(); |
| 356 | + Queue::fake(); |
| 357 | + $user = User::factory()->create(['verified' => true]); |
| 358 | + $response = $this->actingAs($user, 'api') |
| 359 | + ->json( |
| 360 | + 'POST', |
| 361 | + $this->route, |
| 362 | + [...self::defaultData, 'knowledgeEquityResponse' => [ |
| 363 | + 'selectedOption' => 'yes', |
| 364 | + 'freeTextResponse' => str_repeat('a', 3000), |
| 365 | + ]] |
| 366 | + ); |
| 367 | + $id = $response->decodeResponseJson()['data']['id']; |
| 368 | + $this->assertEquals(1, |
| 369 | + KnowledgeEquityResponse::where(['wiki_id' => $id])->count() |
| 370 | + ); |
| 371 | + } |
| 372 | + |
| 373 | + public function testCreateWithKERErrorsIf3001FreeTextResponse(): void { |
| 374 | + $this->createSQLandQSDBs(); |
| 375 | + Queue::fake(); |
| 376 | + $user = User::factory()->create(['verified' => true]); |
| 377 | + $response = $this->actingAs($user, 'api') |
| 378 | + ->json( |
| 379 | + 'POST', |
| 380 | + $this->route, |
| 381 | + [...self::defaultData, 'knowledgeEquityResponse' => [ |
| 382 | + 'selectedOption' => 'yes', |
| 383 | + 'freeTextResponse' => str_repeat('a', 3001), |
| 384 | + ]] |
| 385 | + ); |
| 386 | + $response->assertStatus(422); |
| 387 | + // This only tests for the existance of an error key. |
| 388 | + // Using JSON path to check the specific errors message |
| 389 | + // binds very tightly to the laravel implemention of validation and was hard to make work. |
| 390 | + $response->assertJsonStructure(['errors']); |
| 391 | + } |
313 | 392 | } |
0 commit comments