Skip to content

Commit

Permalink
Display response errors
Browse files Browse the repository at this point in the history
Signed-off-by: Quentin Renard <quentin@area17.com>
  • Loading branch information
Antonio Ribeiro authored and ifox committed May 9, 2021
1 parent 308f2a9 commit 7bb74ee
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 82 deletions.
10 changes: 5 additions & 5 deletions tests/integration/LoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class LoginTest extends TestCase
{
public function testCanRedirectToLogin()
{
$this->request('/twill')->assertStatus(200);
$this->httpRequestAssert('/twill');

$this->assertSame('http://twill.test/twill/login', url()->full());

Expand All @@ -31,7 +31,7 @@ public function testCanLogout()
{
$this->login();

$this->request('/twill/logout');
$this->httpRequestAssert('/twill/logout');

$this->assertSee('Forgot password');
}
Expand All @@ -48,17 +48,17 @@ public function testGoogle2FA()

$this->assertSee('One-time password');

$this->request('/twill/login-2fa', 'POST', [
$this->httpRequestAssert('/twill/login-2fa', 'POST', [
'verify-code' => 'INVALID CODE',
]);

$this->assertSee('Your one time password is invalid.');

$this->request('/twill/login-2fa', 'POST', [
$this->httpRequestAssert('/twill/login-2fa', 'POST', [
'verify-code' => (new Google2FA())->getCurrentOtp(
$user->google_2fa_secret
),
])->assertStatus(200);
]);

$this->assertSee('Media Library');
}
Expand Down
81 changes: 40 additions & 41 deletions tests/integration/ModulesAuthorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,28 @@ public function testCanRedirectAuthorsToEdit()
{
$this->createAuthor();

$this->request(
$this->httpRequestAssert(
"/twill/personnel/authors/{$this->author->id}"
)->assertStatus(200);
);

$this->assertSee($this->description_en);
}

public function testCanDisplayDashboard()
{
$this->request('/twill')->assertStatus(200);
$this->httpRequestAssert('/twill');

$this->assertSee('Personnel');
$this->assertSee('Categories');

$this->request('/twill/personnel/authors')->assertStatus(200);
$this->httpRequestAssert('/twill/personnel/authors');

$this->assertSee('Name');
$this->assertSee('Languages');
$this->assertSee('Mine');
$this->assertSee('Add new');

$this->request('/twill/categories')->assertStatus(200);
$this->httpRequestAssert('/twill/categories');
}

public function testCanSearchString()
Expand Down Expand Up @@ -103,11 +103,11 @@ public function testCanStartRestoringRevision()
$first = AuthorRevision::first();
$last = AuthorRevision::all()->last();

$this->request(
$this->httpRequestAssert(
"/twill/personnel/authors/restoreRevision/{$first->id}",
'GET',
['revisionId' => $last->id]
)->assertStatus(200);
);

$this->assertSee(
'You are currently editing an older revision of this content'
Expand All @@ -121,10 +121,10 @@ public function testCanPublishAuthor()
// Publishing
$this->assertEquals('0', $this->author->published);

$this->request('/twill/personnel/authors/publish', 'PUT', [
$this->httpRequestAssert('/twill/personnel/authors/publish', 'PUT', [
'id' => $this->author->id,
'active' => false,
])->assertStatus(200);
]);

$this->assertNothingWrongHappened();

Expand All @@ -135,18 +135,19 @@ public function testCanPublishAuthor()

public function testCanDisplayErrorWhenPublishHasWrongData()
{
$this->request('/twill/personnel/authors/publish', 'PUT')->assertStatus(
200
);
$this->httpRequestAssert('/twill/personnel/authors/publish', 'PUT');

$this->assertSomethingWrongHappened();
}

public function testCanRaiseHttpNotFoundOnAnEmptyRestoreRevision()
{
$this->request(
'/twill/personnel/authors/restoreRevision/1'
)->assertStatus(404);
$this->httpRequestAssert(
'/twill/personnel/authors/restoreRevision/1',
'GET',
[],
404
);
}

public function testCanPreviewBlock()
Expand All @@ -163,9 +164,7 @@ public function testCanPreviewBlock()
'activeLanguage' => 'en',
];

$this->request('/twill/blocks/preview', 'POST', $data)->assertStatus(
200
);
$this->httpRequestAssert('/twill/blocks/preview', 'POST', $data);

$this->assertSee(json_encode(['quote' => $quote]));
}
Expand All @@ -174,10 +173,10 @@ public function testCanPreviewAuthor()
{
$this->createAuthor();

$this->request(
$this->httpRequestAssert(
"/twill/personnel/authors/preview/{$this->author->id}",
'PUT'
)->assertStatus(200);
);

$this->assertSee(
'Previews have not been configured on this Twill module, please let the development team know about it.'
Expand All @@ -190,11 +189,11 @@ public function testCanPreviewAuthor()
$this->makeFileName('{$resources}/views/site/author.blade.php')
);

$this->request(
$this->httpRequestAssert(
"/twill/personnel/authors/preview/{$this->author->id}",
'PUT',
['activeLanguage' => 'en']
)->assertStatus(200);
);

$this->assertDontSee(
'Previews have not been configured on this Twill module, please let the development team know about it.'
Expand All @@ -212,9 +211,9 @@ public function testCanRestoreAuthor()

$this->assertNotNull($this->author->deleted_at);

$this->request('/twill/personnel/authors/restore', 'PUT', [
$this->httpRequestAssert('/twill/personnel/authors/restore', 'PUT', [
'id' => $this->author->id,
])->assertStatus(200);
]);

$this->assertNothingWrongHappened();

Expand All @@ -225,9 +224,9 @@ public function testCanRestoreAuthor()

public function testCanReturnErrorWhenRestoringWrongAuthor()
{
$this->request('/twill/personnel/authors/restore', 'PUT', [
$this->httpRequestAssert('/twill/personnel/authors/restore', 'PUT', [
'id' => 999999,
])->assertStatus(200);
]);

$this->assertSomethingWrongHappened();
}
Expand All @@ -238,10 +237,10 @@ public function testCanFeatureAuthor()

$this->assertFalse($this->author->featured);

$this->request('/twill/personnel/authors/feature', 'PUT', [
$this->httpRequestAssert('/twill/personnel/authors/feature', 'PUT', [
'id' => $this->author->id,
'active' => false,
])->assertStatus(200);
]);

$this->assertNothingWrongHappened();

Expand All @@ -252,10 +251,10 @@ public function testCanFeatureAuthor()

public function testCanReturnErrorWhenFeaturingWrongAuthor()
{
$this->request('/twill/personnel/authors/feature', 'PUT', [
$this->httpRequestAssert('/twill/personnel/authors/feature', 'PUT', [
'id' => 999999,
'active' => true,
])->assertStatus(404);
], 404);
}

public function testCanChangeOrder()
Expand All @@ -272,9 +271,9 @@ public function testCanChangeOrder()

$this->assertEquals(1, $author1->position);

$this->request('/twill/personnel/authors/reorder', 'POST', [
$this->httpRequestAssert('/twill/personnel/authors/reorder', 'POST', [
'ids' => [$author1->id, $author2->id],
])->assertStatus(200);
]);

$this->assertNothingWrongHappened();

Expand All @@ -291,14 +290,14 @@ public function testCanReturnWhenReorderingWrongAuthor()
* TODO
*/

$this->request('/twill/personnel/authors/reorder', 'POST', [
$this->httpRequestAssert('/twill/personnel/authors/reorder', 'POST', [
'ids' => [1, 2],
])->assertStatus(500);
], 500);
}

public function testCanGetTags()
{
$this->request('/twill/personnel/authors/tags')->assertStatus(200);
$this->httpRequestAssert('/twill/personnel/authors/tags');

$this->assertJson($this->content());
}
Expand All @@ -322,9 +321,9 @@ public function testCanShowEditForm()
$this->createAuthor();
$this->editAuthor();

$this->request(
$this->httpRequestAssert(
"/twill/personnel/authors/{$this->author->id}/edit"
)->assertStatus(200);
);

$this->assertSee($this->name_en);
$this->assertSee($this->description_en);
Expand Down Expand Up @@ -354,9 +353,9 @@ public function testCanShowEditFormInModal()

putenv('EDIT_IN_MODAL=true');

$this->request(
$this->httpRequestAssert(
"/twill/personnel/authors/{$this->author->id}/edit"
)->assertStatus(200);
);

$this->assertSee('v-svg symbol="close_modal"');
}
Expand All @@ -368,9 +367,9 @@ public function testCanSeeRenderedBlocks()

putenv('EDIT_IN_MODAL=false');

$this->request(
$this->httpRequestAssert(
"/twill/personnel/authors/{$this->author->id}/edit"
)->assertStatus(200);
);

// Check if it can see a rendered block
$this->assertSee(
Expand Down
13 changes: 7 additions & 6 deletions tests/integration/ModulesCategoriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
namespace A17\Twill\Tests\Integration;

use App\Models\Category;
use Illuminate\Support\Str;

class ModulesCategoriesTest extends ModulesTestBase
{
public function testCanDisplayModuleInNavigation()
{
$this->request('/twill');
$this->httpRequestAssert('/twill');

$this->assertSee('Personnel');
$this->assertSee('Categories');

$this->request('/twill/categories');
$this->httpRequestAssert('/twill/categories');

$this->assertSee('Name');
$this->assertSee('Languages');
Expand Down Expand Up @@ -54,7 +55,7 @@ public function testCanReorderCategories()
$this->assertEquals(1, $category1->position);
$this->assertEquals(2, $category2->position);

$this->request('/twill/categories/reorder', 'POST', [
$this->httpRequestAssert('/twill/categories/reorder', 'POST', [
'ids' => [
[
'id' => $category2->id,
Expand All @@ -65,7 +66,7 @@ public function testCanReorderCategories()
'children' => [],
],
],
])->assertStatus(200);
]);

$this->assertNothingWrongHappened();

Expand All @@ -87,7 +88,7 @@ public function testCanNestCategories()
$category2 = Category::orderBy('position', 'desc')
->first();

$this->request('/twill/categories/reorder', 'POST', [
$this->httpRequestAssert('/twill/categories/reorder', 'POST', [
'ids' => [
[
'id' => $category2->id,
Expand All @@ -99,7 +100,7 @@ public function testCanNestCategories()
],
],
],
])->assertStatus(200);
]);

$this->assertNothingWrongHappened();

Expand Down
Loading

0 comments on commit 7bb74ee

Please sign in to comment.